跳到主要内容

EtherNet/IP (Logix) 驱动

概述

基于 CIP (Common Industrial Protocol) 的 EtherNet/IP。主要用于与 Allen-Bradley / Rockwell ControlLogix / CompactLogix PLC 通信。

项目
opc_typeEIP
实现类plantpulse.driver.protocol.eip.EIP_34_Driver
digitalpetri/ethernet-ip (CipClient + GetAttributeListService)
read✅ (attribute list raw bytes → String)
write❌ (需单独调用 service)
安全
与 PLC4j 的差异

与其他 PLC 驱动不同,本驱动不使用 PLC4j,而是直接使用 digitalpetri/ethernet-ip (继承 BaseProtocolDriver 而非 PLC4jProtocolDriver)。 lib 中虽然也包含 PLC4j 的 plc4j-driver-eip,但本类并未使用。


OPC 注册表单

字段含义示例
opc_agent_ipPLC IP192.168.0.90
opc_agent_portEIP 端口44818
timecycle轮询周期 (ms)1000
options.backplanebackplane 编号1 (default)
options.local-slotCPU slot 编号0 (default)

内部 timeout 固定为 2 秒 (Duration.ofSeconds(2))。


标签 plc_address 格式

EIP 的 raw read 按 CIP class / instance / attribute 坐标工作。在 Edge 中于 plc_address 字段以 <class>,<instance>,<attribute> 格式(十进制或十六进制)输入。

表示含义
0x6B,1,1Symbol class 0x6B, instance 1, attribute 1
0x6C,1,1Template class
0x01,1,7Identity object 的 Product Name
符号标签 (Tag1.Member)

Logix 中常见的符号标签 read (MyController:Tag1) 需要使用单独的 service (Read Tag Service),而本驱动仅使用 raw GetAttributeListService。 如需符号 read,则须切换到 PLC4j EIP 驱动或后续实现。


data_type / format 映射

data_typeformat备注
String(empty)将响应 raw bytes 原样累加为 String
Integer / Float / …(empty)在后处理中转换类型。当前驱动为 raw bytes → String

在后处理 (PLCValueFomula / Sparkplug DataTypeMapper) 中转换为 data_type


常见错误与解决

消息 / 现象原因解决
Connection timeout端口 44818 被阻断、EIP 未启用在 RSLogix / Studio5000 中启用 EtherNet/IP module
Forward Open failurerack/slot 不匹配修正 options.backplane / options.local-slot
Class/Instance not foundclass / instance ID 错误用 Studio5000 的 Tag Browser 或 wireshark 确认响应
数值显示异常byte 直接转换为 String在后处理中应用按 4-byte little-endian 解析的 fomula

curl 注册示例

curl -X POST http://<edge-host>/api/v1/opc \
-H "Content-Type: application/json" \
-d '{
"opc_id": "OPC_EIP_LOGIX",
"opc_type": "EIP",
"opc_name": "Logix L83E",
"opc_agent_ip": "192.168.0.90",
"opc_agent_port": "44818",
"site_id": "SITE_00001",
"auto_collect": true,
"timecycle": 1000,
"options": {
"backplane": "1",
"local-slot": "0"
},
"tag_list": [
{
"tag_id": "OPC_EIP_LOGIX_TAG_00001",
"tag_name": "ProductName",
"plc_address": "0x01,1,7",
"data_type": "String"
}
]
}'

示例集合(按数据类型)

EIP raw read 将 <class>,<instance>,<attribute> 坐标(十进制或 0x 前缀十六进制)的 raw bytes 累加为 String。在后处理中转换为 data_type / fomula

CIP 坐标格式

plc_address含义
0x01,1,1Identity → Vendor ID
0x01,1,2Identity → Device Type
0x01,1,7Identity → Product Name (String)
0x6B,1,1Symbol Class (Logix tag list) instance 1 attribute 1
0x6C,1,1Template Class
0x6C,2,1Template Class instance 2
0x73,1,1Connection Manager

按数据类型映射

data_typeformatplc_address 示例备注
String(empty)0x01,1,7Product name (raw bytes 原样转 String)
Integer(empty)0x01,1,1Vendor ID。raw bytes → 用 fomula 按 little-endian 解析
Integer(empty)0x01,1,2Device Type
Boolean(empty)0x01,1,8Status word (bit 提取在后处理中完成)
Float(empty)<class>,<inst>,<attr>4-byte raw 响应 → 后处理
当前驱动的限制

EIP_34_Driver 仅调用 GetAttributeListService。如需读取符号标签 (MyController:Tag1.Member),则需要另行实现基于 ControlLogix Read Tag Service 的方案。由于 lib 中已包含 PLC4j EIP,后续可进行切换。

Formula 应用

用途data_typefomula备注
整数 raw 修正Integer${VALUE}*1用于无转换直通
合并两个 16-bit 值Integer${TAG_HI}*65536+${VALUE}合成 hi/lo 两个 attribute
单位换算Float${VALUE}*0.1raw 整数缩放

curl 综合示例

curl -X POST http://<edge-host>/api/v1/opc \
-H "Content-Type: application/json" \
-d '{
"opc_id": "OPC_EIP_FULL",
"opc_type": "EIP",
"opc_name": "Logix Full",
"opc_agent_ip": "192.168.0.90",
"opc_agent_port": "44818",
"site_id": "SITE_00001",
"auto_collect": true,
"timecycle": 1000,
"options": { "backplane": "1", "local-slot": "0" },
"tag_list": [
{"tag_id":"OPC_EIP_FULL_T01", "tag_name":"VendorId", "plc_address":"0x01,1,1", "data_type":"Integer"},
{"tag_id":"OPC_EIP_FULL_T02", "tag_name":"DeviceType", "plc_address":"0x01,1,2", "data_type":"Integer"},
{"tag_id":"OPC_EIP_FULL_T03", "tag_name":"ProductName","plc_address":"0x01,1,7", "data_type":"String"},
{"tag_id":"OPC_EIP_FULL_T04", "tag_name":"Status", "plc_address":"0x01,1,5", "data_type":"Integer"}
]
}'