Python Forum
Unable to read from serial port - 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: Unable to read from serial port (/thread-28892.html)



Unable to read from serial port - br0kenpixel - Aug-08-2020

I'm working on a project where I control a LED matrix connected to an Arduino.
Using pyserial I open the Arduino's serial port and send a "?" to it.
The Arduino should reply with an "!", however I'm unable to read this.

import serial

port = "/dev/tty.usbserial-A106TL49"
port = serial.Serial(port, 115200, timeout=5)
port.write("?\n".encode())
port.flush()
resp = port.readline().decode()
port.close()
print(resp)
If I copy and paste each line into the Python Shell (or just type it in manually), it works.
İmage

I tried adding a time.sleep() before writing and reading to/from the serial port but it did not work either.


RE: Unable to read from serial port - Larz60+ - Aug-08-2020

only the receiver will see the time delay, not the sender so whatever was sent may be gone by the time you try to read it.