三菱 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の全タグを1回のread要求にまとめて
処理します (REQUEST_LIMIT=1)。
よくあるエラーと対処
| メッセージ / 症状 | 原因 | 対処 |
|---|---|---|
| Connection refused | MCプロトコル無効、ポート遮断 | GX Works で MELSOFT 접속 / TCP / 포트 5000 を有効化 |
Wrong device code | デバイスコード非対応 | controller-type の一致を確認 (Q と 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"}
]
}'