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

Modbus RTUドライバ

概要​

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-protocol の ModbusRtuOverTcp)
継承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 として登録します。ボーレート / パリティ / ストップビットなどのシリアルパラメータはコンバータ側で設定し、ドライバはこれを使用しません。


クラス構造​

AbstractNativeModbusDriver (주소 파싱 · 디코드 · read/write 공통)
└── ModbusRTUDriver — createClient() = new ModbusRtuOverTcp(unitId, host, port)
└── ModbusTCPDriver — createClient() = new ModbusTcp(unitId, host, port)

RTUフレーミング(スレーブアドレス + 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 別レジスタ書き込み (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フレーミングのみ。

参考​

  • 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 が誤っているとタイムアウトのみが発生します。