7

I have an OPC server running on a milling machine and want to access the names of the tools which are currently available in the machine.

I do know that the names of the variables I am looking for are

Sinumerik/Tool/Catalogue/toolIdent[1]
Sinumerik/Tool/Catalogue/toolIdent[2]

and so on. I can see the corresponding values in a viewer such as uaexpert.

While I am able to access

Sinumerik/Tool/Catalogue/toolIdent

by successively walking down from the root, using commands such as

children=Position.get_children()
for child in children:
    Position=child

this approach does not work for toolIdent[1] since this is not a child.

How can I access these values of the array?

EDIT: One additional remark: The name of the tool is stored as a value of the node, not as a variable. I have come across the function get_array_dimensions, but this only seems to work for variables.

EDIT2: I have attached a screenshot of the UAExpert view of the array I am looking for. The three first values of the array are 3D_BLUM, 12, and 98. enter image description here

EDIT3: In UAExpert, I am able to see to content of toolIdent[2] by using the "add custom node" command, selecting a string node and offering " /Tool/Catalogue/toolIdent[2]" as parameter for the NodeId. I am trying to find out how I can do the same using python (preferrably opcua library, and I am offering a bounty for reaching this goal in Python.

tfv
  • 6,016
  • 4
  • 36
  • 67

2 Answers2

5

From your screenshots it looks like each of these "array elements" actually has its own Node and NodeId.

You should just be able to read each of these NodeIds:

  • ns=2;s=/Tool/Catalogue/toolIdent[0]
  • ns=2;s=/Tool/Catalogue/toolIdent[1]
  • ns=2;s=/Tool/Catalogue/toolIdent[2]
Kevin Herron
  • 6,500
  • 3
  • 26
  • 35
  • It looks like this, so this is what I tried first, but it does not work in Python. And while I see `toolIdent` as a child of the node Catalogue, `toolIdent[1]` is no child in the list of children of the node Catalogue. It seems that the fact that I can view it in uaexpert using an `add custom node` command does not mean that it actually IS a node. – tfv Nov 22 '19 at 12:23
  • Can you browse to this node in UaExpert and expand it to see if there are children in the browse tree? If you already tried that, then where did you drag those element subscriptions from? – Kevin Herron Nov 22 '19 at 14:14
  • 1
    Oh, I think I understand what you mean - you added it manually to the Data Access View in UaExpert. Interesting. I guess this server is not exposing the References to make these Nodes browsable. But if you can reach them manually like this in UaExpert, you should also be able to from your Python code. But not via browsing - you'll probably have to read or subscribe to those NodeIds explicitly. – Kevin Herron Nov 22 '19 at 14:19
  • Kevin, thanks for your help. I have understood that I need to reach them manually, and that browsing does not work. I must admit that I am no OPC expert at all, so I am not too familiar with the underlying concepts of subscribing to nodes. Furthermore, the docu of the Python OPC library https://python-opcua.readthedocs.io/en/latest/ is very short and lacks example code. But thanks for giving me a direction to focus on. If anyone could offer a hint on the proper Python fuction, ... – tfv Nov 22 '19 at 21:15
  • https://python-opcua.readthedocs.io/en/latest/subscription.html There seems to be a subscription call which allows me to subscribe to data changes and eents, but since I am looking for static values, this might be the wrong approach. – tfv Nov 22 '19 at 21:21
  • 1
    Looks like you can just create a Node (https://python-opcua.readthedocs.io/en/latest/node.html) since you know the NodeId, and then call `get_value()` or `get_data_value()`. – Kevin Herron Nov 23 '19 at 03:19
  • Can you try to propose code which I could test? I don't get there. – tfv Dec 12 '19 at 16:22
  • I have awarded the bounty to this answer because this discussion was most helpful to me, though the Python part of the question has not been solved yet. – tfv Dec 20 '19 at 03:41
  • Have you looked into `translate_browsepaths_to_nodeids`? There you should be able to insert the path as something like `["2:Tool", "2:Catalogue","toolIdent[{}]".format(toolIndex)]` and operate on the NodeId returned by the server. – starturtle Apr 04 '20 at 10:26
1

Based on what I've read, it looks like this isn't an array, but a naming convention. I would start by hacking it:

    for x in range(10):
        if x == 0:
            availTools = [toolIdent]
        else:
            availTools.append(toolIdent[x])

Now you have your available tool in an actual array (availTools) that you can access however you'd like.

Kyle Hurst
  • 252
  • 2
  • 6