spencersalazar / chuck

28 stars 8 forks source link

SerialIO onBytes/getBytes Fails When Receiving 255 Over Serial #39

Open sensel opened 10 years ago

sensel commented 10 years ago

When Chuck tries to read from a serial device (i.e. COM port device), onBytes/getBytes fails when the byte value 255 is received from the device.

I believe I found the source of the issue. In peek_buffer(), and pull_buffer() (both in chuck_io.cpp), a -1 is returned to indicate an error. If no error, the byte value is returned. However, it appears that the bytes received over serial are not stored as unsigned chars. Therefore, when 255 gets converted from a signed char to a signed int, you get -1 (which incorrectly indicates an error). This causes Serial to stop reading from the COM port, preventing any further communication.

Note: the functions that call peek_buffer()/pull_buffer check for errors with an "==", so other negative values don't break things.

spencersalazar commented 10 years ago

Thanks sensel, that sounds like a pretty clear assessment of whats going on. A fix seems straightforward, so we can expect to see that for the next release.