#34 how to use xmodem module with pySerial

closed
Chris Liechti
None
5
2010-07-21
2010-07-18
Brendan Simon
No

I'm looking for a short example of how to use the xmodem module with pySerial (I'm assuming this is possible).

http://packages.python.org/xmodem/xmodem.html

The documentation says that the send() and recv() methods take a 'stream' parameter. Can I just pass the pySerial object as the stream parameter ??, or maybe the ser.fileno() ??

Many thanks,
Brendan.

Discussion

  • Brendan Simon
    Brendan Simon
    2010-07-18

    I think I misunderstood the xmodem documentation. The 'stream' is the actual data to 'send' or 'recv'. Not an I/O stream (such as a serial port interface which is what I was thinking).

    If the data to send is in memory (e.g. a string of bytes), is that considered a 'stream' ??
    If not, then I need to figure out how to convert a 'string' into a 'stream'.

     
  • Chris Liechti
    Chris Liechti
    2010-07-21

    According to their docs is tha class xmodem.XMODEM taking a read and write character function as parameter (getc, putc). It should be easy to write wrappers for a serial port object (just call read/write and return None on errors). See
    http://packages.python.org/xmodem/xmodem.html#xmodem.XMODEM

    The stream parameter for send and recv are file like objects to read respectively write data from/to on your side of the connection. Its not the connection itself.

     
  • Chris Liechti
    Chris Liechti
    2010-07-21

    • labels: 397062 -->
    • assigned_to: nobody --> cliechti
    • status: open --> pending
     
  • Brendan Simon
    Brendan Simon
    2010-07-21

    Yep. Got it working.

    Effectively just called the serial read() and write() functions within the getc() and putc() functions.

    For the stream parameter, I used StringIO to hold the data to send the data which was stored in a string.

    from StringIO import StringIO
    stream = StringIO( data )

    Cheers :)

     
  • Brendan Simon
    Brendan Simon
    2010-07-21

    • status: pending --> open
     
  • Chris Liechti
    Chris Liechti
    2010-07-21

    • status: open --> closed