跳到主要内容

KNXnet/IP 驱动

概述

KNXnet/IP —— 在楼宇自动化(照明 / 遮阳 / 空调)中,将标准化的 KNX 总线通过 IP 进行隧道传输。2026-07 原生重写 —— 已移除原先对 Apache PLC4j knxnet-ip 的委托(2026-07 P2 迁移)。目前使用 plantpulse-plc-protocol 的自研实现(KnxNetIpClient UDP 3671 tunneling + KnxGroupAddress + KnxDpt)。

项目
opc_typeKNXNET
实现类plantpulse.driver.protocol.knxnet.KNXnetDriver
自研原生 (plantpulse-plc-protocolknx —— UDP tunneling)
继承BaseProtocolDriver (非 PLC4j)
getProtocol()"knxnet-ip" (保留旧 PLC4X scheme 表记 —— 兼容日志/诊断)
默认端口3671 (UDP)
状态稳定 (TUNNELING)
readOK (GroupValueRead)
writeOK (GroupValueWrite —— 必须带 DPT 后缀)
安全无 (不支持 KNX Secure)
仅支持 TUNNELING —— 不支持 ROUTING

原生客户端仅支持 TUNNELING(单播)。不支持多播 ROUTING —— 若指定 connection-type=routing,将输出警告日志后按 tunneling 方式继续。


类结构

BaseProtocolDriver
└── KNXnetDriver — connect() 에서 KnxNetIpClient(host, port) tunneling 세션 수립

报文流程:CONNECT_REQUEST(0x0205) → RESPONSE(channelId) → TUNNELING_REQUEST(cEMI L_Data.req GroupValueRead) → ACK → 网关发出 L_Data.ind GroupValueResponse(并回送 ACK) → CONNECTIONSTATE 心跳(30s) → DISCONNECT。read 通信失败时会将套接字置为无效(connected=false),促使 Edge 重新连接。


OPC 注册选项

字段含义默认值
opc_agent_ipKNX/IP 网关 IP192.168.1.10
opc_agent_portUDP 端口3671 (通常固定)
options.request-timeout响应超时 (ms)2000 (与旧 PLC4X 默认值相同)
options.connection-type仅支持 tunnelingtunneling

标签 plc_address 格式 (保留既有约定)

<main>/<middle>/<sub>[:<DPT>] 예) 1/0/5:DPT_Switch / 3/2/0:9.001 / 1/2/10
<main>/<sub>[:<DPT>] 2-level (main 0-31 / sub 0-2047)

DPT 后缀可使用 PLC4X 名称(DPT_Switch / DPT_Scaling / DPT_Value_Temp / DPT_Value_Length ……)或数字(1.001 / 5.001 / 9.001 / 14.056 ……),两种均可。

表记含义
1/0/5:DPT_Switch1-bit boolean (DPT 1.001)
2/1/3:DPT_Scaling0..100 % (DPT 5.001)
3/2/0:DPT_Value_Temp2-byte float (DPT 9.001)
3/2/0:9.001同上 (数字 DPT)
1/2/10省略 DPT —— 按长度进行 unsigned(RAW) 解析

支持的解码:DPT1 bool / 5.001 %scale / 5.x u8 / 7.x u16 / 9.x 2-byte float / 12·13.x u32 / 14.x float32 / 16.x string。省略 DPT 时按长度进行 unsigned(RAW) 解析 —— 若需要精确数值,请依据 ETS 工程明确指定 DPT。


支持 / 不支持

  • read:GroupValueRead → GroupValueResponse —— OK。
  • write:GroupValueWrite —— OK。必须带 DPT 后缀 —— RAW 无法编码,编码方式由 DPT 决定(与 data_type 无关)。
  • ROUTING(多播,224.0.23.12):不支持 (仅 TUNNELING)。
  • KNX Secure (IP / Data):不支持。
  • ETS 工程(.knxproj) import 自动映射:不支持 —— 需直接输入 Group Address。(旧表单中的 knxproj-file-path / knxproj-password / group-address-num-levels 选项在原生实现中被忽略 —— 已移除。)
  • KNX TP/PL/RF 直连:不支持 —— 前提是经由 IP 网关。

参考

  • KNX Standard ISO/IEC 14543-3。
  • 代码:plantpulse-edge-driver/src/plantpulse/driver/protocol/knxnet/KNXnetDriver.java + plantpulse-plc-protocolknx 包。
  • 运维:注意网关(Gira / ABB / Siemens N146)的 Tunneling 槽位数量限制 —— 通常同时连接数为 1~5 个。