Modbus RTU ドライバ (RTU-over-TCP)
概要
Modbus RTU — RS-485 / RS-232 シリアル上で動作する Modbus の派生仕様です。2026-07 にネイティブ実装へ書き換えされ、旧 Apache PLC4j modbus-rtu への委譲は削除されました。現在は plantpulse-plc-protocol のネイティブ RTU-over-TCP 実装(ModbusRtuOverTcp)を使用します。シリアル RTU 機器はシリアル-TCP コンバータで公開し、host:port として登録します — ドライバが扱うのは TCP ソケットのみです。
| 項目 | 値 |
|---|---|
opc_type | MODBUS_RTU |
| 実装クラス | plantpulse.driver.protocol.modbus.ModbusRTUDriver |
| ライブラリ | 独自ネイティブ (plantpulse-plc-protocol の ModbusRtuOverTcp) |
| 継承 | AbstractNativeModbusDriver (PLC4j ではありません) |
| read | ✅ |
| write | ✅ (coil / holding-register) |
| セキュリティ | なし (Modbus 標準そのものの制約) |
ネイティブドライバは TCP ソケットのみを扱います。RS-485/232 機器はシリアル↔TCP コンバータ(例: USR-TCP232、Moxa NPort)で公開し、そのコンバータの IP:ポートを opc_agent_ip / opc_agent_port として登録します。baud-rate / parity / stop-bit などのシリアルパラメータはコンバータ側で設定し、ドライバはこれらを使用しません。
クラス構造
AbstractNativeModbusDriver (주소 파싱 · 디코드 · read/write 공통)
└── ModbusRTUDriver — createClient() = new ModbusRtuOverTcp(unitId, host, port)
└── ModbusTCPDriver — createClient() = new ModbusTcp(unitId, host, port)
RTU framing(slave address + PDU + CRC-16 LE)は ModbusRtuOverTcp が TCP ストリーム上で処理します。
OPC 登録オプション
| フィールド | 意味 | デフォルト |
|---|---|---|
opc_agent_ip | シリアル-TCP コンバータの IP | 192.168.0.60 |
opc_agent_port | コンバータの TCP ポート | コンバータの設定値 (例 502 / 4001) |
options.unit-id (別名 unit-identifier) | Modbus スレーブ ID (1..247) | 1 |
options.request-timeout | 応答タイムアウト (ms) | 5000 |
baud-rate/parity/stop-bitsなどのシリアルパラメータはコンバータ側の設定であり、ドライバは受け取りません。
タグ plc_address 形式
Modbus TCP と同一 — <area>:<address>[:<datatype>][[<count>]] (PLC4X modbus4x 文法を維持、1-based):
| 表記 | 意味 |
|---|---|
coil:1 | FC 01 — Read Coils |
discrete-input:1 | FC 02 — Read Discrete Inputs |
holding-register:1 | FC 03 — Read Holding Registers (signed 16) |
holding-register:1:UINT | unsigned 16 |
holding-register:1:DINT | signed 32 (2 register、MSWord-first) |
holding-register:1:REAL | 32-bit float (2 register) |
holding-register:100:STRING[10] | 10-word ASCII |
input-register:1 | FC 04 — Read Input Registers |
詳細な表記ルールおよび data_type · format のマッピングは Modbus TCP ドライバのページと同一です。
Write (ネイティブ)
coil:N→ single coil write (Boolean)。holding-register:N[:TYPE]→ datatype ごとの register write (REAL/DINT= MSWord-first の 2 レジスタ、それ以外は単一 16-bit)。discrete-input/input-registerは read-only。
未対応の範囲
- 直接シリアルポート(
/dev/ttyUSB0) — 未対応。シリアル-TCP コンバータ経由が前提です。 - Multi-master / token-passing — 単一 master のみ。
- Modbus ASCII (コロン区切り、LRC チェックサム) — RTU framing のみ。
参考
- Modbus over Serial Line (V1.02) — Modbus-IDA.
- コード:
plantpulse-edge-driver/src/plantpulse/driver/protocol/modbus/ModbusRTUDriver.java+plantpulse-plc-protocolのmodbusパッケージ。 - 運用: USB ↔ RS-485 アダプタではなくシリアル-TCP コンバータを使用し、終端抵抗 120 Ω を確認してください。unit-id / baud が誤っていると timeout のみが発生します。