Python Forum
Unable to read from serial port
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to read from serial port
#1
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.
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pyserial/serial "has no attribute 'Serial' " gowb0w 11 21,543 Sep-27-2024, 12:18 PM
Last Post: NigelHalse
  Python is unable to read file Genericgamemaker 13 3,577 Jul-19-2024, 06:42 PM
Last Post: snippsat
  Waiting for input from serial port, then move on KenHorse 3 4,083 Apr-17-2024, 07:21 AM
Last Post: DeaD_EyE
  MCU reboots after opening Serial port when ran from Raspberry PI zazas321 3 1,627 Mar-19-2024, 09:02 AM
Last Post: zazas321
  Serial Port As Global Prasanjith 2 2,898 Mar-23-2023, 08:54 PM
Last Post: deanhystad
  Python Serial: How to read the complete line to insert to MySQL? sylar 1 1,542 Mar-21-2023, 10:06 PM
Last Post: deanhystad
  python serial port barryjo 2 2,343 Dec-27-2021, 11:09 PM
Last Post: barryjo
  is there a way to mention port range or search for port dynamically with qConnection Creepy 0 2,035 Sep-09-2021, 03:15 PM
Last Post: Creepy
  How to Properly Open a Serial Port in a Function bill_z 2 8,088 Jul-22-2021, 12:54 PM
Last Post: bill_z
  UART Serial Read & Write to MP3 Player Doesn't Work bill_z 15 8,789 Jul-17-2021, 04:19 PM
Last Post: bill_z

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020