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.
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
How to Modify the Navigation Toolbar Easily in a Matplotlib Figure Window
How to Print Colored Text to the Terminal
Python Replace Elements in Array At Certain Range
How to Check Url Change With Selenium in Python
Pandas: Sum Dataframe Rows for Given Columns
_Tkinter.Tclerror: No Display Name and No $Display Environment Variable
Using a Global Variable With a Thread
Correctly Reading Text from Windows-1252(Cp1252) File in Python
Most Efficient Way to Construct Similarity Matrix
How to Convert a Float into Hex
Hiding Axis Text in Matplotlib Plots
Dividing Each Row by the Previous One
Python - Split a List of Dicts into Individual Dicts
How to Further Filter a Result of Resultset
How to Show a Pandas Dataframe into a Existing Flask HTML Table
Permissionerror: [Errno 13] Permission Denied