メインコンテンツまでスキップ

シーメンス S7 ドライバ

概要

シーメンス SIMATIC S7 シリーズ (S7-300 / S7-400 / S7-1200 / S7-1500) の ISO-on-TCP 通信。

項目
opc_typeS7
実装クラス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_ipPLC IP192.168.0.70
opc_agent_portISO-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-rackrack 番号 (旧タイプミスの local-lack も互換)0 (default)
options.local-slotslot 番号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.0DB1 の X0.0 ビット (Bool)
%DB1.DBB0DB1 の byte 0 (8-bit)
%DB1.DBW0DB1 の word 0 (16-bit)
%DB1.DBD0DB1 の double word 0 (32-bit / Real)
%I0.0Input bit 0.0
%Q0.0Output bit 0.0
%M0.0Memory bit 0.0
%MW100Memory word 100
%MD100Memory double 100

iot-communication ライブラリは DB1.DBW0 のように % のない形式も受け付けますが、一貫性のため % 接頭辞を推奨します。


data_type / format マッピング

data_typeformatマッピング / 備考
Boolean / Bool(empty)DBX / Ix.y / Mx.y
ByteB / BYTEDBB / MB
Short / Int / Int16(empty)DBW (signed 16-bit)
Int32 / DWordDW / DWORDDBD (signed 32-bit)
UInt32UDWDBD (unsigned)
Float / REALREALDBD 32-bit IEEE float
Double / LREALLREALDB の 8-byte 領域
StringSTR[N]S7 STRING(2 byte ヘッダ + N byte)

バッチモード (IS_BATCH_MODE=true) + REQUEST_LIMIT=4 — 1 回の read で最大 4 アドレスをまとめて処理します。


よくあるエラーと対処

メッセージ / 症状原因対処
Connection refusedISO-on-TCP (ポート 102) が遮断されているTIA Portal の「Permit access with PUT/GET」を有効化
Connection rejected by remoterack/slot の不一致上表を参照して修正
Address out of rangeDB が絶対アドレスモードでない (Optimized)TIA Portal で DB プロパティ → "Optimized block access" を OFF
すべての値が 0DB 番号 / オフセットの誤り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_typeformatplc_address意味
Boolean(empty)%DB1.DBX0.0DB1 byte0 の bit 0
Boolean(empty)%DB1.DBX10.7DB1 byte10 の bit 7
Boolean(empty)%I0.0Input bit 0.0
Boolean(empty)%Q0.0Output bit 0.0
Boolean(empty)%M0.0Memory bit 0.0

8 / 16-bit 整数

data_typeformatplc_address意味
IntegerB%DB1.DBB0byte (8-bit)
IntegerBYTE%MB10Memory byte 10
Integer(empty)%DB1.DBW0DB word (signed 16)
Integer(empty)%MW100Memory word 100

32-bit 整数

data_typeformatplc_address意味
IntegerDW%DB1.DBD0DB double (signed 32)
IntegerDWORD%MD100Memory double 100
IntegerUDW%DB1.DBD8unsigned 32

実数 (Float / Double)

data_typeformatplc_address意味
FloatREAL%DB1.DBD0IEEE 754 32-bit (DBD = 4 byte)
FloatREAL%MD200Memory float 200
DoubleLREAL%DB1.DBD8IEEE 754 64-bit (8 byte)

文字列

data_typeformatplc_address意味
StringSTR[16]%DB1.DBB100S7 STRING (max 16 chars)、ヘッダ 2 byte を含む
StringSTR[32]%DB2.DBB0S7 STRING、max 32

Formula の活用

用途data_typefomula備考
整数 raw → 実数スケールFloat${VALUE}*0.1DBW 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"}
]
}'