HART-IP 驱动
概述
HART (Highway Addressable Remote Transducer) 的 IP 变体。通过 IP 网关对 4-20 mA 工业仪表进行数字化 read/write。基于 HCF 公开的 HART-IP 规范。
| 项目 | 值 |
|---|---|
opc_type | HART |
| 实现类 | plantpulse.driver.protocol.hart.HARTDriver |
| 库 | 自研 Java 实现(基于 HCF spec,无外部库依赖) |
| read | ✅ (cmd 1, 3, 13) |
| write | ✅ (cmd 6, 17, 18, 19, 22) |
| 安全 | 无(HART-IP spec 本身不含认证/加密) |
| 默认端口 | 5094 (TCP) |
类结构
| 类 | 作用 |
|---|---|
HARTDriver | 生命周期 / 地址解析器 / read·write 分发 / KeepAlive 线程 |
HartIpHeader | 13 字节 HART-IP 头(version, type, id, status, sequence, byteCount BE) |
HartCommand | HART 命令 PDU 构建器 — preamble + 0x82 + 5 字节 address + cmd + byteCount + data + XOR |
HartChecksum | longitudinal XOR(不含 preamble) |
HartDecode | float32 BE / packed-ASCII 6-bit 解码器,communication status 位解析 |
Wire 格式
HART-IP 메시지 = 13-byte 헤더 + payload
byte 0 Version 1
byte 1 Message Type 0=Request 1=Response 2=Publish 3=NAK
byte 2 Message ID 0=Session-Init 1=Session-Close 2=KeepAlive 3=PDU
byte 3 Status / Error
byte 4-5 Sequence (BE)
byte 6-7 ByteCount (BE, 헤더 13 byte 포함)
byte 8-12 Reserved (0)
PDU payload (Message ID 3) =
Preamble(0xFF×N) + Start(0x82) + Address(5) + Command(1) + ByteCount(1) + Data(N) + XOR(1)
握手:connect() 发送 Session Init(master-type 1 字节 + inactivity-close-time 4 字节 BE)→ 接收 Response。此后由 KeepAlive 后台线程周期性发送 Message ID 2。
OPC 注册选项
| 字段 | 含义 | 默认值 |
|---|---|---|
opc_agent_ip / opc_agent_port | 网关 IP / 端口 | (port 为 0 时使用 5094) |
options.master-type | primary / secondary | primary |
options.inactivity-ms | Session inactivity close time | 600000(10 分钟) |
options.keepalive-ms | KeepAlive 发送周期 | 30000 |
options.connect-timeout | TCP connect 超时 | 5000 |
options.read-timeout | read SO 超时 | 5000 |
标签 plc_address 格式
| 表示法 | 含义 | 解码 |
|---|---|---|
1 或 1:pv | cmd 1 — Read PV | float32 BE(status 2 字节之后 offset 3) |
3:0 ~ 3:3 或 3:pv/sv/tv/qv | cmd 3 — PV/SV/TV/QV | 4 × float32 BE(简化模型) |
13 或 13:tag | cmd 13 — Tag 8 char | packed-ASCII(3 字节 → 4 字符) |
write 地址(与 address.getValue() 配合使用):
| 表示法 | 含义 | value 格式 |
|---|---|---|
6 / polling-address | cmd 6 — Write Polling Address | 0..63 整数 |
17 / message | cmd 17 — Write Message | 32 字符 packed-ASCII |
18 / tag / descriptor / date | cmd 18 — Tag/Descriptor/Date | tag|desc|DD/MM/YY 或按 sub-field 分别指定 |
19 / final-assembly | cmd 19 — Final Assembly Number | 0..16777215 |
22 / long-tag | cmd 22 — Long Tag(32 字节 ISO-Latin-1) | 任意字符串 |
未支持范围
- WirelessHART (HART 7) burst 模式、publish (Message Type 2) 异步接收。
- Cmd 0/cmd 50/cmd 9 等 device-discovery 类命令 — 可后续追加。
- Long-frame 以外的 Short-frame address。
- 5 字节 device address 的 manufacturer/device-type 匹配(当前为 zero-fill)。
- Keepalive 响应的同步处理 — 为简化实现,keepalive 响应被忽略(可通过独立 receiver thread + seq correlation 增强)。
测试覆盖率
test/java/plantpulse/driver/protocol/hart/
| 测试 | 验证内容 |
|---|---|
HartIpHeaderTest | 13 字节头 round-trip |
HartChecksumTest | XOR 已知 vector |
HartCommandTest / HartCommandWriteTest | cmd 0/1/3/13/6/17/18/19/22 PDU 构建 |
HartDecodeTest / HartEncodeTest | float32 BE、packed-ASCII(双向)、BCD date |
HARTDriverAddressTest / HARTDriverWriteTest | 地址解析器 + write 分发 |
HartSpecExtraTest | 附加 spec 符合性 |
参考
- HART-IP spec — FieldComm Group / HART Communication Foundation(会员文档)。
- 代码:
plantpulse-edge-driver/src/plantpulse/driver/protocol/hart/。 - 运行时需确保网关(例如 ABB AC500-eCo、Pepperl+Fuchs HART Multiplexer)对外开放 TCP 5094。