pyserial with binary data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alastair

    pyserial with binary data

    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(buffe r)
    File "/usr/lib/python2.3/site-packages/serial/serialposix.py" , line
    288, in write
    n = os.write(self.f d, 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.
  • Guillaume Weymeskirch

    #2
    Re: pyserial with binary data

    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

    Comment

    • Peter Hansen

      #3
      Re: pyserial with binary data

      Guillaume Weymeskirch wrote:[color=blue]
      > 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.[/color]

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

      -Peter

      Comment

      • Grant Edwards

        #4
        Re: pyserial with binary data

        On 2004-11-26, alastair <ally_burnett@y ahoo.co.uk> wrote:
        [color=blue]
        > 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(buffe r)
        > File "/usr/lib/python2.3/site-packages/serial/serialposix.py" , line
        > 288, in write
        > n = os.write(self.f d, d)
        > OSError: [Errno 11] Resource temporarily unavailable[/color]

        A patch that fixes this is available from the pyserial SF site.
        [color=blue]
        > Can anyone offer any pointers as to why this should happen ?[/color]

        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.
        [color=blue]
        > 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 :)[/color]

        Here's the bug:

        Here's the patch:


        --
        Grant Edwards grante Yow! TATTOOED MIDGETS
        at are using ALFREDO in their
        visi.com SALAMI FACTORY!

        Comment

        Working...