# {{ interface_name | pascal_case }} Modbus Interface

{{ interface_description }}

Generated by MADSci template: `comm/modbus` v{{ template_version }}

## Overview

Modbus TCP/RTU communication interface for industrial automation devices
such as PLCs, sensors, and actuators. Supports reading and writing holding
registers, input registers, and coils.

## Usage

```python
from {{ interface_name }}_interface import {{ interface_name | pascal_case }}Interface

# Modbus TCP
interface = {{ interface_name | pascal_case }}Interface(host="192.168.1.100", port=502, unit_id=1)
interface.connect()

# Read holding registers
values = interface.read_holding_registers(address=0, count=10)

# Write a single register
interface.write_register(address=0, value=1234)

# Write multiple registers
interface.write_registers(address=10, values=[100, 200, 300])

# Read input registers (read-only sensor data)
inputs = interface.read_input_registers(address=0, count=5)

# Read/write coils (boolean I/O)
coils = interface.read_coils(address=0, count=8)
interface.write_coil(address=0, value=True)

interface.disconnect()
```

## Testing

Use the fake interface for development and testing without a PLC:

```python
from {{ interface_name }}_fake_interface import {{ interface_name | pascal_case }}FakeInterface

interface = {{ interface_name | pascal_case }}FakeInterface(simulated_latency=0.0)
interface.connect()
interface.write_register(address=0, value=42)
values = interface.read_holding_registers(address=0, count=1)
assert values == [42]
```

Run the test suite:

```bash
pytest test_{{ interface_name }}.py
```

## Dependencies

- `pymodbus>=3.0` for the real interface

## Common Pitfalls

- Modbus register addresses are zero-based in pymodbus but some devices use one-based addressing
- Holding registers store 16-bit unsigned integers (0-65535); use two registers for 32-bit values
- Unit IDs must match the device configuration; default is typically 1
- TCP port 502 is the Modbus standard, but some devices use alternate ports
- RTU mode requires correct baud rate, parity, and stop bit settings to match the device
- Input registers are read-only from the Modbus client perspective
