How to Expand Input Buffer Size of Pyserial

Pyserial buffer fills faster than I can read

There's a "Receive Buffer" slider that's accessible from the com port's Properties Page in Device Manager. It is found by following the Advanced button on the "Port Settings" tab.

advanced settings for com port

More info:

http://support.microsoft.com/kb/131016 under heading Receive Buffer

http://tldp.org/HOWTO/Serial-HOWTO-4.html under heading Interrupts

Try knocking it down a notch or two.

pyserial input buffer

It was my stupid fault. In cutecom I didn't close the log file, so the missing data were in the write() buffer. Device didn't work because of another bug.

Python serial read is extremely slow, how to speed up?

A couple of things you can do.

You shouldn't need time.sleep(). If you know you only want 2 bytes then do ser.read(2) and if you want to limit the wait time ser.timeout = 0.01
EDIT unless you are in a separate thread. Python threads are greedy. I/O operations release the thread so the main thread can run. However, in your case you are always reading the data that is in the buffer ser.read(ser.inWaiting()). I've found that you need to force the serial port to wait on I/O ser.read(ser.inWaiting() + 32). Just make sure you also have a timeout, so you aren't waiting for the I/O forever. Also your current timeout is 5 seconds which is a long time to wait. end edit

You might be able to use readline ser.readline() this may only read to '\r\n'. I'm not sure.

If you are on Python3 then ser.read() returns bytes, so any comparison will be false. data[0] == '0' would need to be data[0:1] == b'0'

The other thing to do is to run the code through the debugger to make sure you are getting the data you are expecting. It is possible that a string comparison or something is wrong which would make you loop a bunch of times needlessly.



Related Topics



Leave a reply



Submit