OPC-UA ドライバ
概要
OPC Unified Architecture (IEC 62541) ベースの産業データ標準プロトコル。
| 項目 | 値 |
|---|---|
opc_type | OPCUA |
| 実装クラス | plantpulse.driver.protocol.opcua.OPCUA_34_Driver |
| ライブラリ | Eclipse Milo (milo-sdk-client) |
| read | ✅ |
| write | ❌ (Phase 3 / Sparkplug NCMD と併せて) |
| セキュリティ | Username/Password, Anonymous |
Kepware、Matrikon、Prosys など、ほとんどの OPC-UA サーバと互換性があります。
OPC 登録フォーム
| フィールド | 意味 | 例 |
|---|---|---|
opc_agent_ip | OPC-UA サーバ IP | 192.168.0.40 |
opc_agent_port | OPC-UA サーバ TCP ポート | 49320 (Kepware デフォルト) |
timecycle | ポーリング周期 (ms) | 1000 |
options.servername | endpoint 末尾のサーバ名 | (Kepware の場合は空欄) |
options.username | 認証ユーザー | kopens |
options.password | 認証パスワード | *** |
options.discovery | discovery endpoint の使用有無 | false (true の場合 endpoints を自動検索) |
生成される endpoint URL 形式:
opc.tcp://<opc_agent_ip>:<opc_agent_port>/<servername>
username と password が両方ある場合は UsernameProvider、ない場合は AnonymousProvider を使用します。
タグ plc_address 形式
OPC-UA 標準の NodeId 表記。例:
| 表記 | 意味 |
|---|---|
ns=2;s=Simulator.Sine1 | namespace 2、string identifier Simulator.Sine1 |
ns=2;i=1234 | numeric identifier 1234 |
ns=3;g=09087e75-8e5e-499b-954f-f2a8624db28a | GUID identifier |
ns=2;b=Mb= | opaque (bytestring) identifier |
Kepware の場合は通常 ns=2;s=<Channel>.<Device>.<Tag> 形式です。
data_type / format マッピング
OPC-UA 変数ノードの Value を String にキャストして返します。data_type は後続の段階
(PLCValueFomula、Sparkplug 発行など) がキャストに使用します。
data_type | 動作 |
|---|---|
Float / Double | 数値そのまま |
Int / Integer / Int32 / Short / Long | 数値そのまま |
Boolean / Bool | true/false 文字列 |
String / Text | UTF-8 文字列 |
DateTime | ISO 文字列 |
format は OPC-UA では一般的に使用しません。後処理の演算が必要な場合は fomula を使用します。
よくあるエラーと対処
| メッセージ / 症状 | 原因 | 対処 |
|---|---|---|
connection refused | サーバ未稼働、ポート遮断 | telnet <ip> <port> で通信を確認 |
Bad_UserAccessDenied | username/password の誤り、匿名アクセス不許可 | サーバ側でユーザー登録、または anonymous を有効化 |
Bad_SecurityChecksFailed | セキュリティポリシーの不一致 | サーバ側で None / Basic256Sha256 などのポリシーを確認。Phase 1 は MessageSecurityMode.None を優先 |
endpointUrl 不一致 | discovery=false なのにサーバが別のホスト名を返す | discovery=true のままにするか、hosts ファイルにマッピング |
| 値が常に 0 / null | NodeId の誤記、namespace 番号の不一致 | UA Expert などのクライアントで同じ NodeId の read を検証 |
curl 登録例
curl -X POST http://<edge-host>/api/v1/opc \
-H "Content-Type: application/json" \
-d '{
"opc_id": "OPC_UA_Kepware",
"opc_type": "OPCUA",
"opc_name": "Kepware",
"opc_agent_ip": "192.168.0.40",
"opc_agent_port": "49320",
"site_id": "SITE_00001",
"auto_collect": true,
"timecycle": 1000,
"options": {
"username": "kopens",
"password": "***",
"discovery": "false"
},
"tag_list": [
{
"tag_id": "OPC_UA_Kepware_TAG_00001",
"tag_name": "Sine1",
"plc_address": "ns=2;s=Simulator.Sine1",
"data_type": "Float",
"description": "Sine wave"
},
{
"tag_id": "OPC_UA_Kepware_TAG_00002",
"tag_name": "Random1",
"plc_address": "ns=2;s=Simulator.Random1",
"data_type": "Integer"
}
]
}'
値の read:
curl -s http://<edge-host>/api/v1/tag/OPC_UA_Kepware_TAG_00001/value | jq
参考: Kepware クイック設定ガイド
- Kepware Server → Project → チャネル追加 (例:
Simulator)。 - デバイス追加 (例:
Simulator) → モデル =16 Bit Device。 - タグ追加 →
Sine1、typeFloat、scan rate100msなど。 Project Properties → OPC UA → Server Endpointでポート49320を有効化。- Anonymous またはユーザーアカウントを有効化。
→ Edge 登録フォーム:
| フィールド | 値 |
|---|---|
| opc_agent_ip | Kepware サーバ IP |
| opc_agent_port | 49320 |
| options.servername | (空欄) |
| options.username/password | 上で作成したアカウント |
| plc_address | ns=2;s=Simulator.Simulator.Sine1 |
例集 (データ型別)
OPC-UA は変数ノードの値(Variant)を String にキャストして返します。data_type は後処理 (PLCValueFomula、Sparkplug DataTypeMapper) がキャストに使用します。format は一般的に使用しません。
Boolean
data_type | plc_address 例 | 備考 |
|---|---|---|
Boolean | ns=2;s=Simulator.Boolean1 | Kepware Simulator の Boolean tag |
Boolean | ns=2;s=PLC.Status.Running | Kepware Channel.Device.Tag |
Boolean | ns=2;i=1003 | numeric NodeId |
16/32-bit 整数
data_type | plc_address 例 | 備考 |
|---|---|---|
Integer | ns=2;s=Simulator.Random1 | Random integer シミュレーション |
Integer | ns=2;s=Simulator.Counter1 | Counter |
Integer | ns=2;s=PLC.D100 | Kepware MELSEC チャネル公開 |
64-bit 整数
data_type | plc_address 例 | 備考 |
|---|---|---|
Long | ns=2;s=Simulator.LongCounter | UInt64 / Int64 ノード |
Long | ns=2;s=PLC.Cycle.Total | 累積カウンタ |
実数
data_type | plc_address 例 | 備考 |
|---|---|---|
Float | ns=2;s=Simulator.Sine1 | sine wave シミュレーション |
Float | ns=2;s=Simulator.Ramp1 | ramp wave |
Double | ns=2;s=PLC.Pressure | 精密測定値 |
文字列
data_type | plc_address 例 | 備考 |
|---|---|---|
String | ns=2;s=Simulator.User1.Name | 文字列ノード |
String | ns=2;s=PLC.Recipe.Active | レシピ名 |
NodeId 形式別
| identifier タイプ | plc_address 例 |
|---|---|
String (s=) | ns=2;s=Simulator.Sine1 |
Numeric (i=) | ns=2;i=1234 |
GUID (g=) | ns=3;g=09087e75-8e5e-499b-954f-f2a8624db28a |
Opaque (b=) | ns=2;b=Mb= |
Formula の活用
| 用途 | data_type | fomula | 備考 |
|---|---|---|---|
| 単位変換 | Float | ${VALUE}*0.001 | g → kg など |
| ゼロ点補正 | Float | ${VALUE}-${TAG_ZERO} | 他の OPCUA タグを参照可能 |
| 型変換 | Float | ${VALUE}*1.0 | Integer → Float を強制 |
| 多項式 | Float | ${VALUE}*${VALUE}*0.0001 | 非線形 |
curl 総合例 (全タイプ)
curl -X POST http://<edge-host>/api/v1/opc \
-H "Content-Type: application/json" \
-d '{
"opc_id": "OPC_UA_FULL",
"opc_type": "OPCUA",
"opc_name": "Kepware Full",
"opc_agent_ip": "192.168.0.40",
"opc_agent_port": "49320",
"site_id": "SITE_00001",
"auto_collect": true,
"timecycle": 1000,
"options": { "discovery": "false" },
"tag_list": [
{"tag_id":"OPC_UA_FULL_T01", "tag_name":"BoolTag", "plc_address":"ns=2;s=Simulator.Boolean1", "data_type":"Boolean"},
{"tag_id":"OPC_UA_FULL_T02", "tag_name":"IntTag", "plc_address":"ns=2;s=Simulator.Random1", "data_type":"Integer"},
{"tag_id":"OPC_UA_FULL_T03", "tag_name":"LongTag", "plc_address":"ns=2;s=Simulator.LongCounter", "data_type":"Long"},
{"tag_id":"OPC_UA_FULL_T04", "tag_name":"FloatTag", "plc_address":"ns=2;s=Simulator.Sine1", "data_type":"Float"},
{"tag_id":"OPC_UA_FULL_T05", "tag_name":"DoubleTag", "plc_address":"ns=2;s=PLC.Pressure", "data_type":"Double"},
{"tag_id":"OPC_UA_FULL_T06", "tag_name":"StringTag", "plc_address":"ns=2;s=Simulator.User1.Name", "data_type":"String"},
{"tag_id":"OPC_UA_FULL_T07", "tag_name":"NumIdTag", "plc_address":"ns=2;i=1234", "data_type":"Integer"},
{"tag_id":"OPC_UA_FULL_T08", "tag_name":"ScaledTag", "plc_address":"ns=2;s=Simulator.Sine1", "data_type":"Float", "fomula":"${VALUE}*100"}
]
}'