Basic data inspectionΒΆ

You can get or modify some data by address in the usual way: via Python indexing operations:

>>> print ih[0] # read data from address 0

When you need to work with 16-bit data stored in 8-bit Intel HEX files you need to use class IntelHex16bit. This class is derived from IntelHex and has all its methods. Some of methods have been modified to implement 16-bit behaviour.

NOTE: IntelHex16bit class despite its name can’t handle real HEX16 files. Initially IntelHex16bit has been created as helper class to work with HEX files for Microchip’s PIC16 family firmware. It may or may not work for your purpose.

This class assumes the data is in Little Endian byte order. The data can be accessed exactly like above, except that data returned will be 16 bits, and the addresses should be word addresses.

Another useful inspection tool is the dump command. This will output the entire contents of the hex file to stdout or to a specified file object like so:

>>> ih.dump() # dump contents of ih to stdout in tabular hexdump format

>>> f = open('hexdump.txt', 'w') # open file for writing
>>> ih.dump(f)                   # dump to file object
>>> f.close()                    # close file