Closed EddieParis closed 6 years ago
I wrote this library over 7 years ago, and only kept it updated as I needed. When I first wrote this, I don't remember if pyserial had timeouts or that they didn't work correctly. Also, pyserial on read or write may send incomplete streams and/or not pause between transmissions. The pyserial timeouts are more for transmission timeouts and not BusPirate wait/sleep/pause type timeouts.
Yes, pyserial timeout are transmission (and in our case reception timeouts). I noticed that most of the usage of self.timeout() is to wait a bit before getting answer. This is exactly the purpose of the pySerial timeout. Somtime a simple pause is needed, better use time.sleep() instead of timeout.
Again my point is that the select in timeout does not work on Windows, so I can provide a branch with no more select, you can then merge it if you agree :-)
@EddieParis pySerial timeouts are Transaction timeouts, they don't control response timeout or pre-response pausing.
I'm surprised this get back to the front :-) So let me explain one last time. In the original code, the select is used to wait any event on the process FDs for a maximum of timeout seconds. If an event happens (an incoming character on the serial line for instance) the select exits immediately and then you go and fetch the response which is available since you waited in the select.
This behavior is EXACTLY what's behind pySerial timeouts, so when a timeout is set, if you want to read a character and there is non immediately available it wait for a maximum of timeout seconds.
So using the pySerial timeouts is more clear and have the benefit of compatibility regarding the select issue on the windows platform.
@EddieParis Let me explain how the BusPirate works, the serial interface will return whatever junk is in the buffer on the device side. We use select/timeout to ensure the BusPirate has enough time to flush its buffer and push data onto the buffer. If we were dealing with a "Normal" serial port, the pySerial timeouts would work. But as for the BusPirate, it doesn't always return valid data using pySerial timeouts. I know because when I originally tried to use the pySerial Timeouts I wasn't getting valid responses to sent commands.
The problem comes from the select() used in timeout function. From python doc it is said that select with 3 empty fd list does not work on windows.
This leads me to another stuff, why bothering with this timeout management since pyserial does already manages timeout ? Is there a limitation that I am not aware off ?
If no I can branch and propose a modification implementing pyserial timeout usage.