본문으로 건너뛰기

미쓰비시 MELSEC 드라이버

개요

미쓰비시 전기 PLC 시리즈 (Q / L / iQ-R / iQ-F / FX) 의 MC 프로토콜 (3E / 1E) 통신.

항목
opc_typeMELSEC
구현 클래스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_ipPLC IP192.168.0.60
opc_agent_portMC 포트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-modesingle (태그별 개별 read, default) / grouped (그룹 배치 read — 왕복 최소화)single
options.batch-gap-wordsgrouped 모드 워드 블록 병합 허용 gap16 (default)
options.string-charsetString 태그 인코딩 (한글 지원)MS949 (default)
options.enable-iqr-extendediQ-R 확장 디바이스 (LCN/LZ/LF/LSTN/LCC/LSC) 직접 readfalse (default)

controller-type 미지정 시 Q_L 사용 (Q / L 시리즈).


태그 plc_address 형식

iot-communication 표기. 디바이스 코드 + 인덱스 (10진) 조합.

표기의미
D100Data Register 100 (16-bit)
D100.W16-bit word (명시)
D100.D32-bit double word (D100~D101)
D100.F32-bit float (D100~D101)
M100Internal relay 100 (1 bit)
X100Input X100 (1 bit)
Y100Output Y100 (1 bit)
B0Link relay
W100Link register
R100File register

D Data Register, M Coil, X/Y I/O, R File Reg, W Link Reg.


data_type / format 매핑

data_typeformat폭 / 해석
Boolean / Bool(empty)1-bit (M, X, Y 등)
Short / Int / Integer(empty)16-bit signed (W)
UInt16UI / UWORD16-bit unsigned
Int32 / DWordDW32-bit signed (2 워드)
UInt32UDW32-bit unsigned
Float / REALREAL32-bit IEEE 754
Double / LREALLREAL64-bit IEEE 754
StringSTR[N]N 워드 → 2N 바이트 ASCII

배치 모드 (IS_BATCH_MODE=true) 가 기본 활성. 단일 PLC 의 모든 태그를 한 번의 read 요청으로 묶어 처리합니다 (REQUEST_LIMIT=1).


흔한 에러 + 해결

메시지 / 증상원인해결
Connection refusedMC 프로토콜 비활성, 포트 차단GX Works 에서 MELSOFT 접속 / TCP / 포트 5000 활성화
Wrong device code디바이스 코드 미지원controller-type 일치 확인 (Q vs iQ-R 의 디바이스 코드 차이)
32-bit 값 부정합byte orderD100.D (signed) / D100.UD (unsigned) 명시
모든 태그가 0network 번호 / 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_typeformatplc_address의미
Boolean(empty)M100Internal relay 100
Boolean(empty)X100Input bit X100
Boolean(empty)Y100Output bit Y100
Boolean(empty)B0Link relay 0

16-bit 정수

data_typeformatplc_address의미
Integer(empty)D100Data Register (signed 16)
Integer(empty)D100.W명시적 16-bit Word
IntegerUID100unsigned 16
Integer(empty)W100Link register
Integer(empty)R100File register

32-bit 정수

data_typeformatplc_address의미
IntegerDWD100signed 32 (D100~D101 결합)
Integer(empty)D100.D라이브러리 표기로 32-bit signed
IntegerUDWD100unsigned 32
Integer(empty)D100.UD라이브러리 표기로 unsigned 32

실수

data_typeformatplc_address의미
FloatREALD200IEEE 754 32-bit (D200~D201)
Float(empty)D200.F라이브러리 표기
DoubleLREALD300IEEE 754 64-bit

문자열

data_typeformatplc_address의미
StringSTR[5]D4005 워드 = 10 byte ASCII
StringSTR[16]D50016 워드 = 32 byte

Formula 활용

용도data_typefomula비고
정수 raw → 실수 스케일Float${VALUE}*0.0112345 → 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"}
]
}'