pyserial with binary data

A

alastair

Hi,

I'm using pyserial to transfer data from PC to another device - the
data is either from an ASCII file or binary data file. Everything
works fine up until I start using files of a particular size on Linux,
around 1.3MB.

When I send the data on windows everything is ok - on Linux I get the
following traceback:

Traceback (most recent call last):
....
File "/home/pythonCode/loader.py", line 155,
in serialWrite
ser.write(buffer)
File "/usr/lib/python2.3/site-packages/serial/serialposix.py", line
288, in write
n = os.write(self.fd, d)
OSError: [Errno 11] Resource temporarily unavailable

In the serialposix.py file the data is being written to the serial
port - I'm guessing that the win32 file is used when running on
windows so might be why things work ok.

Can anyone offer any pointers as to why this should happen ? I first
thought that it might be because I was using binary data, but the same
happens when I tried a large ASCII data file. Any ideas for a
workaround appreciated :)

Many thanks,

Alastair.
 
G

Guillaume Weymeskirch

Hi,

I've got the same problem. Errno 11 is because too much data, sending
is in progress.

Fix is easy: assign a non zero value to the writeTimeout property of
your serial objet.
Then the write method will wait up to this time for sending data.

Hope that's help

Guillaume
 
P

Peter Hansen

Guillaume said:
I've got the same problem. Errno 11 is because too much data, sending
is in progress.

Fix is easy: assign a non zero value to the writeTimeout property of
your serial objet.
Then the write method will wait up to this time for sending data.

Note that writeTimeout is new in PySerial v2.1, released 2004 July 28.

-Peter
 
G

Grant Edwards

When I send the data on windows everything is ok - on Linux I get the
following traceback:

Traceback (most recent call last):
...
File "/home/pythonCode/loader.py", line 155,
in serialWrite
ser.write(buffer)
File "/usr/lib/python2.3/site-packages/serial/serialposix.py", line
288, in write
n = os.write(self.fd, d)
OSError: [Errno 11] Resource temporarily unavailable

A patch that fixes this is available from the pyserial SF site.
Can anyone offer any pointers as to why this should happen ?

It happens because the serial device driver returns -11. The
Regular serial (16x50) driver doesn't do this and will buffer
up to 4K, then block. For reasons known only to their authors,
some serial drivers don't behave like that. If you try to
write more than they can immediately send to the HW (a dozen or
two bytes in the case I ran across with a Prolific USB->serial
widget), they take as much as they can send and return
immediately. If you then try to write more data, you get a
return of -11.
I first thought that it might be because I was using binary
data, but the same happens when I tried a large ASCII data
file. Any ideas for a workaround appreciated :)

Here's the bug:
http://sourceforge.net/tracker/index.php?func=detail&aid=1043420&group_id=46487&atid=446302
Here's the patch:
http://sourceforge.net/tracker/index.php?func=detail&aid=1043436&group_id=46487&atid=446304
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top