Zum Hauptinhalt springen

OPC-UA Treiber

Überblick

Industrielles Datenstandardprotokoll auf Basis der OPC Unified Architecture (IEC 62541).

PunktWert
opc_typeOPCUA
Implementierungsklasseplantpulse.driver.protocol.opcua.OPCUA_34_Driver
BibliothekEclipse Milo (milo-sdk-client)
read
write❌ (Phase 3 / zusammen mit Sparkplug NCMD)
SicherheitUsername/Password, Anonymous

Kompatibel mit den meisten OPC-UA Servern wie Kepware, Matrikon, Prosys usw.


OPC-Registrierungsformular

FeldBedeutungBeispiel
opc_agent_ipIP des OPC-UA Servers192.168.0.40
opc_agent_portTCP-Port des OPC-UA Servers49320 (Kepware-Standard)
timecycleAbfrageintervall (ms)1000
options.servernameServername am Ende des Endpoints(bei Kepware leer lassen)
options.usernameBenutzer für die Authentifizierungkopens
options.passwordPasswort für die Authentifizierung***
options.discoveryDiscovery-Endpoint verwendenfalse (bei true werden Endpoints automatisch ermittelt)

Format der erzeugten Endpoint-URL:

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

Sind username und password beide vorhanden, wird UsernameProvider verwendet, andernfalls AnonymousProvider.


Format von Tag-plc_address

OPC-UA-Standard-NodeId-Notation. Beispiele:

NotationBedeutung
ns=2;s=Simulator.Sine1Namespace 2, String-Identifier Simulator.Sine1
ns=2;i=1234Numerischer Identifier 1234
ns=3;g=09087e75-8e5e-499b-954f-f2a8624db28aGUID-Identifier
ns=2;b=Mb=Opaque (Bytestring) Identifier

Bei Kepware üblicherweise das Format ns=2;s=<Channel>.<Device>.<Tag>.


Zuordnung data_type / format

Der Value des OPC-UA-Variablenknotens wird nach String gecastet und zurückgegeben. data_type wird von den nachgelagerten Stufen (PLCValueFomula, Sparkplug-Veröffentlichung usw.) für das Casting verwendet.

data_typeVerhalten
Float / DoubleZahl unverändert
Int / Integer / Int32 / Short / LongZahl unverändert
Boolean / Booltrue/false als Zeichenkette
String / TextUTF-8-Zeichenkette
DateTimeISO-Zeichenkette

format wird bei OPC-UA in der Regel nicht verwendet. Wird eine Nachbearbeitungsformel benötigt, fomula verwenden.


Häufige Fehler + Lösungen

Meldung / SymptomUrsacheLösung
connection refusedServer nicht in Betrieb, Port blockiertKommunikation mit telnet <ip> <port> prüfen
Bad_UserAccessDeniedFehler bei username/password, anonymer Zugriff nicht erlaubtBenutzer serverseitig anlegen oder Anonymous aktivieren
Bad_SecurityChecksFailedNicht übereinstimmende SicherheitsrichtlinieRichtlinie am Server prüfen (None / Basic256Sha256 usw.). In Phase 1 hat MessageSecurityMode.None Vorrang
endpointUrl stimmt nicht übereindiscovery=false gesetzt, Server liefert jedoch einen anderen Hostnamen zurückAuf discovery=true belassen oder in der hosts-Datei zuordnen
Wert immer 0 / nullTippfehler in der NodeId, Namespace-Nummer stimmt nichtDenselben NodeId-Read mit einem Client wie UA Expert verifizieren

curl-Registrierungsbeispiel

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"
}
]
}'

Wert lesen:

curl -s http://<edge-host>/api/v1/tag/OPC_UA_Kepware_TAG_00001/value | jq

Hinweis: Kurzanleitung zur Kepware-Konfiguration

  1. Kepware Server → Project → Kanal hinzufügen (z. B. Simulator).
  2. Gerät hinzufügen (z. B. Simulator) → Modell = 16 Bit Device.
  3. Tag hinzufügen → Sine1, type Float, scan rate 100ms usw.
  4. In Project Properties → OPC UA → Server Endpoint den Port 49320 aktivieren.
  5. Anonymous oder Benutzerkonto aktivieren.

→ Edge-Registrierungsformular:

FeldWert
opc_agent_ipIP des Kepware-Servers
opc_agent_port49320
options.servername(leer)
options.username/passwordoben angelegtes Konto
plc_addressns=2;s=Simulator.Simulator.Sine1

Beispielsammlung (nach Datentyp)

OPC-UA castet den Wert des Variablenknotens (Variant) nach String und gibt ihn zurück. data_type wird von der Nachbearbeitung (PLCValueFomula, Sparkplug DataTypeMapper) für das Casting verwendet. format wird in der Regel nicht verwendet.

Boolean

data_typeplc_address BeispielHinweis
Booleanns=2;s=Simulator.Boolean1Boolean-Tag des Kepware Simulators
Booleanns=2;s=PLC.Status.RunningKepware Channel.Device.Tag
Booleanns=2;i=1003Numerische NodeId

16/32-Bit-Ganzzahlen

data_typeplc_address BeispielHinweis
Integerns=2;s=Simulator.Random1Simulation Random Integer
Integerns=2;s=Simulator.Counter1Counter
Integerns=2;s=PLC.D100Über Kepware MELSEC-Kanal bereitgestellt

64-Bit-Ganzzahlen

data_typeplc_address BeispielHinweis
Longns=2;s=Simulator.LongCounterUInt64 / Int64 Knoten
Longns=2;s=PLC.Cycle.TotalKumulativer Zähler

Gleitkommazahlen

data_typeplc_address BeispielHinweis
Floatns=2;s=Simulator.Sine1Sinuswellen-Simulation
Floatns=2;s=Simulator.Ramp1Rampenverlauf
Doublens=2;s=PLC.PressurePräzisionsmesswert

Zeichenketten

data_typeplc_address BeispielHinweis
Stringns=2;s=Simulator.User1.NameString-Knoten
Stringns=2;s=PLC.Recipe.ActiveRezeptname

Nach NodeId-Format

Identifier-Typplc_address Beispiel
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=

Einsatz von Formula

Zweckdata_typefomulaHinweis
EinheitenumrechnungFloat${VALUE}*0.001z. B. g → kg
NullpunktkorrekturFloat${VALUE}-${TAG_ZERO}Verweis auf andere OPCUA-Tags möglich
TypumwandlungFloat${VALUE}*1.0Integer → Float erzwingen
PolynomFloat${VALUE}*${VALUE}*0.0001Nichtlinear

Umfassendes curl-Beispiel (alle Typen)

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"}
]
}'