1chenar 1chenar - 3 years ago 98
Python Question

how to read non-zero part of intelhex file in python using IntelHex package

I'm trying to read part hex data from an intelhex file using Intelhex package of python 3.6. Using following code I opened the file and tried to convert to dictionary if it helps.

ih = IntelHex("data.hex")
mydict = ih.todict()


now I have an address

startAddress = some value


I want to read stored data starting from $startAddress delimited to the zero value. What's the best way to perform that?

Answer Source

The following code is the solution. First I converted the IntenHex file to the dictionary:

from intelhex import IntelHex
ih = IntelHex("sampleFile.hex")
ihdict = ih.todict()

Then iterated through the dictionary from startAddress to the place that value is None. I stored values in a string named datastr.

datastr = ""
startAddress = 500300
while ihdict.get(startAddress) != None:
    datastr += str("%0.2X" %ihdict.get(startAddress))
    startAddress += 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download