JuanJoMh
Posts: 3
Joined: Tue Jan 09, 2018 4:15 am

USB serial adapter generating error after successful transmitions

Tue Jan 09, 2018 4:33 am

I receive the data from a serial adapter for XBEE, after receiving approximately 10 or 20 data the program stops with the following error:

File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 453, in read
buf = os.read(self.fd, size-len(read))
OSError: [Errno 11] Resource temporarily unavailable

After researching and trying the solution of several sites and forums I have not been able to fix it.

This is a serial adapter that I use: https://www.itead.cc/foca.html

The code is very simple and I dont understand what is happen.

Code: Select all

ser = serial.Serial('/dev/ttyUSB0',9600)

while 1:
	while (ser.inWaiting()>0):
		incoming = ser.readline()
		print incoming


In some places they recommend using "if (ser.inWaiting()>0)" but it fails faster.

I used python.


The idea is to receive the data in raspberry pi for unlimited time.

Thanks for help1

wh7qq
Posts: 1440
Joined: Thu Oct 09, 2014 2:50 am

Re: USB serial adapter generating error after successful transmitions

Tue Jan 09, 2018 5:53 am

In Foca literature, I see nothing that touts compatibility with the RPi. You might try the inexpensive PL2303 based serial adapters that are spec'd for the RPi. They cost well under $10 US on amazon.

JuanJoMh
Posts: 3
Joined: Tue Jan 09, 2018 4:15 am

Re: USB serial adapter generating error after successful transmitions

Tue Jan 09, 2018 6:58 am

I do not know if it will be a FOCA problem, because I receive the data well for a while, then it falls with the message that I put before or with this message:

Traceback (most recent call last):
File "EPSensor.py", line 57, in <module>
incoming = ser.readline().strip()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 460, in read
raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected?)


Sometimes the program works for a few minutes but finally falls with this other message:

Exception in thread Thread-1 (most likely raised during interpreter shutdown):Exception in thread Thread-10 (most likely raised during interpreter shutdown)

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: USB serial adapter generating error after successful transmitions

Tue Jan 09, 2018 9:25 am

Why not just catch the exception and carry on with the program on the hope that data will be available next time.

Code: Select all

ser = serial.Serial('/dev/ttyUSB0',9600)

while 1:
    while (ser.inWaiting()>0):
        try:
            incoming = ser.readline()
            print incoming
        except serial.serialutil.SerialException:
            print("No data this time")
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

JuanJoMh
Posts: 3
Joined: Tue Jan 09, 2018 4:15 am

Re: USB serial adapter generating error after successful transmitions

Tue Jan 09, 2018 12:54 pm

Cool, that was a good orientation, I was just to add "OSError" in the exception

Code: Select all

ser = serial.Serial('/dev/ttyUSB0',9600)

while 1:
    while (ser.inWaiting()>0):
        try:
            incoming = ser.readline()
            print incoming
        except (OSError, serial.serialutil.SerialException):
            print("No data this time")
Thanks for the help!

Return to “Troubleshooting”