I need some help troubleshooting an Attribute Error in my Python code.
I am working with a serial device connected by a /dev/ttyUSB0 to a Raspberry Pi 2B. My goal for this code is to read live serial data continuously from the serial device and separate out commands delineated by an '@' symbol instead of /n or /r.
This project is still in its early stages but from some quick research I've done the pyserial attribute 'read_until' would work perfectly as its backbone. This would allow me to read in one byte at a time and stop at an '@' symbol, and afterwards process the data before moving on to the next portion of serial data.
For some reason I get an Attribute Error when I try to use 'read_until' claiming that the 'Serial' object does not have this function. Below is the test code I am using and the error it spit back out:
import serial
gc = serial.Serial('/dev/ttyUSB0', baudrate = 230400)
print(gc.name)
def getCommand():
gcData = gc.read_until('@', 1).decode('ascii')
print(gcData)
getCommand()
gc.close()
And here is the output that this code gave me:
>>>
/dev/ttyUSB0
Traceback (most recent call last):
File "/home/pi/Python/GC/serialRead1.py", line 10, in <module>
getCommand()
File "/home/pi/Python/GC/serialRead1.py", line 7, in getCommand
gcData = gc.read_until('@', 1).decode('ascii')
AttributeError: 'Serial' object has no attribute 'read_until'
>>>
The frustration behind this is that 'read_until' should have been imported along with the serial library. Perhaps I am missing something quite simple, but it would be very helpful if I could use this attribute. Most other questions about 'read_until' are referencing the 'telnetlib' which as far as I know is not the same as what PySerial has.
Here is a link to the website where I found the documentation saying that 'read_until' should belong to PySerial: https://pyserial.readthedocs.io/en/latest/pyserial_api.html
Just so you are aware, I am very new to programming in general. Some of the jargon that seasoned programmers like yourselves use might go over my head and so I may have no idea how to perform the solutions you have. I ask for your patience as I learn more about programming and Python in general.
Thank you very much for your time!