Python Forum
pySerial - missed messages - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: pySerial - missed messages (/thread-36181.html)



pySerial - missed messages - q_nerk - Jan-25-2022

ESP32 is sending data via USB do desktop with Ubuntu 20.04 (at the end script will be used on RPI4).
Yesterday it was working, today not.

def read():
    port = '/dev/ttyUSB0'
    baudrate = 115200
    ser = serial.Serial(port, baudrate)
    data = ser.readline()
    text = data.decode(errors="ignore")
    return text
What serial monitor from arduino ide see:
Output:
x0.33 y0.76 z9.70 t0.19 x0.32 y0.73 z9.73 t0.19 x0.31 y0.74 z9.65 t0.19 ....
What is terminal output from script:
Output:
x0.27 z9.71 x0.26 z9.73 x0.29 z9.72 x0.29 z9.68 x0.28 z9.73 x0.28 z9.70 x0.28 z9.74 x0.20 z9.74 x0.33 z9.69 x0.29 z9.68 ....
The funniest thing is that it was working yesterday, today is not. What I'm doing wrong? I tried to set different timeout, as well as None, and many other parameters with no result.


RE: pySerial - missed messages - deanhystad - Jan-25-2022

I don't know what happens when you repeat this over and over on an already opened serial port.
ser = serial.Serial(port, baudrate)
Does this close the already open connection? If so, that would flush anything remaining in the read buffer. I would open the port once and read many times.


RE: pySerial - missed messages - Jeff_t - Jan-27-2022

Can you post the section of serial output code of the ESP32 so that we can see what your python script should expect and if there is a better way to read it.