1

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?

0

I had a similar issue when I was using a USB based GPS module. The only way I managed to resolve it is by reducing the baud rate to 9600. 19200 might work as well but with me, only 9600 was stable enough. I don't think GPS modules can produce data any faster anyway.

  • I have reduced the baud rate to 4800 as some forum recommend this value but the issue persists. – Ricard Molins May 11 '18 at 12:10
0

I have a little experience with GPS dongles and so far I have been able to read from them by opening the device file as it it were just a normal plain file (with open) and then pulling with readline(). The only details I've had to change (say, set no echo or change speed) I just call stty with supprocess.popen and then I just go and open the file and read from it till I reach EOF (device was disconnected, for example).

How long does it take for your application to fail? Because you can try with cat (on bash, say)... run cat on the device file and see if it will run longer than your application reading from the device. It should run forever, actually... if it goes fine, then I would expect open/readline() to work just as well on python reading from it.

  • First of all thank you for the sugestion of doing cat onto the device, its a nice way to obtain the output that I didn't know. If I do cat on /dev/serial0 after some seconds (0-15) the cat command is stopped. – Ricard Molins May 11 '18 at 6:42
  • Then it's probably something not related to your programming or the APIs you are depending on but on either the hardware or the kernel driver (more likely the first than the second). Any messages on dmesg? How about on /var/log/syslog? – eftshift0 May 11 '18 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.