-
Notifications
You must be signed in to change notification settings - Fork 206
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
Timeouts #33
Timeouts #33
Conversation
And placed close to related system function definitions
Backward compatibility note: Default port behaviour (just after serial.Open()) keep unchanged, but where no way to get it back after some timeouts explicitly set with appropriate methods.
Hi @albenik first of all thank you for the very high quality patch, as usual. I've tested some of the functions and they seems to work as expected. I have some questions about the interface though: // Sets interbytes timeout
// Values:
// x <= 0: disable interbyte timeout
// x > 0: set iterbyte timeout ot x milliseconds
SetInterbyteTimeout(msec int) error
// SetReadTimeout sets whole packet read timeout.
// Values:
// x < 0: wait forever / until requested number of bytes are received.
// x = 0: non-blocking mode, return immediately in any case, returning zero or more,
// up to the requested number of bytes.
// NOTE: SetReadTimeout(0) for windows resets interbyte timeout to MAXDWORD
// x > 0: set timeout to x milliseconds returns immediately when the requested number of bytes are available,
// otherwise wait until the timeout expires and return all bytes that were received until then.
SetReadTimeout(msec int) error
// SetWriteTimeout set whole packet write timeout
// For possible values refer to the list for read timeout values above.
SetWriteTimeout(msec int) error in particular I'm wondering how we can simplify it, here some thoughts:
I found this very convoluted and IMHO we lose the only timeout that is useful and has any sense with a serial port:
the current blocking Read implementation blocks until the first character is received, so it's like this latter case "timeout-until-first-char" but with the timeout set to infinity. If possible I'd like to see only this timeout implemented and available.
I'm sorry for being picky on this one, but I'd like to hear your opinion before this gets merged and the API becomes written into stone. Getting the API right is probably the most difficult part of software design, so I think it's better to discuss a bit more now. In my vision, I want this library to be useful and simple, by providing only the most useful functions. On the other hand the "serial port" is probably one of the most over-engineered piece of hardware ever invented and I'd like to avoid implementing (and maintaining!) all of the possible permutations of functionality that the OS provides... |
First of all, I bought most of implementation from https://github.com/pyserial/pyserial. I consider it as mature, well-designed library. So actually ideas not my, but pyserial community, and i believe to them.
|
Simple return bytes read or written and no error
Fixed |
Buffer size passed to syscall.ReadFile must be equal to calculated readSize below
I'm doing some more in-depth tests, I started on linux.
with the current
in this case the Read() blocks and is interrupted after the Close().
in this case the Read() exits immediately (with n=0 and err=nil). This is a non-backward compatible change that I can't merge. PS: the testsuite I'm working on is based on this kind of regression test. |
I'm sure you did because you needed it :-) I was asking if this interface could be simplified in some way (by reducing the number of different kind of timeouts for example) because, IMHO, it makes easier to achieve a consistent behavior across different OS and reduce the risk of regressions (by reducing the surface of code touched by the PR). Adding so many different types of timeouts to me seemed to make this goal harder but, I repeat, it's just my impression, since you get inspiration by |
@cmaglie Sorry for delay. I am under hard pressure with my primary job needs. So I can answer for question and fix bugs a bit later. |
Hi @cmaglie, sorry for delay. Bug with timeout under *nix fixed. And I have a new read timeouts interface proposal:
At most cases just one of (1) or (3) simple methods enough. For complex cases (2) method can help. Do you accept this proposal? |
Hello friends, I am very interested in non-blocking read mode support. |
I've got some free time latlely, I'll try to take a look again to this PR this weekend. (wow 2.5 years passed already from the last comment... time flies... 😞) |
For the short term if anyone needs timeouts, you might consider this package which can be used to wrap any io.ReadWriter: https://pkg.go.dev/github.com/simpleiot/simpleiot/respreader?tab=doc I've been using it for modem control (AT commands), and for RS485 protocols like modbus -- seems to be working well. |
Superseded by #109 |
Read/Write timeouts implemented