A lightweight Python Modbus client implemented as a thin wrapper around libmodbus
Project description
ctypes-modbus
A lightweight Python Modbus client implemented as a thin wrapper around libmodbus.
This project is similar to pylibmodbus, but uses the built-in ctypes instead of cffi,
eliminating external Python dependencies and reducing memory usage while maintaining comparable performance.
Dependencies
- python3.8+
- libmodbus5
Installation
- apt-get install libmodbus5
- pip install ctypes-modbus
Usage
import logging
from ctypes_modbus import Modbus
logging.basicConfig(level=logging.DEBUG)
mb = Modbus.RTU("/dev/ttyS0", 115200, "N", 8, 1, logger=logging.getLogger())
mb.set_slave(1)
# or
# mb = Modbus.TCP("localhost", 1502)
mb.connect()
mb.write_registers(0, [16, 17])
data = mb.read_registers(0, 2)
logging.info("REGISTERS: %s", [hex(n) for n in data])
Benchmarks
Reading one million registers.
*The memory plots exclude the Python interpreter overhead (~10.3 MB).
benchmark.csv
Package;Time;RSS
ctypes_modbus;30.28;4596
pylibmodbus;28.48;7672
pymodbus;40.73;17328
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ctypes_modbus-0.1.0.tar.gz.
File metadata
- Download URL: ctypes_modbus-0.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
549033688832d4f1230f7d0ddde8b1c831206b005a15b142ddde7c46dac0f8b7
|
|
| MD5 |
7a30184d96aae09eee0acb90b7731852
|
|
| BLAKE2b-256 |
d4470c83cfe03c55fa29c82462f0c9dfc1cfb9044fd7e2312888d3eda527652a
|
File details
Details for the file ctypes_modbus-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ctypes_modbus-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3be7b2e3a7e4812e142f7ac387aa7d0da5fdfdc59a74502bafba36454c409d91
|
|
| MD5 |
dece1f96958566705175e332ed5a96dc
|
|
| BLAKE2b-256 |
e4c5e86a1e699fd54a4191ab349a9fde1c411fb506f921c704e7f208534741c7
|