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 만 발생.