跳到主要内容

HART-IP 驱动

概述

HART (Highway Addressable Remote Transducer) 的 IP 变体。通过 IP 网关对 4-20 mA 工业仪表进行数字化 read/write。基于 HCF 公开的 HART-IP 规范。

项目
opc_typeHART
实现类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 线程
HartIpHeader13 字节 HART-IP 头(version, type, id, status, sequence, byteCount BE)
HartCommandHART 命令 PDU 构建器 — preamble + 0x82 + 5 字节 address + cmd + byteCount + data + XOR
HartChecksumlongitudinal XOR(不含 preamble)
HartDecodefloat32 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-typeprimary / secondaryprimary
options.inactivity-msSession inactivity close time600000(10 分钟)
options.keepalive-msKeepAlive 发送周期30000
options.connect-timeoutTCP connect 超时5000
options.read-timeoutread SO 超时5000

标签 plc_address 格式

表示法含义解码
11:pvcmd 1 — Read PVfloat32 BE(status 2 字节之后 offset 3)
3:0 ~ 3:33:pv/sv/tv/qvcmd 3 — PV/SV/TV/QV4 × float32 BE(简化模型)
1313:tagcmd 13 — Tag 8 charpacked-ASCII(3 字节 → 4 字符)

write 地址(与 address.getValue() 配合使用):

表示法含义value 格式
6 / polling-addresscmd 6 — Write Polling Address0..63 整数
17 / messagecmd 17 — Write Message32 字符 packed-ASCII
18 / tag / descriptor / datecmd 18 — Tag/Descriptor/Datetag|desc|DD/MM/YY 或按 sub-field 分别指定
19 / final-assemblycmd 19 — Final Assembly Number0..16777215
22 / long-tagcmd 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/

测试验证内容
HartIpHeaderTest13 字节头 round-trip
HartChecksumTestXOR 已知 vector
HartCommandTest / HartCommandWriteTestcmd 0/1/3/13/6/17/18/19/22 PDU 构建
HartDecodeTest / HartEncodeTestfloat32 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。