シーメンス S7 ドライバ
概要
シーメンス SIMATIC S7 シリーズ (S7-300 / S7-400 / S7-1200 / S7-1500) の ISO-on-TCP 通信。
| 項目 | 値 |
|---|---|
opc_type | S7 |
| 実装クラス | plantpulse.driver.protocol.s7.S7_34_Driver |
| ライブラリ | iot-communication (plantpulse.plc.protocol.s7) |
| read | ✅ (バッチモード) |
| write | ✅ (Boolean/Integer/Long/Float/Double/String) |
| セキュリティ | なし (TCP 直結、S7 セーフティ通信は非対応) |
OPC 登録フォーム
| フィールド | 意味 | 例 |
|---|---|---|
opc_agent_ip | PLC IP | 192.168.0.70 |
opc_agent_port | ISO-on-TCP ポート | 102 |
timecycle | ポーリング周期 (ms) | 1000 |
options.controller-type | シリーズ | S7_400 (default) / S7_300 / S7_200 / S7_200_SMART / S7_1200 / S7_1500 / SINUMERIK_828D |
options.local-rack | rack 番号 (旧タイプミスの local-lack も互換) | 0 (default) |
options.local-slot | slot 番号 | 3 (S7-400 標準) / 0 (S7-1200/1500) / 2 (S7-300) |
options.multi-read | チャンク単位で 1 往復の一括 read (opt-in) | false (default) |
options.multi-read-max-items | チャンクあたりのアイテム数上限 | 18 (default、PDU 240 の予算) |
rack/slot
- S7-300 : rack=0, slot=2
- S7-400 : rack=0, slot=3 (CPU スロットにより異なる)
- S7-1200 / 1500 : rack=0, slot=0 (または 1)
タグ plc_address 形式
シーメンス標準のメモリアドレス表記 (DB / I / Q / M / T / C)。
| 表記 | 意味 |
|---|---|
%DB1.DBX0.0 | DB1 の X0.0 ビット (Bool) |
%DB1.DBB0 | DB1 の byte 0 (8-bit) |
%DB1.DBW0 | DB1 の word 0 (16-bit) |
%DB1.DBD0 | DB1 の double word 0 (32-bit / Real) |
%I0.0 | Input bit 0.0 |
%Q0.0 | Output bit 0.0 |
%M0.0 | Memory bit 0.0 |
%MW100 | Memory word 100 |
%MD100 | Memory double 100 |
iot-communication ライブラリは DB1.DBW0 のように % のない形式も受け付けますが、一貫性のため % 接頭辞を推奨します。
data_type / format マッピング
data_type | format | マッピング / 備考 |
|---|---|---|
| Boolean / Bool | (empty) | DBX / Ix.y / Mx.y |
| Byte | B / BYTE | DBB / MB |
| Short / Int / Int16 | (empty) | DBW (signed 16-bit) |
| Int32 / DWord | DW / DWORD | DBD (signed 32-bit) |
| UInt32 | UDW | DBD (unsigned) |
| Float / REAL | REAL | DBD 32-bit IEEE float |
| Double / LREAL | LREAL | DB の 8-byte 領域 |
| String | STR[N] | S7 STRING(2 byte ヘッダ + N byte) |
バッチモード (IS_BATCH_MODE=true) + REQUEST_LIMIT=4 — 1 回の read で最大 4 アドレスをまとめて処理します。
よくあるエラーと対処
| メッセージ / 症状 | 原因 | 対処 |
|---|---|---|
| Connection refused | ISO-on-TCP (ポート 102) が遮断されている | TIA Portal の「Permit access with PUT/GET」を有効化 |
Connection rejected by remote | rack/slot の不一致 | 上表を参照して修正 |
Address out of range | DB が絶対アドレスモードでない (Optimized) | TIA Portal で DB プロパティ → "Optimized block access" を OFF |
| すべての値が 0 | DB 番号 / オフセットの誤り | TIA Portal の Watch table で同一アドレスの read を検証 |
| Bool のみ読めない | %DB1.DBX0.0 の .bit が欠落 | DBX{byte}.{bit} 表記を正確に記述 |
curl 登録例
S7-1500 / DB1 の Real 値と Bool 値を読み取る例:
curl -X POST http://<edge-host>/api/v1/opc \
-H "Content-Type: application/json" \
-d '{
"opc_id": "OPC_S7_LINE2",
"opc_type": "S7",
"opc_name": "Line2 S7-1500",
"opc_agent_ip": "192.168.0.70",
"opc_agent_port": "102",
"site_id": "SITE_00001",
"auto_collect": true,
"timecycle": 1000,
"options": {
"controller-type": "S7_1500",
"local-rack": "0",
"local-slot": "0"
},
"tag_list": [
{
"tag_id": "OPC_S7_LINE2_TAG_00001",
"tag_name": "Pressure",
"plc_address": "%DB1.DBD0",
"data_type": "Float",
"format": "REAL"
},
{
"tag_id": "OPC_S7_LINE2_TAG_00002",
"tag_name": "RunFlag",
"plc_address": "%DB1.DBX10.0",
"data_type": "Boolean"
}
]
}'
値の read:
curl -s http://<edge-host>/api/v1/tag/OPC_S7_LINE2_TAG_00001/value | jq
サンプル集 (データ型別)
シーメンス標準のメモリ領域は DB / I / Q / M / T / C。iot-communication ライブラリは %DB1.DBW0 のように % 接頭辞を受け付けます (なくても動作しますが、一貫性のため推奨)。
ビット / ブール (Boolean)
data_type | format | plc_address 例 | 意味 |
|---|---|---|---|
Boolean | (empty) | %DB1.DBX0.0 | DB1 byte0 の bit 0 |
Boolean | (empty) | %DB1.DBX10.7 | DB1 byte10 の bit 7 |
Boolean | (empty) | %I0.0 | Input bit 0.0 |
Boolean | (empty) | %Q0.0 | Output bit 0.0 |
Boolean | (empty) | %M0.0 | Memory bit 0.0 |
8 / 16-bit 整数
data_type | format | plc_address 例 | 意味 |
|---|---|---|---|
Integer | B | %DB1.DBB0 | byte (8-bit) |
Integer | BYTE | %MB10 | Memory byte 10 |
Integer | (empty) | %DB1.DBW0 | DB word (signed 16) |
Integer | (empty) | %MW100 | Memory word 100 |
32-bit 整数
data_type | format | plc_address 例 | 意味 |
|---|---|---|---|
Integer | DW | %DB1.DBD0 | DB double (signed 32) |
Integer | DWORD | %MD100 | Memory double 100 |
Integer | UDW | %DB1.DBD8 | unsigned 32 |
実数 (Float / Double)
data_type | format | plc_address 例 | 意味 |
|---|---|---|---|
Float | REAL | %DB1.DBD0 | IEEE 754 32-bit (DBD = 4 byte) |
Float | REAL | %MD200 | Memory float 200 |
Double | LREAL | %DB1.DBD8 | IEEE 754 64-bit (8 byte) |
文字列
data_type | format | plc_address 例 | 意味 |
|---|---|---|---|
String | STR[16] | %DB1.DBB100 | S7 STRING (max 16 chars)、ヘッダ 2 byte を含む |
String | STR[32] | %DB2.DBB0 | S7 STRING、max 32 |
Formula の活用
| 用途 | data_type | fomula | 備考 |
|---|---|---|---|
| 整数 raw → 実数スケール | Float | ${VALUE}*0.1 | DBW raw → 実測値 |
| 温度補正 | Float | ${VALUE}+${TAG_OFFSET} | キャリブレーション |
| 圧力の単位変換 (Pa → kPa) | Float | ${VALUE}/1000 | 単位変換 |
curl 総合例
curl -X POST http://<edge-host>/api/v1/opc \
-H "Content-Type: application/json" \
-d '{
"opc_id": "OPC_S7_FULL",
"opc_type": "S7",
"opc_name": "S7-1500 Full",
"opc_agent_ip": "192.168.0.70",
"opc_agent_port": "102",
"site_id": "SITE_00001",
"auto_collect": true,
"timecycle": 1000,
"options": { "controller-type": "S7_1500", "local-rack": "0", "local-slot": "0" },
"tag_list": [
{"tag_id":"OPC_S7_FULL_T01", "tag_name":"DBBit", "plc_address":"%DB1.DBX0.0", "data_type":"Boolean"},
{"tag_id":"OPC_S7_FULL_T02", "tag_name":"InputBit", "plc_address":"%I0.0", "data_type":"Boolean"},
{"tag_id":"OPC_S7_FULL_T03", "tag_name":"DBByte", "plc_address":"%DB1.DBB1", "data_type":"Integer", "format":"B"},
{"tag_id":"OPC_S7_FULL_T04", "tag_name":"DBWord", "plc_address":"%DB1.DBW2", "data_type":"Integer"},
{"tag_id":"OPC_S7_FULL_T05", "tag_name":"DBDouble", "plc_address":"%DB1.DBD4", "data_type":"Integer", "format":"DW"},
{"tag_id":"OPC_S7_FULL_T06", "tag_name":"Pressure", "plc_address":"%DB1.DBD8", "data_type":"Float", "format":"REAL"},
{"tag_id":"OPC_S7_FULL_T07", "tag_name":"Power", "plc_address":"%DB1.DBD12", "data_type":"Double", "format":"LREAL"},
{"tag_id":"OPC_S7_FULL_T08", "tag_name":"BatchName", "plc_address":"%DB1.DBB100", "data_type":"String", "format":"STR[16]"},
{"tag_id":"OPC_S7_FULL_T09", "tag_name":"PressKpa", "plc_address":"%DB1.DBD8", "data_type":"Float", "format":"REAL", "fomula":"${VALUE}/1000"}
]
}'