Panasonic MEWTOCOL 驱动
概述
Panasonic FP 系列(FP0R / FP-X / FPΣ / FP7)的 ASCII 通信协议 MEWTOCOL-COM。 仅依据 Panasonic 公开 用户手册(ARCT1F320、ARCT1F313 等)中的帧格式 / 命令 / 设备代码 / BCC 算法 自行实现。未借用任何外部 GitHub 代码。
| 项目 | 值 |
|---|---|
opc_type | MEWTOCOL |
| 实现类 | plantpulse.driver.protocol.mewtocol.MEWTOCOLDriver |
| 库 | (无 —— 自行实现。ARCT1F320) |
| read | 良好(RD / RC) |
| write | 良好(WD / WC) |
| 默认端口 | 9094(FP-X / FP7 TCP) |
| 安全 | 无 |
类 / 结构
MEWTOCOLDriver (BaseProtocolDriver)
├── Socket / InputStream / OutputStream
├── station — "01" 디폴트, 옵션 station 으로 변경
├── ioLock — synchronized exchange()
├── ParsedAddress.parse() — 디바이스/wordIndex/bitIndex 분해
├── computeBcc(byte[]) — '%' ~ ETX 위치 직전 XOR → 2자리 hex
└── decodeRdResponseHex / encodeWords — 16/32/64-bit
wire 格式摘要
요청 : '%' <station 2> '#' <cmd 2> <data> <BCC 2hex> CR
응답 : '%' <station 2> '$' <cmd 2> <data> <BCC 2hex> CR (정상)
'%' <station 2> '!' <error-2hex> <BCC 2hex> CR (에러)
BCC : '%' 부터 BCC 직전 (= ETX 위치) 까지 XOR
CR : 0x0D (LF 는 무시)
支持的命令
| cmd | 动作 | 格式(data 部分) |
|---|---|---|
RD | 字 read(DT/LD/FL/WX/WY/WR) | <dev-1char><start-5digits><end-5digits> |
RC | 位 read(单点,X/Y/R/L/T/C) | RCS<dev-1char><wordAddr4><bit-1hex> |
WD | 字 write | <dev><start5><end5><word1 hex 4>... |
WC | 位 write(单点) | WCS<dev><wordAddr4><bit1><val1> |
字的 hex 按手册规定为 LSB 字节在前(例如 0x1234 字 → 响应 hex 3412)。
OPC 注册选项(options)
| 键 | 含义 | 默认值 |
|---|---|---|
station | 站号(2 位) | 01 |
connect-timeout | ms | 3000 |
read-timeout | ms | 3000 |
normalizeStation() 会将 1 位输入("1")自动补正为 "01"。
标签地址格式
| 表示 | 含义 |
|---|---|
DT0 | Data Register 0(16-bit) |
LD100 | Link Data 100 |
FL10 | File Register 10 |
WX0 / WY0 / WR0 | I/O / Internal word |
R0.5 | Internal Relay word 0 的 bit 5 |
R0005 | 4 位 = 字 3 位 + 位 1 位(= R0.5) |
X0.0 / Y0.5 | Input/Output bit |
T0 / C0 | Timer / Counter(按单个位处理) |
数据编码 / 解码
wordCountFor(dt, fmt) 决定 16/32/64-bit(1/2/4 个字)。
decodeWords(words, dt, fmt) 负责多字 → 数值转换:
| format / data_type | 字数 | 转换 |
|---|---|---|
DW / Int32 | 2 | (words[1]<<16) | words[0](low word first),signed |
UDW / UInt32 | 2 | unsigned 32 |
REAL / Float | 2 | Float.intBitsToFloat(...) |
LREAL / Double | 4 | Double.longBitsToDouble(...) |
LW / Int64 | 4 | signed 64 |
| (默认) | 1 | signed 16 |
错误代码映射
decodeError(code) 将手册中的典型错误转换为中文(部分):
| code | 说明 |
|---|---|
20 | Relay/register 编号错误 |
21 | 超出 Memory 区域 |
22 | Latch 错误 |
40 | BCC 错误(接收侧) |
41 | Format 错误 |
42 | 不支持的命令 |
60 | Parameter 错误 |
66 | Address 错误 |
支持 / 不支持
- ✅ RD / WD(连续 N 个字)
- ✅ RC / WC(单个位)
- ✅ 32 / 64-bit 多字、Float、Double
- ❌ RC 多点(RCP — Preset multi)
- ❌ RT / WT(Timer / Counter EV/SV 分离 read)
- ❌ MEWTOCOL-7 / MEWTOCOL-DAT 扩展
测试覆盖率
test/java/plantpulse/driver/protocol/mewtocol/
| 类 | 测试数 |
|---|---|
MEWTOCOLDriverTest | 39 |
共 39 项测试 —— BCC、帧构建器、地址解析器、RD 响应解码、WC bit、错误映射。
参考
- Panasonic ARCT1F320 FP-X User Manual MEWTOCOL-COM
- Panasonic ARCT1F313 FP Series Programming Manual
- 代码:
src/plantpulse/driver/protocol/mewtocol/MEWTOCOLDriver.java