I have a python code that reads the serial port of the raspberry pi 3to obtain GPS positions from a fona808. The code works for some time and then throws this error.
Traceback (most recent call last):
File "serial_run0.py", line 29, in <module>
while ser.inWaiting() > 0:
File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 572, in inWaiting
return self.in_waiting
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 456, in in_waiting
s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
IOError: [Errno 5] Input/output error
My code is as follows
ser = serial.Serial(
port='/dev/serial0',
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=0.5,
write_timeout= 0.2,
xonxoff=False,
rtscts=False,
# exclusive=True
)
ser.isOpen()
print ('Enter your commands below.\r\nInsert "exit" to leave the application.')
input_val = 1
while 1 :
# get keyboard input
time.sleep(1)
out = ""
while ser.inWaiting() > 0:
out += ser.read(1).decode()
print (">>" + out)
Any guidance on which ay be the source of this error?