sending binary files to a 16 micro controller.

Magnus Lycka lycka at carmen.se
Mon Aug 22 08:02:45 EDT 2005


johnny.karlsson at gmail.com wrote:
> Hi, I'm working on a project were a need to be able to upload firmware
> to a microcontroller based Ethernet device. But because of the memory
> constraints the controller can only handle packages of 300 bytes each
> time. So therefore the firmware file must be sent in chunks and i need
> a header in each file describing which part of the file it is I'm
> sending. Could anyone give me some pointer on how a could accomplish
> that in python? I'm talking about the client that uploads the software
> to the device via TCP.

You can probably start here:
http://docs.python.org/lib/socket-example.html

If you're uncertain about the exact content of the transmitted
messages, and has access to some other client program, you could
write a Python server and see exactly what bit pattern the other
client sends. Then you can write a Python client that behaves the
same way.

The basic pattern to split and transmit your file would probably
be something like:

f = open('filename')
header_template = 'Chunk %05i, %03i bytes'
for i, bytes in enumerate(f.read(max_number_of_bytes_per_chunk)):
     msg = header_template % (i, len(bytes))
     msg += bytes
     sock.send(msg)
sock.send('The end!')



More information about the Python-list mailing list