pamoja-modbus
Modbus RTU requests and replies with CRC-16/MODBUS for RS485 field devices. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.
Install
pip install pamoja-modbus
from pamoja import modbus
This pulls in pamoja-native, the compiled engine. pip install pamoja is the whole framework in one package.
Example
The script the test suite runs, spliced here as it ran.
From bindings/python/guides/modbus.py:
from pamoja.core import PamojaError
from pamoja.modbus import parse_frame, read_holding_registers, read_holding_registers_reply
# The device this gateway polls: a power meter at unit 17, whose manual says the three
# registers holding voltage, current and a fault word start at address 107.
METER = 17
FIRST_REGISTER = 107
# Ask it for those three registers. The frame is complete, checksum included, exactly as
# it goes out on the wire.
request = read_holding_registers(METER, FIRST_REGISTER, 3)
print(f"polling unit {METER}, {len(request)} bytes out")
# A stand-in for the meter. On a running gateway this frame arrives over RS485; here the
# library builds what a meter reporting those three values would send back.
from_the_meter = read_holding_registers_reply(METER, [2301, 418, 0])
# Everything below is the gateway's own code. A reply carries its own checksum, so the
# frame is validated before any value is read out of it.
reply = parse_frame(from_the_meter)
registers = reply.registers()
print(f"voltage {registers[0] / 10:.1f} V")
print(f"current {registers[1] / 100:.2f} A")
print(f"faults {registers[2]}")
# One flipped bit anywhere in the frame fails the checksum, which is the whole point of
# carrying one over a long RS485 run.
mangled = bytearray(from_the_meter)
mangled[2] ^= 0xFF
try:
parse_frame(bytes(mangled))
print("mangled frame accepted, which should never happen")
except PamojaError as error:
print(f"mangled frame rejected: {error}")
The same capability in every language
| Language | Package | Reference |
|---|---|---|
| Rust | pamoja-modbus |
reference, docs.rs, install |
| TypeScript | @pamoja/modbus |
reference, install |
| Python | pamoja-modbus |
reference, install |
| C# | Pamoja.Modbus |
reference, install |
Documentation
pamoja.modbusreference, every class and function in this module.- The Modbus RTU guide, with the same example in Rust, TypeScript, and C#.
- Every capability, and the install page.
License
MIT
Release files for pamoja-modbus 0.1.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pamoja_modbus-0.1.18.tar.gz | 5.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pamoja_modbus-0.1.18-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.3 kB
Release files / pamoja_modbus-0.1.18.tar.gz
| Download URL | pamoja_modbus-0.1.18.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
277bb7454586a724c8ff958c6d0bb7887659b9c9bf2b57a54a2a648a3458d697
|
|
BLAKE2b-256 checksum How to use checksums |
679b2542a348ca9188a697179729aac5949ae2aa589b7df0195633ff50115281
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / pamoja_modbus-0.1.18-py3-none-any.whl
| Download URL | pamoja_modbus-0.1.18-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
44c587cc9d4faa39728ba59bceaa27c2225440ead098d2481d73b4a9bfe81124
|
|
BLAKE2b-256 checksum How to use checksums |
8946eee5f83d7fd2933b7a979e0af8792ddf81a1c6fa7cc71c6057eefdf4a2c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|