how to use xmodem module with pySerial
Brought to you by:
cliechti
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.
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'.
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.
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 :)