Mitsubishi MELSEC Driver
Overview
MC protocol (3E / 1E) communication for Mitsubishi Electric PLC series (Q / L / iQ-R / iQ-F / FX).
| Item | Value |
|---|---|
opc_type | MELSEC |
| Implementation class | plantpulse.driver.protocol.melsec.Melsec_34_Driver |
| Library | iot-communication (plantpulse.plc.protocol.melsec) |
| read | ✅ (batch mode) |
| write | ✅ (Boolean/Integer/Long/Float/Double/String + BIN[n] word-bit RMW) |
| Security | None (direct TCP, assumes internal network) |
OPC Registration Form
| Field | Meaning | Example |
|---|---|---|
opc_agent_ip | PLC IP | 192.168.0.60 |
opc_agent_port | MC port | 5000 (Q/L default 1500) |
timecycle | Polling interval (ms) | 1000 |
options.controller-type | Series (Q_L, QnA, IQ_R, A — use Q_L for iQ-F/FX) | Q_L |
options.read-mode | single (individual read per tag, default) / grouped (grouped batch read — minimizes round trips) | single |
options.batch-gap-words | Allowed gap for word block merging in grouped mode | 16 (default) |
options.string-charset | String tag encoding (Korean supported) | MS949 (default) |
options.enable-iqr-extended | Direct read of iQ-R extended devices (LCN/LZ/LF/LSTN/LCC/LSC) | false (default) |
If controller-type is not specified, Q_L is used (Q / L series).
Tag plc_address Format
iot-communication notation. Device code + index (decimal) combination.
| Notation | Meaning |
|---|---|
D100 | Data Register 100 (16-bit) |
D100.W | 16-bit word (explicit) |
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 Mapping
data_type | format | Width / Interpretation |
|---|---|---|
| Boolean / Bool | (empty) | 1-bit (M, X, Y, etc.) |
| Short / Int / Integer | (empty) | 16-bit signed (W) |
| UInt16 | UI / UWORD | 16-bit unsigned |
| Int32 / DWord | DW | 32-bit signed (2 words) |
| UInt32 | UDW | 32-bit unsigned |
| Float / REAL | REAL | 32-bit IEEE 754 |
| Double / LREAL | LREAL | 64-bit IEEE 754 |
| String | STR[N] | N words → 2N bytes ASCII |
Batch mode (IS_BATCH_MODE=true) is enabled by default. All tags on a single PLC are bundled into one read request (REQUEST_LIMIT=1).
Common Errors and Fixes
| Message / Symptom | Cause | Fix |
|---|---|---|
| Connection refused | MC protocol disabled, port blocked | Enable MELSOFT 접속 / TCP / 포트 5000 in GX Works |
Wrong device code | Unsupported device code | Verify controller-type match (device code differences between Q and iQ-R) |
| 32-bit value mismatch | byte order | Specify D100.D (signed) / D100.UD (unsigned) |
| All tags read 0 | network number / station number mismatch | Specify network, station in options (currently defaults to 0) |
curl Registration Example
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"
}
]
}'
Example Collection (by Data Type)
Mitsubishi device codes: D (Data), M (Internal Relay), X (Input), Y (Output), B (Link Relay), W (Link Register), R (File Register), T (Timer), C (Counter).
Bit / Boolean
data_type | format | plc_address example | Meaning |
|---|---|---|---|
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 Integer
data_type | format | plc_address example | Meaning |
|---|---|---|---|
Integer | (empty) | D100 | Data Register (signed 16) |
Integer | (empty) | D100.W | Explicit 16-bit Word |
Integer | UI | D100 | unsigned 16 |
Integer | (empty) | W100 | Link register |
Integer | (empty) | R100 | File register |
32-bit Integer
data_type | format | plc_address example | Meaning |
|---|---|---|---|
Integer | DW | D100 | signed 32 (D100~D101 combined) |
Integer | (empty) | D100.D | 32-bit signed in library notation |
Integer | UDW | D100 | unsigned 32 |
Integer | (empty) | D100.UD | unsigned 32 in library notation |
Floating Point
data_type | format | plc_address example | Meaning |
|---|---|---|---|
Float | REAL | D200 | IEEE 754 32-bit (D200~D201) |
Float | (empty) | D200.F | Library notation |
Double | LREAL | D300 | IEEE 754 64-bit |
String
data_type | format | plc_address example | Meaning |
|---|---|---|---|
String | STR[5] | D400 | 5 words = 10 bytes ASCII |
String | STR[16] | D500 | 16 words = 32 bytes |
Using Formulas
| Purpose | data_type | fomula | Notes |
|---|---|---|---|
| Integer raw → scaled real | Float | ${VALUE}*0.01 | 12345 → 123.45 |
| Counter accumulation (sum with another tag) | Integer | ${VALUE}+${TAG_PREV} | Adds the previous accumulated value |
| Unit conversion (g → kg) | Float | ${VALUE}/1000 |
Comprehensive curl Example
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"}
]
}'