FATEK FBs 드라이버
개요
FATEK FACON FBs 시리즈 PLC 의 ASCII 통신. FBs Series Communication Protocol Manual 의 공개 스펙 기반 자체 구현. 외부 라이브러리 / 깃허브 코드 의존성 없음.
| 항목 | 값 |
|---|---|
opc_type | FATEK |
| 구현 클래스 | 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 1자> <data> <LRC 2hex> ETX
STX = 0x02, ETX = 0x03
LRC : STX 다음부터 LRC 직전까지 XOR (ASCII char 단위) → 2자리 hex 대문자
주요 명령
| cmd | 동작 |
|---|---|
40 | Read system status |
41 | Get PLC run/stop/error/break status (헬로용) |
42 | Run/Stop PLC |
44 | Read data from registers (연속 워드) |
45 | Write data to registers (연속 워드) |
46 | Read individual data (단일 비트 / 혼재) |
47 | Write individual data |
sendAndReceive() 에서 응답 error code 가 '0' 이 아니면 IOException (예: '2' illegal value, '4' illegal command, '5' checksum, '6' illegal address, 'A' PLC password locked).
OPC 등록 옵션 (options)
| 키 | 의미 | 디폴트 |
|---|---|---|
station | PLC station ID (0~255) | 1 |
connect-timeout | ms | 3000 |
read-timeout | ms | 3000 |
태그 주소 형식
| 표기 | 의미 | bit/word |
|---|---|---|
R0 / R100 | General register | word |
D100 | Data register | word |
WX10 / WY0 / WM10 | Input/Output/Internal word | word |
M100 | Internal relay | bit |
X0 / Y0 / S0 | Input / Output / Step | bit |
T0 / C0 | Timer / 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 (low word 가 먼저).
| format / data_type | 워드 수 | 비고 |
|---|---|---|
W / WORD / UI / UW | 1 | signed/unsigned 16 |
B / BYTE | 1 | (16-bit 응답 그대로) |
DW / DWORD / Int32 | 2 | signed 32 |
UDW / UInt32 | 2 | unsigned 32 |
REAL / FLOAT / Float | 2 | IEEE 32-bit |
LREAL / DOUBLE / Double | 4 | IEEE 64-bit |
LW / LWORD / Int64 | 4 | signed 64 |
지원 / 미지원
- ✅ cmd 44 / 45 (워드 N개 연속 read/write)
- ✅ cmd 46 / 47 (단일 비트 read/write)
- ✅ STX/ETX/LRC 프레임 검증 + station/cmd echo 검증
- ✅ 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/
| 클래스 | 테스트 수 |
|---|---|
FatekDriverTest | 48 |
총 48 테스트 — LRC, buildRequest, 주소 파서, 워드 인/디코드, error code.
참고
- FATEK FBs Series Communication Protocol Manual (벤더 공개)
- 코드:
src/plantpulse/driver/protocol/fatek/FatekDriver.java