Package intelhex :: Class IntelHex
[hide private]
[frames] | no frames]

Class IntelHex

source code

object --+
         |
        IntelHex
Known Subclasses:

Intel HEX file reader.
Instance Methods [hide private]
 
__init__(self, source=None)
Constructor.
source code
 
_decode_record(self, s, line=0)
Decode one record of HEX file.
source code
 
loadhex(self, fobj)
Load hex file into internal buffer.
source code
 
loadbin(self, fobj, offset=0)
Load bin file into internal buffer.
source code
 
loadfile(self, fobj, format)
Load data file into internal buffer.
source code
 
fromfile(self, fobj, format)
Load data file into internal buffer.
source code
 
fromdict(self, dikt)
Load data from dictionary.
source code
 
_get_start_end(self, start=None, end=None)
Return default values for start and end if they are None...
source code
 
tobinarray(self, start=None, end=None, pad=None)
Convert this object to binary form as array.
source code
 
tobinstr(self, start=None, end=None, pad=255)
Convert to binary form and return as a string.
source code
 
tobinfile(self, fobj, start=None, end=None, pad=255)
Convert to binary and write to file.
source code
 
todict(self)
Convert to python dictionary.
source code
 
addresses(self)
Returns all used addresses in sorted order.
source code
 
minaddr(self)
Get minimal address of HEX content.
source code
 
maxaddr(self)
Get maximal address of HEX content.
source code
 
__getitem__(self, addr)
Get requested byte from address.
source code
 
__setitem__(self, addr, byte)
Set byte at address.
source code
 
__delitem__(self, addr)
Delete byte at address.
source code
 
__len__(self)
Return count of bytes with real values.
source code
 
write_hex_file(self, f, write_start_addr=True)
Write data to file f in HEX format.
source code
 
tofile(self, fobj, format)
Write data to hex or bin file.
source code
 
gets(self, addr, length)
Get string of bytes from given address.
source code
 
puts(self, addr, s)
Put string of bytes at given address.
source code
 
getsz(self, addr)
Get zero-terminated string from given address.
source code
 
putsz(self, addr, s)
Put string in object at addr and append terminating zero at end.
source code
 
dump(self, tofile=None)
Dump object content to specified file object or to stdout if None.
source code
 
merge(this, other, overlap='error')
Merge content of other IntelHex object to this object.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, source=None)
(Constructor)

source code 
Constructor. If source specified, object will be initialized with the contents of source. Otherwise the object will be empty.
Parameters:
  • source - source for initialization (file name of HEX file, file object, addr dict or other IntelHex object)
Overrides: object.__init__

_decode_record(self, s, line=0)

source code 
Decode one record of HEX file.
Parameters:
  • s - line with HEX record.
  • line - line number (for error messages).
Raises:
  • EndOfFile - if EOF record encountered.

loadhex(self, fobj)

source code 
Load hex file into internal buffer. This is not necessary if object was initialized with source set. This will overwrite addresses if object was already initialized.
Parameters:
  • fobj - file name or file-like object

loadbin(self, fobj, offset=0)

source code 
Load bin file into internal buffer. Not needed if source set in constructor. This will overwrite addresses without warning if object was already initialized.
Parameters:
  • fobj - file name or file-like object
  • offset - starting address offset

loadfile(self, fobj, format)

source code 
Load data file into internal buffer. Preferred wrapper over loadbin or loadhex.
Parameters:
  • fobj - file name or file-like object
  • format - file format ("hex" or "bin")

fromfile(self, fobj, format)

source code 
Load data file into internal buffer. Preferred wrapper over loadbin or loadhex.
Parameters:
  • fobj - file name or file-like object
  • format - file format ("hex" or "bin")

fromdict(self, dikt)

source code 
Load data from dictionary. Dictionary should contain int keys representing addresses. Values should be the data to be stored in those addresses in unsigned char form (i.e. not strings). The dictionary may contain the key, ``start_addr`` to indicate the starting address of the data as described in README. The contents of the dict will be merged with this object and will overwrite any conflicts. This function is not necessary if the object was initialized with source specified.

_get_start_end(self, start=None, end=None)

source code 
Return default values for start and end if they are None

tobinarray(self, start=None, end=None, pad=None)

source code 
Convert this object to binary form as array. If start and end unspecified, they will be inferred from the data.
Parameters:
  • start - start address of output bytes.
  • end - end address of output bytes (inclusive).
  • pad - fill empty spaces with this value (if None used self.padding).
Returns:
array of unsigned char data.

tobinstr(self, start=None, end=None, pad=255)

source code 
Convert to binary form and return as a string.
Parameters:
  • start - start address of output bytes.
  • end - end address of output bytes (inclusive).
  • pad - fill empty spaces with this value (if None used self.padding).
Returns:
string of binary data.

tobinfile(self, fobj, start=None, end=None, pad=255)

source code 
Convert to binary and write to file.
Parameters:
  • fobj - file name or file object for writing output bytes.
  • start - start address of output bytes.
  • end - end address of output bytes (inclusive).
  • pad - fill empty spaces with this value (if None used self.padding).

todict(self)

source code 
Convert to python dictionary.
Returns:
dict suitable for initializing another IntelHex object.

addresses(self)

source code 
Returns all used addresses in sorted order.
Returns:
list of occupied data addresses in sorted order.

minaddr(self)

source code 
Get minimal address of HEX content.
Returns:
minimal address or None if no data

maxaddr(self)

source code 
Get maximal address of HEX content.
Returns:
maximal address or None if no data

__getitem__(self, addr)
(Indexing operator)

source code 
Get requested byte from address.
Parameters:
  • addr - address of byte.
Returns:
byte if address exists in HEX file, or self.padding if no data found.

write_hex_file(self, f, write_start_addr=True)

source code 
Write data to file f in HEX format.
Parameters:
  • f - filename or file-like object for writing
  • write_start_addr - enable or disable writing start address record to file (enabled by default). If there is no start address in obj, nothing will be written regardless of this setting.

tofile(self, fobj, format)

source code 
Write data to hex or bin file. Preferred method over tobin or tohex.
Parameters:
  • fobj - file name or file-like object
  • format - file format ("hex" or "bin")

gets(self, addr, length)

source code 
Get string of bytes from given address. If any entries are blank from addr through addr+length, a NotEnoughDataError exception will be raised. Padding is not used.

puts(self, addr, s)

source code 
Put string of bytes at given address. Will overwrite any previous entries.

getsz(self, addr)

source code 
Get zero-terminated string from given address. Will raise NotEnoughDataError exception if a hole is encountered before a 0.

dump(self, tofile=None)

source code 
Dump object content to specified file object or to stdout if None. Format is a hexdump with some header information at the beginning, addresses on the left, and data on right.
Parameters:
  • tofile - file-like object to dump to

merge(this, other, overlap='error')

source code 
Merge content of other IntelHex object to this object.
Parameters:
  • other - other IntelHex object.
  • overlap - action on overlap of data or starting addr: - error: raising OverlapError; - ignore: ignore other data and keep this data in overlapping region; - replace: replace this data with other data in overlapping region.
Raises:
  • TypeError - if other is not instance of IntelHex
  • ValueError - if other is the same object as this
  • ValueError - if overlap argument has incorrect value
  • AddressOverlapError - on overlapped data