bincopy
bincopy is a Python library for manipulating various binary information file formats, including Motorola S-Record, Intel HEX, TI-TXT, Verilog VMEM, ELF, and raw binary files. The current version is 20.1.1, and the library is actively maintained with regular updates.
Warnings
- breaking bincopy versions 20.x.x and newer require Python 3.9 or higher. Attempting to install or run these versions on Python 2.x will result in installation errors or runtime exceptions due to syntax incompatibility and dropped support.
- gotcha The primary class for handling binary files was `bincopy.File` in older versions. It has been renamed to `bincopy.BinFile` in current versions. Using `bincopy.File()` will raise an `AttributeError` or `NameError` if the older class is not available or if you're following outdated examples.
- gotcha When adding data, methods like `add_ihex()` expect a file-like object. For directly adding a string containing Intel HEX or S-Record data, it's generally best to create an `io.StringIO` object from the string and pass that, or check for specific `add_*_string` methods if available (though `add_ihex` with `StringIO` is robust). Incorrectly passing a raw string to methods expecting a file object can lead to unexpected parsing errors.
Install
-
pip install bincopy
Imports
- BinFile
from bincopy import BinFile
Quickstart
import bincopy
import io
# Example Intel HEX content as a string
intel_hex_content = (
":10010000214601360121470136007EFE09D219012146017E17C20001FF5F16002148011973\n"
":0C011000194E79234623965778239EDA3F0199\n"
":00000001FF"
)
# Create an in-memory file-like object from the string
hex_file_stream = io.StringIO(intel_hex_content)
# Initialize BinFile and add the Intel HEX data
bin_file = bincopy.BinFile()
bin_file.add_ihex(hex_file_stream)
# Convert to Motorola S-Record format
srec_output = bin_file.as_srec()
print("Motorola S-Record output:")
print(srec_output)
# Access properties like minimum and maximum address
print(f"Minimum address: {bin_file.minimum_address:#x}")
print(f"Maximum address: {bin_file.maximum_address:#x}")