EtherNet/IP (Logix) 驱动
概述
基于 CIP (Common Industrial Protocol) 的 EtherNet/IP。主要用于与 Allen-Bradley / Rockwell ControlLogix / CompactLogix PLC 通信。
| 项目 | 值 |
|---|---|
opc_type | EIP |
| 实现类 | plantpulse.driver.protocol.eip.EIP_34_Driver |
| 库 | digitalpetri/ethernet-ip (CipClient + GetAttributeListService) |
| read | ✅ (attribute list raw bytes → String) |
| write | ❌ (需单独调用 service) |
| 安全 | 无 |
与其他 PLC 驱动不同,本驱动不使用 PLC4j,而是直接使用 digitalpetri/ethernet-ip (继承 BaseProtocolDriver 而非 PLC4jProtocolDriver)。
lib 中虽然也包含 PLC4j 的 plc4j-driver-eip,但本类并未使用。
OPC 注册表单
| 字段 | 含义 | 示例 |
|---|---|---|
opc_agent_ip | PLC IP | 192.168.0.90 |
opc_agent_port | EIP 端口 | 44818 |
timecycle | 轮询周期 (ms) | 1000 |
options.backplane | backplane 编号 | 1 (default) |
options.local-slot | CPU 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,1 | Symbol class 0x6B, instance 1, attribute 1 |
0x6C,1,1 | Template class |
0x01,1,7 | Identity object 的 Product Name |
Tag1.Member)Logix 中常见的符号标签 read (MyController:Tag1) 需要使用单独的 service (Read Tag Service),而本驱动仅使用 raw GetAttributeListService。
如需符号 read,则须切换到 PLC4j EIP 驱动或后续实现。
data_type / format 映射
data_type | format | 备注 |
|---|---|---|
| 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 failure | rack/slot 不匹配 | 修正 options.backplane / options.local-slot |
Class/Instance not found | class / 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,1 | Identity → Vendor ID |
0x01,1,2 | Identity → Device Type |
0x01,1,7 | Identity → Product Name (String) |
0x6B,1,1 | Symbol Class (Logix tag list) instance 1 attribute 1 |
0x6C,1,1 | Template Class |
0x6C,2,1 | Template Class instance 2 |
0x73,1,1 | Connection Manager |
按数据类型映射
data_type | format | plc_address 示例 | 备注 |
|---|---|---|---|
String | (empty) | 0x01,1,7 | Product name (raw bytes 原样转 String) |
Integer | (empty) | 0x01,1,1 | Vendor ID。raw bytes → 用 fomula 按 little-endian 解析 |
Integer | (empty) | 0x01,1,2 | Device Type |
Boolean | (empty) | 0x01,1,8 | Status 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_type | fomula | 备注 |
|---|---|---|---|
| 整数 raw 修正 | Integer | ${VALUE}*1 | 用于无转换直通 |
| 合并两个 16-bit 值 | Integer | ${TAG_HI}*65536+${VALUE} | 合成 hi/lo 两个 attribute |
| 单位换算 | Float | ${VALUE}*0.1 | raw 整数缩放 |
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"}
]
}'