Skip to main content

moat-lib-modbus

% start synopsis % start main

A sans-IO Modbus protocol core implementing the minimal subset used by moat.modbus: PDU encoding/decoding for function codes 1, 2, 3, 4, 5, 6, 15, 16, plus TCP (MBAP) and RTU framers with a client/server role flag, and an RTU-only monitor role for passive bus sniffing.

Stdlib only -- no pymodbus, no anyio.

% end synopsis

Design

The library is strictly sans-IO: it never opens a socket, touches a serial port, sleeps, waits, or spawns a task. Every component is a pure transform -- bytes in -> messages/PDUs out, messages in -> bytes out. The only mutable state permitted is a framer's internal byte accumulator. All real I/O stays in moat.modbus.

Role flag

The same function-code byte decodes to a request on a server and a response on a client. The role is therefore a constructor flag on the framer itself: FramerTCP(role) / FramerRTU(role) where role is True / "server" (decode incoming bytes as requests), False / "client" (decode as responses), or -- for RTU only -- "monitor" (passive bus sniffer; see below).

Monitor mode (RTU only)

FramerRTU("monitor") taps a live master/slave RTU line without participating in it. Sending is prohibited (buildFrame raises ModbusIOError). Frames are decoded as an alternating request/response sequence starting with a request; each decoded frame flips the expectation (queryable via expecting_request). Since the framer is sans-IO it cannot time the inter-frame gap, so the caller calls resetFrame() on an inter-frame timeout, which clears the accumulator and returns the framer to expecting a request -- covering both torn partial frames and silent slaves. Monitor mode is RTU-only; FramerTCP("monitor") is rejected.

Logging

The framers log every frame they build or decode to the moat.lib.modbus.frame logger at level DEBUG, prefixed with the framer's name (its optional second argument; moat.modbus uses the host and port, or the serial port's file name):

heat-stiebel OUT u3 read_holding 769 n=1
heat-stiebel IN  u3 read_holding: = [4]
localhost:503 OUT u3 #12 write_reg 304 = 5
srv:heat-stiebelfake dropped 99 03

A reply has a colon after the function name; #N is the TCP transaction ID. Bytes that can't be decoded are logged in hex as dropped.

% end main

Metadata

Release files for moat-lib-modbus 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moat-lib-modbus 0.1.1
File Size Uploaded Provenance Actions
moat_lib_modbus-0.1.1.tar.gz 16.3 kB Without provenance Details for moat_lib_modbus-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for moat-lib-modbus 0.1.1
File Interpreter ABI Platform Actions
moat_lib_modbus-0.1.1-py3-none-any.whl Python 3 none any Details for moat_lib_modbus-0.1.1-py3-none-any.whl

Total release size: 32.0 kB

Release files / moat_lib_modbus-0.1.1.tar.gz

Download URL moat_lib_modbus-0.1.1.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
305f8e94b812b028525804fe772313f6640711e53cd0336a5f48d1729a787cf8
BLAKE2b-256 checksum
How to use checksums
1e2240835b1ef89d5462519badd6644b4a6df1259fdd2bb7b0ed001bfbae2626
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / moat_lib_modbus-0.1.1-py3-none-any.whl

Download URL moat_lib_modbus-0.1.1-py3-none-any.whl
Size 15.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4317753ed82893f4b97ef2e33dd853ee895d51c0b27dc2ed353dd0c1376d0cd1
BLAKE2b-256 checksum
How to use checksums
3b51a594ceeb5de60a4486e0e902133c418bc1de283fa2434f7ffd49fcdbfdf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for moat-lib-modbus 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page