Metadata-Version: 2.4
Name: moat-modbus
Version: 0.10.4
Summary: Modular async modbus client and server
Author-email: Matthias Urlichs <matthias@urlichs.de>
Project-URL: homepage, https://m-o-a-t.org
Project-URL: repository, https://github.com/M-o-a-T/moat
Keywords: MoaT
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Framework :: AsyncIO
Classifier: Framework :: Trio
Classifier: Framework :: AnyIO
Classifier: Development Status :: 4 - Beta
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: anyio~=4.2
Requires-Dist: moat-lib-modbus~=0.1.1
Requires-Dist: moat-lib-codec~=0.4.22
Requires-Dist: anyio-serial
Requires-Dist: moat-util~=0.64.13
Requires-Dist: asyncscope~=0.8.3
Requires-Dist: moat-lib-run~=0.2.4
Requires-Dist: moat-lib-path~=0.4.4
Dynamic: license-file

# moat-modbus

% start synopsis
% start main

This is an anyio-enabled async Modbus client/server, built on the sans-IO
protocol core ``moat-lib-modbus`` (no ``pymodbus`` dependency).

% end synopsis

## Usage

Check the example client and server for rudimentary usage.

Documentation patches gladly accepted.

## Background

`moat-modbus` diverges from `pymodbus` in that it does not expose a "data
store" context to the user. Instead, every bus value is a separate object,
with arbitrary length and encapsulating its own encoding and decoding rules.

A Modbus server exposing writeable registers only needs to

- register the value in question
- wait for it to be written to

The rest happens behind the scenes.

## Device Server

As some Modbus devices only allow ine server at a time, MoaT's Modbus
supports a simple bidirectional gateway.

How to get there:

- Write a generic device description. Put it in the modbus-data repository.
- Add an interface overlay that describes which topic to send the data to /
  which topic to read.
- Run `moat modbus dev poll FILE.yaml`. You can use a generic systemd
  service if you copy the file to `/etc/moat/modbus`.

The values can be modified (factor+offset); the gateway works in both
directions (command/state).

## Bus log

MoaT-Modbus can write a structured log of the Modbus messages on a bus:
`moat modbus monitor --log FILE` (with `--log-check SECONDS` to
follow log rotation instead of creating the file), or `log` entries in a poller's
configuration (see {doc}`dev-poll`). Each record contains the device
name, a sequence number, the wall-clock time, and the decoded message.
Several loggers may append to the same file.

`moat modbus log FILE…` prints the records, merged by time, one per
line; with `--long`, in detail and with the time since the previous
record.

% end main

## MQTT / MoaT-KV interface

MoaT-Modbus includes a server that's informed by a device profile. This server
acts as a bidirectional gateway from and to MQTT and/or MoaT-KV storage.

See "gateway.rst" for details.

### TODO

- configurable codecs
- get/set attributes
- pack multiple values into a message
- read-after-write if no slot
