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

OPC-UA ドライバ

概要

OPC Unified Architecture (IEC 62541) ベースの産業データ標準プロトコル。

項目
opc_typeOPCUA
実装クラス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_ipOPC-UA サーバ IP192.168.0.40
opc_agent_portOPC-UA サーバ TCP ポート49320 (Kepware デフォルト)
timecycleポーリング周期 (ms)1000
options.servernameendpoint 末尾のサーバ名(Kepware の場合は空欄)
options.username認証ユーザーkopens
options.password認証パスワード***
options.discoverydiscovery endpoint の使用有無false (true の場合 endpoints を自動検索)

生成される endpoint URL 形式:

opc.tcp://<opc_agent_ip>:<opc_agent_port>/<servername>

usernamepassword が両方ある場合は UsernameProvider、ない場合は AnonymousProvider を使用します。


タグ plc_address 形式

OPC-UA 標準の NodeId 表記。例:

表記意味
ns=2;s=Simulator.Sine1namespace 2、string identifier Simulator.Sine1
ns=2;i=1234numeric identifier 1234
ns=3;g=09087e75-8e5e-499b-954f-f2a8624db28aGUID 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 / Booltrue/false 文字列
String / TextUTF-8 文字列
DateTimeISO 文字列

format は OPC-UA では一般的に使用しません。後処理の演算が必要な場合は fomula を使用します。


よくあるエラーと対処

メッセージ / 症状原因対処
connection refusedサーバ未稼働、ポート遮断telnet <ip> <port> で通信を確認
Bad_UserAccessDeniedusername/password の誤り、匿名アクセス不許可サーバ側でユーザー登録、または anonymous を有効化
Bad_SecurityChecksFailedセキュリティポリシーの不一致サーバ側で None / Basic256Sha256 などのポリシーを確認。Phase 1 は MessageSecurityMode.None を優先
endpointUrl 不一致discovery=false なのにサーバが別のホスト名を返すdiscovery=true のままにするか、hosts ファイルにマッピング
値が常に 0 / nullNodeId の誤記、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 クイック設定ガイド

  1. Kepware Server → Project → チャネル追加 (例: Simulator)。
  2. デバイス追加 (例: Simulator) → モデル = 16 Bit Device
  3. タグ追加 → Sine1、type Float、scan rate 100ms など。
  4. Project Properties → OPC UA → Server Endpoint でポート 49320 を有効化。
  5. Anonymous またはユーザーアカウントを有効化。

→ Edge 登録フォーム:

フィールド
opc_agent_ipKepware サーバ IP
opc_agent_port49320
options.servername(空欄)
options.username/password上で作成したアカウント
plc_addressns=2;s=Simulator.Simulator.Sine1

例集 (データ型別)

OPC-UA は変数ノードの値(Variant)を String にキャストして返します。data_type は後処理 (PLCValueFomula、Sparkplug DataTypeMapper) がキャストに使用します。format は一般的に使用しません。

Boolean

data_typeplc_address備考
Booleanns=2;s=Simulator.Boolean1Kepware Simulator の Boolean tag
Booleanns=2;s=PLC.Status.RunningKepware Channel.Device.Tag
Booleanns=2;i=1003numeric NodeId

16/32-bit 整数

data_typeplc_address備考
Integerns=2;s=Simulator.Random1Random integer シミュレーション
Integerns=2;s=Simulator.Counter1Counter
Integerns=2;s=PLC.D100Kepware MELSEC チャネル公開

64-bit 整数

data_typeplc_address備考
Longns=2;s=Simulator.LongCounterUInt64 / Int64 ノード
Longns=2;s=PLC.Cycle.Total累積カウンタ

実数

data_typeplc_address備考
Floatns=2;s=Simulator.Sine1sine wave シミュレーション
Floatns=2;s=Simulator.Ramp1ramp wave
Doublens=2;s=PLC.Pressure精密測定値

文字列

data_typeplc_address備考
Stringns=2;s=Simulator.User1.Name文字列ノード
Stringns=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_typefomula備考
単位変換Float${VALUE}*0.001g → kg など
ゼロ点補正Float${VALUE}-${TAG_ZERO}他の OPCUA タグを参照可能
型変換Float${VALUE}*1.0Integer → 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"}
]
}'