SirPali
Posts: 17
Joined: Mon Feb 09, 2015 10:54 am
Location: Netherlands

Serial port wont stop giving errors

Thu Nov 26, 2015 4:13 pm

I am using a USB to Serial cable to monitor data which is sent from a computer to printer.
The problem is that my script seems to work out fine 3/4 of the time but I cant find out why the failures keep happening.


I tried the following:

Python script (automatically starts up 30 seconds after boot):

Code: Select all

ser = serial.Serial(

    port='/dev/ttyUSB0',
    baudrate = 115200,
    parity = serial.PARITY_NONE,
    stopbits = serial.STOPBITS_ONE,
    bytesize = serial.EIGHTBITS,
    timeout = 1

    )

while 1:
    try: 

        line = ser.readline().strip()

    except (OSError, SerialException) as e:
        print e 
        continue
Terminal output (on failure):

Code: Select all

Loading script...
Script loaded and ready to use!
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
device reports readiness to read but returned no data (device disconnected?)
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
device reports readiness to read but returned no data (device disconnected?)
device reports readiness to read but returned no data (device disconnected?)
device reports readiness to read but returned no data (device disconnected?)
device reports readiness to read but returned no data (device disconnected?)
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
device reports readiness to read but returned no data (device disconnected?)
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
device reports readiness to read but returned no data (device disconnected?)
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
device reports readiness to read but returned no data (device disconnected?)
[Errno 11] Resource temporarily unavailable
device reports readiness to read but returned no data (device disconnected?)
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
device reports readiness to read but returned no data (device disconnected?)
[Errno 11] Resource temporarily unavailable
device reports readiness to read but returned no data (device disconnected?)
device reports readiness to read but returned no data (device disconnected?)
device reports readiness to read but returned no data (device disconnected?)
device reports readiness to read but returned no data (device disconnected?)
[Errno 11] Resource temporarily unavailable
[Errno 11] Resource temporarily unavailable
When I restart the script everything seems to work fine but I cant find out why it keeps happening.
I also disabled the serial port as console port for the pi and tried to use more and less time.sleeps to give the port some warmup time but nothing solved the problem.

I hope you guys can help me!

SirPali
Posts: 17
Joined: Mon Feb 09, 2015 10:54 am
Location: Netherlands

Re: Serial port wont stop giving errors

Sat Nov 28, 2015 2:05 pm

Does anyone have any idea what this might be? It's driving me up the walls.

User avatar
B.Goode
Posts: 13220
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Serial port wont stop giving errors

Sat Nov 28, 2015 3:30 pm

Would it help to slow down the rate at which you attempt to read from the serial port? [That is, the time between successive calls to readline() - not the baudrate.]

SirPali
Posts: 17
Joined: Mon Feb 09, 2015 10:54 am
Location: Netherlands

Re: Serial port wont stop giving errors

Tue Dec 08, 2015 1:09 pm

B.Goode wrote:Would it help to slow down the rate at which you attempt to read from the serial port? [That is, the time between successive calls to readline() - not the baudrate.]
I tried to do that but it didn't solve my problem.

I created a new try except which restarts the whole script instead of a new try on readline but it is still giving me errors over time.
The error messages show up so irregular.. (sometimes instant but sometimes you see no error for minutes)

Btw, the serial port constantly receives messages (about every 2 seconds). But when I send the messages manually it still gives me errors sometimes.


Anybody who can help me out? :(

User avatar
topguy
Posts: 7243
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Serial port wont stop giving errors

Tue Dec 08, 2015 1:21 pm

I would look for other programs using the same device or check you have accidentally started multiple instances of your script.

"ps aux" or "ps -ef" to list all running processes.
"lsof" is a command that will list *all* open files on your system with name and number of the processes that has opened it.

SirPali
Posts: 17
Joined: Mon Feb 09, 2015 10:54 am
Location: Netherlands

Re: Serial port wont stop giving errors

Fri Dec 11, 2015 11:11 am

topguy wrote:I would look for other programs using the same device or check you have accidentally started multiple instances of your script.

"ps aux" or "ps -ef" to list all running processes.
"lsof" is a command that will list *all* open files on your system with name and number of the processes that has opened it.
That solved it!
I was completely sure I ran the script only once but I didn't notice there is a difference between "sudo crontab -e" and "crontab -e" :|

Thanks a lot, my script is working now :)

Return to “Troubleshooting”