跳到主要内容

Panasonic MEWTOCOL 驱动

概述

Panasonic FP 系列(FP0R / FP-X / FPΣ / FP7)的 ASCII 通信协议 MEWTOCOL-COM。 仅依据 Panasonic 公开 用户手册(ARCT1F320、ARCT1F313 等)中的帧格式 / 命令 / 设备代码 / BCC 算法 自行实现。未借用任何外部 GitHub 代码。

项目
opc_typeMEWTOCOL
实现类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-timeoutms3000
read-timeoutms3000

normalizeStation() 会将 1 位输入("1")自动补正为 "01"


标签地址格式

表示含义
DT0Data Register 0(16-bit)
LD100Link Data 100
FL10File Register 10
WX0 / WY0 / WR0I/O / Internal word
R0.5Internal Relay word 0 的 bit 5
R00054 位 = 字 3 位 + 位 1 位(= R0.5)
X0.0 / Y0.5Input/Output bit
T0 / C0Timer / Counter(按单个位处理)

数据编码 / 解码

wordCountFor(dt, fmt) 决定 16/32/64-bit(1/2/4 个字)。 decodeWords(words, dt, fmt) 负责多字 → 数值转换:

format / data_type字数转换
DW / Int322(words[1]<<16) | words[0](low word first),signed
UDW / UInt322unsigned 32
REAL / Float2Float.intBitsToFloat(...)
LREAL / Double4Double.longBitsToDouble(...)
LW / Int644signed 64
(默认)1signed 16

错误代码映射

decodeError(code) 将手册中的典型错误转换为中文(部分):

code说明
20Relay/register 编号错误
21超出 Memory 区域
22Latch 错误
40BCC 错误(接收侧)
41Format 错误
42不支持的命令
60Parameter 错误
66Address 错误

支持 / 不支持

  • ✅ 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/

测试数
MEWTOCOLDriverTest39

共 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