미쓰비시 MELSEC 드라이버
개요
미쓰비시 전기 PLC 시리즈 (Q / L / iQ-R / iQ-F / FX) 의 MC 프로토콜 (3E / 1E) 통신.
| 항목 | 값 |
|---|---|
opc_type | MELSEC |
| 구현 클래스 | plantpulse.driver.protocol.melsec.Melsec_34_Driver |
| 라이브러리 | iot-communication (plantpulse.plc.protocol.melsec) |
| read | ✅ (배치 모드) |
| write | ✅ (Boolean/Integer/Long/Float/Double/String + BIN[n] 워드 비트 RMW) |
| 보안 | 없음 (TCP 직결, 사내망 전제) |
OPC 등록 폼
| 필드 | 의미 | 예시 |
|---|---|---|
opc_agent_ip | PLC IP | 192.168.0.60 |
opc_agent_port | MC 포트 | 5000 (Q/L 기본 1500) |
timecycle | 폴링 주기 (ms) | 1000 |
options.controller-type | 시리즈 (Q_L, QnA, IQ_R, A — iQ-F/FX 는 Q_L) | Q_L |
options.read-mode | single (태그별 개별 read, default) / grouped (그룹 배치 read — 왕복 최소화) | single |
options.batch-gap-words | grouped 모드 워드 블록 병합 허용 gap | 16 (default) |
options.string-charset | String 태그 인코딩 (한글 지원) | MS949 (default) |
options.enable-iqr-extended | iQ-R 확장 디바이스 (LCN/LZ/LF/LSTN/LCC/LSC) 직접 read | false (default) |
controller-type 미지정 시 Q_L 사용 (Q / L 시리즈).
태그 plc_address 형식
iot-communication 표기. 디바이스 코드 + 인덱스 (10진) 조합.
| 표기 | 의미 |
|---|---|
D100 | Data Register 100 (16-bit) |
D100.W | 16-bit word (명시) |
D100.D | 32-bit double word (D100~D101) |
D100.F | 32-bit float (D100~D101) |
M100 | Internal relay 100 (1 bit) |
X100 | Input X100 (1 bit) |
Y100 | Output Y100 (1 bit) |
B0 | Link relay |
W100 | Link register |
R100 | File register |
D Data Register, M Coil, X/Y I/O, R File Reg, W Link Reg.
data_type / format 매핑
data_type | format | 폭 / 해석 |
|---|---|---|
| Boolean / Bool | (empty) | 1-bit (M, X, Y 등) |
| Short / Int / Integer | (empty) | 16-bit signed (W) |
| UInt16 | UI / UWORD | 16-bit unsigned |
| Int32 / DWord | DW | 32-bit signed (2 워드) |
| UInt32 | UDW | 32-bit unsigned |
| Float / REAL | REAL | 32-bit IEEE 754 |
| Double / LREAL | LREAL | 64-bit IEEE 754 |
| String | STR[N] | N 워드 → 2N 바이트 ASCII |
배치 모드 (IS_BATCH_MODE=true) 가 기본 활성. 단일 PLC 의 모든 태그를 한 번의 read 요청으로 묶어
처리합니다 (REQUEST_LIMIT=1).
흔한 에러 + 해결
| 메시지 / 증상 | 원인 | 해결 |
|---|---|---|
| Connection refused | MC 프로토콜 비활성, 포트 차단 | GX Works 에서 MELSOFT 접속 / TCP / 포트 5000 활성화 |
Wrong device code | 디바이스 코드 미지원 | controller-type 일치 확인 (Q vs iQ-R 의 디바이스 코드 차이) |
| 32-bit 값 부정합 | byte order | D100.D (signed) / D100.UD (unsigned) 명시 |
| 모든 태그가 0 | network 번호 / station 번호 mismatch | 옵션에 network, station 명시 (현재 기본 0) |
curl 등록 예시
curl -X POST http://<edge-host>/api/v1/opc \
-H "Content-Type: application/json" \
-d '{
"opc_id": "OPC_MELSEC_LINE1",
"opc_type": "MELSEC",
"opc_name": "Line1 Q-Series",
"opc_agent_ip": "192.168.0.60",
"opc_agent_port": "5000",
"site_id": "SITE_00001",
"auto_collect": true,
"timecycle": 1000,
"options": { "controller-type": "Q_L" },
"tag_list": [
{
"tag_id": "OPC_MELSEC_LINE1_TAG_00001",
"tag_name": "Counter",
"plc_address": "D100",
"data_type": "Integer"
},
{
"tag_id": "OPC_MELSEC_LINE1_TAG_00002",
"tag_name": "Pressure",
"plc_address": "D200",
"data_type": "Float",
"format": "REAL"
},
{
"tag_id": "OPC_MELSEC_LINE1_TAG_00003",
"tag_name": "PumpRun",
"plc_address": "M100",
"data_type": "Boolean"
}
]
}'
예제 모음 (데이터타입별)
미쓰비시 디바이스 코드: D (Data), M (Internal Relay), X (Input), Y (Output), B (Link Relay), W (Link Register), R (File Register), T (Timer), C (Counter).
비트 / 불 (Boolean)
data_type | format | plc_address 예 | 의미 |
|---|---|---|---|
Boolean | (empty) | M100 | Internal relay 100 |
Boolean | (empty) | X100 | Input bit X100 |
Boolean | (empty) | Y100 | Output bit Y100 |
Boolean | (empty) | B0 | Link relay 0 |
16-bit 정수
data_type | format | plc_address 예 | 의미 |
|---|---|---|---|
Integer | (empty) | D100 | Data Register (signed 16) |
Integer | (empty) | D100.W | 명시적 16-bit Word |
Integer | UI | D100 | unsigned 16 |
Integer | (empty) | W100 | Link register |
Integer | (empty) | R100 | File register |
32-bit 정수
data_type | format | plc_address 예 | 의미 |
|---|---|---|---|
Integer | DW | D100 | signed 32 (D100~D101 결합) |
Integer | (empty) | D100.D | 라이브러리 표기로 32-bit signed |
Integer | UDW | D100 | unsigned 32 |
Integer | (empty) | D100.UD | 라이브러리 표기로 unsigned 32 |
실수
data_type | format | plc_address 예 | 의미 |
|---|---|---|---|
Float | REAL | D200 | IEEE 754 32-bit (D200~D201) |
Float | (empty) | D200.F | 라이브러리 표기 |
Double | LREAL | D300 | IEEE 754 64-bit |
문자열
data_type | format | plc_address 예 | 의미 |
|---|---|---|---|
String | STR[5] | D400 | 5 워드 = 10 byte ASCII |
String | STR[16] | D500 | 16 워드 = 32 byte |
Formula 활용
| 용도 | data_type | fomula | 비고 |
|---|---|---|---|
| 정수 raw → 실수 스케일 | Float | ${VALUE}*0.01 | 12345 → 123.45 |
| 카운터 누적 (다른 태그 합) | Integer | ${VALUE}+${TAG_PREV} | 직전 누적값 합산 |
| 단위 변환 (g → kg) | Float | ${VALUE}/1000 |
curl 종합 예제
curl -X POST http://<edge-host>/api/v1/opc \
-H "Content-Type: application/json" \
-d '{
"opc_id": "OPC_MELSEC_FULL",
"opc_type": "MELSEC",
"opc_name": "MELSEC iQ-R Full",
"opc_agent_ip": "192.168.0.60",
"opc_agent_port": "5000",
"site_id": "SITE_00001",
"auto_collect": true,
"timecycle": 1000,
"options": { "controller-type": "IQ_R" },
"tag_list": [
{"tag_id":"OPC_MELSEC_FULL_T01", "tag_name":"InternalBit", "plc_address":"M100", "data_type":"Boolean"},
{"tag_id":"OPC_MELSEC_FULL_T02", "tag_name":"InputBit", "plc_address":"X100", "data_type":"Boolean"},
{"tag_id":"OPC_MELSEC_FULL_T03", "tag_name":"DataWord", "plc_address":"D100", "data_type":"Integer"},
{"tag_id":"OPC_MELSEC_FULL_T04", "tag_name":"DataDWord", "plc_address":"D102", "data_type":"Integer", "format":"DW"},
{"tag_id":"OPC_MELSEC_FULL_T05", "tag_name":"Pressure", "plc_address":"D200", "data_type":"Float", "format":"REAL"},
{"tag_id":"OPC_MELSEC_FULL_T06", "tag_name":"Power", "plc_address":"D300", "data_type":"Double", "format":"LREAL"},
{"tag_id":"OPC_MELSEC_FULL_T07", "tag_name":"Batch", "plc_address":"D500", "data_type":"String", "format":"STR[16]"},
{"tag_id":"OPC_MELSEC_FULL_T08", "tag_name":"PressKpa", "plc_address":"D200", "data_type":"Float", "format":"REAL", "fomula":"${VALUE}*0.001"}
]
}'