IntelHex is a Python library for manipulating Intel HEX files, which are commonly used for programming microcontrollers and memory devices. It provides functionalities to read, write, parse, modify, and analyze HEX file data. The current version is 2.3.0, with a release cadence that addresses bug fixes and introduces new API features as needed.
pip install intelhexVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to load an Intel HEX file, read and modify data, and then write the changes back to a new HEX file. It uses a temporary directory for file operations and highlights the use of `eolstyle` during file writing, which is crucial for cross-platform compatibility.
If you require strict separation of all non-overlapping segments, explicitly set `min_gap=0` when calling `ih.segments(min_gap=0)`. Adjust `min_gap` as needed to control segment consolidation behavior.
For new projects or existing Python 3 projects, always use `intelhex` version 2.0 or newer. For Python 2 projects, using `intelhex` >= 2.0 also provides better cross-compatibility and bug fixes.
Always explicitly set the `eolstyle` parameter to `'CRLF'` or `'LF'` when writing HEX files, e.g., `ih.write_hex_file(filepath, eolstyle='CRLF')`, to ensure consistent line endings compatible with your target environment.
Ensure the library is installed using pip for the correct Python interpreter: `pip install intelhex` or `pip3 install intelhex`.
Validate the HEX file's integrity and format. Use a HEX file viewer or editor to identify and correct the specific issue (e.g., incorrect checksum, invalid record type, truncated line). Often, the error message will point to a specific line or record type.
Before accessing data, verify the address range and data length against the actual data present in the `IntelHex` object, or use methods that safely handle sparse data, such as checking `ih.get(address)` for `0xFF` (default fill byte) or iterating through `ih.segments()`.
Examine the source of the HEX file to identify and resolve the overlapping address ranges. This often requires correcting the linker script or memory allocation in the build process that generated the HEX file.
No dependency data recorded yet.