OMRON FINS 驱动
概述
OMRON FINS over TCP。仅依据 OMRON 官方手册(W342、W421)的 wire spec 实现的自研 Java 版本,不依赖任何外部库或外部进程。
| 项目 | 值 |
|---|---|
opc_type | FINS |
| 实现类 | plantpulse.driver.protocol.fins.FINSDriver |
| 库 | (无 — 自研实现。OMRON W342/W421) |
| read | 良好 (Memory Area Read 0101) |
| write | 良好 (Memory Area Write 0102) |
| 默认端口 | 9600 |
| 安全 | 无 |
类 / 结构
FINSDriver (BaseProtocolDriver)
├── Socket — host:9600
├── clientNode/serverNode — connect() 의 Auto-Assign 응답에서 획득
├── sid — 0~255 순환 (요청-응답 매칭, 0 회피)
├── ParsedAddr — areaChar, wordAddr, bit
├── putBeInt / beInt — 4-byte big-endian helper
└── memAreaRead / memAreaWrite — synchronized
connect() 时通过 FINS/TCP Node Address Auto-Assign (CIP cmd=0) 获取 client/server 节点地址。
wire 格式摘要
CIP 头 (16 byte, big-endian)
'F' 'I' 'N' 'S' | length(4) | command(4) | error(4)
command = 0Auto-Assign Request、=1Auto-Assign Response、=2FINS frame sendlength= 自command起到末尾的字节数
FINS 头 (10 byte)
ICF | RSV | GCT | DNA | DA1 | DA2 | SNA | SA1 | SA2 | SID
0x80 0x00 0x02 <dn> <sn> <du> <sn> <cn> <su> <sid>
ICF=0x80:要求响应- DA1 = 服务器节点,SA1 = 客户端节点(auto-assign 结果)
Memory Area Read (MRC=01 SRC=01)
01 01 | area(1) | addrHi addrLo | bit | countHi countLo
响应 = FINS 头(10) + 01 01 + MRES(1) SRES(1) + 数据。
内存区域代码
| 区域 | word 代码 | bit 代码 |
|---|---|---|
| CIO | 0xB0 | 0x30 |
| W (Work) | 0xB1 | 0x31 |
| H (Holding) | 0xB2 | 0x32 |
| A (Auxiliary) | 0xB3 | 0x33 |
| D (DM) | 0x82 | 0x02 |
| Timer / Counter PV | 0x89 | 0x09 (完成 flag) |
由 wordAreaCode(char) / bitAreaCode(char) 负责转换。
OPC 注册选项 (options)
| 键 | 含义 | 默认值 |
|---|---|---|
dna | Destination Network Address | 0 |
da2 | Destination Unit | 0 |
sna | Source Network Address | 0 |
sa2 | Source Unit | 0 |
connect-timeout | ms | 3000 |
read-timeout | ms | 3000 |
标签地址格式
| 表示法 | 含义 |
|---|---|
D100 | DM 100 (16-bit word) |
D100.05 或 D100/5 | DM 100 的 bit 5 |
H0.05 | Holding bit |
CIO10 | CIO word |
W50 | Work word |
format 关键字(大写):
| format | 含义 |
|---|---|
X / BIT | bit |
W / WORD | signed 16 |
UI / UW / UWORD | unsigned 16 |
DW / DWORD | signed 32 (low word first) |
UDW / DUW / UDWORD | unsigned 32 |
LW / LWORD | signed 64 |
REAL / FLOAT | IEEE 32-bit |
LREAL / DOUBLE | IEEE 64-bit |
BIN[n] | 提取 word 的第 n 位 |
32/64-bit 多字数据遵循 OMRON 惯例,采用 low word first。
支持 / 不支持
- ✅ Memory Area Read / Write (MRC=01 SRC=01/02)
- ✅ Bit / Word / DWord / LWord / Float / Double
- ✅ FINS/TCP Auto-Assign 握手
- ❌ Multiple Memory Area Read (MRC=01 SRC=04)
- ❌ Program Area / Parameter Area / Clock 命令
- ❌ FINS over UDP
测试覆盖率
test/java/plantpulse/driver/protocol/fins/
| 类 | 测试数 |
|---|---|
FINSDriverTest | 38 |
共 38 项测试 — 地址解析、区域代码映射、字解码、握手模拟等。
参考
- OMRON W342 FINS Communications Reference Manual
- OMRON W421 CS/CJ Series Communications Commands Reference
- 代码:
src/plantpulse/driver/protocol/fins/FINSDriver.java