pyserial question (issue?)
At Matt's suggestion I have been looking into pyserial as a more flexible means of creating a serial connection, while also allowing for IP socket connections. I have it running. But, as noted in another thread, I have found what looks like a bug in pyserial. Specifically, a timeout
value of 0
, which should be a blocking read - I.e. when used with readline()
it only return data when a line has been read. Instead, use of the zero value simply blocks forever and never returns anything.
So, my solution was to simply use a value >0. However, since readline()
returns on timeout as well as on a newline, it can return a lot of null data. Here is the code I am playing with:
- Code: Select all
s = serial.serial_for_url('socket://192.168.4.2:5003', timeout=1)
foo = ""
while len(foo) == 0:
foo = s.readline()
foo = ""
OTOH, I could also use an arbitrarily large value for timeout
and essentially achieve the blocking read I want.
So, my questions.
Do you know if this is a bug in serial_for_url
and if so, does it affect serial as well as socket connections?
In your opinion (which I value highly) which approach seems better... long timeout or short timeout and check for null data? Certainly the long timeout is simpler, but maybe there are other considerations.
EDIT: I forgot... there is one clear downside to a long timeout value. It causes the plugin to block and not die when asked to by Indiigo, like on a reload plugin.