メインコンテンツまでスキップ

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_typeMODBUS_RTU
実装クラスplantpulse.driver.protocol.modbus.ModbusRTUDriver
ライブラリ独自ネイティブ (plantpulse-plc-protocolModbusRtuOverTcp)
継承AbstractNativeModbusDriver (PLC4j ではありません)
read
write✅ (coil / holding-register)
セキュリティなし (Modbus 標準そのものの制約)
直接シリアルではありません — シリアル-TCP コンバータが前提

ネイティブドライバは 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 コンバータの IP192.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:1FC 01 — Read Coils
discrete-input:1FC 02 — Read Discrete Inputs
holding-register:1FC 03 — Read Holding Registers (signed 16)
holding-register:1:UINTunsigned 16
holding-register:1:DINTsigned 32 (2 register、MSWord-first)
holding-register:1:REAL32-bit float (2 register)
holding-register:100:STRING[10]10-word ASCII
input-register:1FC 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-protocolmodbus パッケージ。
  • 運用: USB ↔ RS-485 アダプタではなくシリアル-TCP コンバータを使用し、終端抵抗 120 Ω を確認してください。unit-id / baud が誤っていると timeout のみが発生します。