跳到主要内容

FATEK FBs 驱动

概述

FATEK FACON FBs 系列 PLC 的 ASCII 通信。基于 FBs Series Communication Protocol Manual 公开规范自行实现,不依赖外部库 / GitHub 代码。

项目
opc_typeFATEK
实现类plantpulse.driver.protocol.fatek.FatekDriver
(无 —— 自行实现,依据 FATEK FBs 手册)
read良好 (cmd 44 / 46)
write良好 (cmd 45 / 47)
默认端口500
安全

类 / 结构

FatekDriver (BaseProtocolDriver)
├── Socket / InputStream / OutputStream
├── station — 0~255 (디폴트 1)
├── synchronized read/write
├── Addr (device, index, bit)
├── parseAddress(raw) — R/D/M/X/Y/T/C/WX/WY/WM
├── formatBitItem / formatWordItem
└── sendAndReceive(cmd, body) — STX/ETX/LRC 검증

connect() 之后立即调用 cmd 41 (status) 作为握手,但即使失败也保持连接(PLC 可能不支持)。


wire 格式摘要

Request : STX <station 2hex> <cmd 2hex> <data ASCII> <LRC 2hex> ETX
Response: STX <station 2hex> <cmd 2hex> <error-1char> <data> <LRC 2hex> ETX
STX = 0x02, ETX = 0x03
LRC : STX 다음부터 LRC 직전까지 XOR (ASCII char 단위) → 2자리 hex 대문자

主要命令

cmd动作
40Read system status
41Get PLC run/stop/error/break status(用于握手)
42Run/Stop PLC
44Read data from registers(连续字)
45Write data to registers(连续字)
46Read individual data(单个位 / 混合)
47Write individual data

sendAndReceive() 中,若响应 error code 不为 '0'IOException(例如:'2' illegal value、'4' illegal command、'5' checksum、'6' illegal address、'A' PLC password locked)。


OPC 注册选项 (options)

含义默认值
stationPLC station ID (0~255)1
connect-timeoutms3000
read-timeoutms3000

标签地址格式

表示含义bit/word
R0 / R100General registerword
D100Data registerword
WX10 / WY0 / WM10Input/Output/Internal wordword
M100Internal relaybit
X0 / Y0 / S0Input / Output / Stepbit
T0 / C0Timer / Counter 当前值word(cmd 44 中的 RT/RC 表示)

formatWordItem()

  • R/D → <dev>+5자 index(共 6 字符)
  • WX/WY/WM → <dev>+4자(共 6 字符)
  • T → RT + 4 字符,C → RC + 4 字符

数据编码 / 解码

wordCountFor(dt, fmt) 决定 1/2/4 个字。decodeWords() 负责转换 —— FATEK FB 多字采用 little-endian word order(低位字在前)。

format / data_type字数备注
W / WORD / UI / UW1signed/unsigned 16
B / BYTE1(直接使用 16-bit 响应)
DW / DWORD / Int322signed 32
UDW / UInt322unsigned 32
REAL / FLOAT / Float2IEEE 32-bit
LREAL / DOUBLE / Double4IEEE 64-bit
LW / LWORD / Int644signed 64

支持 / 不支持

  • ✅ cmd 44 / 45(连续 N 个字 read/write)
  • ✅ cmd 46 / 47(单个位 read/write)
  • ✅ STX/ETX/LRC 帧校验 + station/cmd 回显校验
  • ✅ 32 / 64-bit 多字、Float、Double
  • ❌ 多个位同时 read/write(cmd 46/47 的 mixed 项)
  • ❌ Run/Stop PLC (cmd 42)
  • ❌ Timer/Counter contact bit 分离(当前仅支持 word)

测试覆盖率

test/java/plantpulse/driver/protocol/fatek/

测试数
FatekDriverTest48

共 48 个测试 —— LRC、buildRequest、地址解析器、字编码/解码、error code。


参考

  • FATEK FBs Series Communication Protocol Manual(厂商公开)
  • 代码:src/plantpulse/driver/protocol/fatek/FatekDriver.java