Metadata-Version: 2.4
Name: modbus-tcp-cython
Version: 0.1.1
Summary: A Cython Modbus TCP client with heartbeat and multi-connection management.
Description-Content-Type: text/markdown
Dynamic: description
Dynamic: description-content-type
Dynamic: summary

# modbus-tcp-cython

A Cython Modbus TCP client with structured protocol parsing, heartbeat reconnects,
and multi-connection management.

普通请求默认会在超时或 socket 错误后自动关闭连接、重连并重试 1 次。

## Build locally

```bash
python -m venv .venv
. .venv/bin/activate
python -m pip install -U pip setuptools wheel Cython
python -m pip install .
```

## Basic usage

```python
from modbus_tcp import ModbusTcpClient

client = ModbusTcpClient(
    "192.168.180.18",
    26,
    timeout=5.0,
    request_retries=1,
    request_retry_delay=0.2,
)
client.connect()

try:
    values = client.read_holding_registers(unit_id=3, start_address=2, quantity=1)
    print(values)
finally:
    client.close()
```

## Multi-connection usage

```python
from modbus_tcp import ModbusTcpManager

with ModbusTcpManager() as manager:
    manager.add_client(
        name="line_1",
        host="192.168.180.18",
        port=26,
        unit_id=3,
        heartbeat_address=2,
        heartbeat_interval=5.0,
        request_retries=1,
        request_retry_delay=0.2,
    )
    manager.start_all()

    print(manager.read_holding_registers("line_1", 2, 1))
```
