-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set Windows timeouts to enforce non-blocking read #38
base: master
Are you sure you want to change the base?
Conversation
Settings ReadIntervalTimeout and ReadTotalTimeoutMultiplier to MAXDWORD in the COMMTIMEOUTS structure on Windows makes Windows behave as normally expected; a read call to the serial port will return immediately if there is any data available, or if a single byte arrives in the buffer. If no data arrives, it will timeout out after the timeout specified in ReadTotalTimeoutConstant. This fixes issues where reading from a serial port would take longer than desired when less data arrives that there is room for in the buffer passed to the read function. See also: https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-commtimeouts
Ping me when this is accepted in serialport and I'll give it a detailed look |
@estokes this has now been released with serialport-rs 4.4 :) |
@larsch I may have encountered an issue with this as I have been testing it. It seems that you get the EOF condition somewhat unexpectedly with the serial port, causing I might work up a fix for this if I can. |
Just based on my rudimentary understanding, which is not yet complete, I think that we need to detect somewhere ( This might also not block this PR since this is a change forced upon |
- Removes bad timeout overrides - See: - berkowski#38 - berkowski#47 - serialport/serialport-rs#79 - serialport/serialport-rs#73 (comment) - Cleans up unused imports
Given that the fix is accepted in serialport, would you like to amend this PR to completely remove the override? |
This is the equivalent of the PR serialport/serialport-rs#79. I would actually recommend completely removing the COMMTIMEOUTS override in mio-serial when/if the patch is accepted on serialport-rs, as this will solve the issue of read not returning available data until buffer is full or timeout. However, without this patch, the fix in serialport-rs does nothing.
This behavior is critical for and request/response protocol. I see 27-30 millisecond minimum latency on reads for data that takes <1ms to transfer, which is unacceptable.
Original change description:
Settings ReadIntervalTimeout and ReadTotalTimeoutMultiplier to MAXDWORD in the COMMTIMEOUTS structure on Windows makes Windows behave as normally expected; a read call to the serial port will return immediately if there is any data available, or if a single byte arrives in the buffer. If no data arrives, it will timeout out after the timeout specified in ReadTotalTimeoutConstant.
This fixes issues where reading from a serial port would take longer than desired when less data arrives that there is room for in the buffer passed to the read function.
See also: https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-commtimeouts