2

I am a noob in dealing with OPCUA and trying the python library to interface with a server. I have already established a connection with the OPCUA Expert application, and this is what a screenshot looks like.

enter image description here

This is how my sample python code looks like.

#!/usr/bin/env python3
# encoding: utf-8
from opcua import Client
from opcua import ua
url='opc.tcp://192.168.112.94:4840'
client=Client(url=url)
somenode=client.get_node(nodeid='NS2|String/Plc/MD') # UaStringParsingError: ('Error parsing string NS2|String/Plc/MD', ValueError('not enough values to unpack (expected 2, got 1)'))

So basically, what is a nodeid and how to form it from what the UA Expert shows? Does not that column bearing the same name directly give the node id? Some helps on how to find the correct node id will be appreciated.

I realise I do not even have clarity on what is a node, as in is it like a node in graph theory, or network routing, or something else?

Della
  • 1,264
  • 2
  • 15
  • 32
  • Here is the Documentation of the UAExpert: https://documentation.unified-automation.com/uaexpert/1.6.3/html/first_steps.html#read To Create an NodeID in asyncio-opc ua here is an example: https://github.com/FreeOpcUa/opcua-asyncio/blob/07e6df2f2ccae4eb3649fd589496d748dc22bf0a/examples/client-example.py#L38 – SFriedl Feb 17 '23 at 08:51

1 Answers1

3

The syntax that python-opcua is using is "ns=2;s=String/PLC/MD", "ns=2;i=4",...

The syntax is ns={namespace_index_no} if ommited namespace index 0 is used.

  • i={numeric identifier} for example i=55
  • s={string identifier} for example s=ABC
  • g={uuid identifier} for example g=01108e12-d038-4591-a976-25f479008487

python-opcua is deprecated. So it's best to use opcua-asyncio, which also has a sync-wrapper, with very few changes in AP.

Schroeder
  • 749
  • 4
  • 10