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.0.3

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.0.3
File Size Uploaded Provenance Actions
moat_lib_modbus-0.0.3.tar.gz 15.4 kB Without provenance Details for moat_lib_modbus-0.0.3.tar.gz

Built distribution (wheel)

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

Total release size: 30.3 kB

Release files / moat_lib_modbus-0.0.3.tar.gz

Download URL moat_lib_modbus-0.0.3.tar.gz
Size 15.4 kB
Tags Source
SHA-256 checksum
How to use checksums
642f7d6ec77020db444817fcb24be0312148f9525fd773cdb1376a5cb1c7b4e5
BLAKE2b-256 checksum
How to use checksums
21d4ca796c703143d6b625e96d687ca3ccd7b0b365d2688ec4355e989609d88f
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.0.3-py3-none-any.whl

Download URL moat_lib_modbus-0.0.3-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f744c6b7c85ea801c764aaf7bedd647d6c32b9cc3bae5dd73c8b52fca2ce950
BLAKE2b-256 checksum
How to use checksums
4d3c573fa7a9532e422eaa5f8ab12c3ab6436e512dff2b40f0fbc45db3dac0fc
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.0.3

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