# Modbus RTU serial collection

Copy [the example configuration](../examples/config/modbus_rtu.json). Set
`serial_port` to the actual port, such as `COM3` on Windows or `/dev/ttyUSB0`
on Linux. Give the gateway account access to that port. For RS-485, use a
serial adapter with automatic transmit-direction control. Configure one
collection job per port.

| Setting | Values |
| --- | --- |
| `baud` | 1200, 2400, 4800, 9600, 19200 (default), 38400, 57600 or 115200 |
| `parity` | `even` (default), `odd` or `none` |
| `stop_bits` | 1 with parity or 2 without parity by default. Can be set explicitly |
| `unit` | 1–247 |
| `function` | 3 for holding registers or 4 for input registers |
| `address`, `count` | Zero-based address and 1–125 registers within the address range |
| `timeout_ms`, `interval_ms` | Default 1000 ms each. Timeout 25–60000 ms and interval 1–60000 ms |

Set the serial format and unit to match the device. Field offsets are relative
to the starting register. The same numeric layouts and word order as Modbus TCP
are available. Use `pipeline` mappings for scaling and units, then select a
console or JSON Lines sink.

```text
moon run cmd/moonedge --target native -- check-config examples/config/modbus_rtu.json
moon run cmd/moonedge --target native -- run examples/config/modbus_rtu.json
```

The gateway checks response CRC, unit, function and register count. A partial
reply that exceeds the timeout closes the port and follows the configured
reconnect policy. Collection uses unicast reads. The focused verification
covers reference frames and the Linux pseudo-terminal path. Physical serial
devices still require validation at the deployment site.
