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 RH 769 n=1
heat-stiebel IN  u3 RH: = [4]
localhost:503 OUT u3 #12 WH 304 = 5
srv:heat-stiebelfake dropped 99 03

The function is R (read) or W (write), followed by the type: H (holding register), I (input register), C (coil) or D (discrete input). A reply has a colon after the function; #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.2

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.2
File Size Uploaded Provenance Actions
moat_lib_modbus-0.1.2.tar.gz 16.5 kB Without provenance Details for moat_lib_modbus-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 32.4 kB

Release files / moat_lib_modbus-0.1.2.tar.gz

Download URL moat_lib_modbus-0.1.2.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
cc66e439d2ecfbee9b037294a5d393934acee49eb2d167c29465f99b877dc68d
BLAKE2b-256 checksum
How to use checksums
b6e882a712838d1aec4c3c630919ef0857e7627957bfd3f32587e6eb63ed2465
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.2-py3-none-any.whl

Download URL moat_lib_modbus-0.1.2-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9cdcb17b24dd0694502ac751ec4f32a94104cc8867cb6b419cc0b4702b130fee
BLAKE2b-256 checksum
How to use checksums
ed655d19a4d923eb075aaa3f06a8b2452d5efd9d5b7519269e634b7f3d7a10d8
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.2

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