OPC UA instance specifier to access single value of array

OPC UA instance specifier to access single value of array

steven_chen1
Collaborator Collaborator
259 Views
14 Replies
Message 1 of 15

OPC UA instance specifier to access single value of array

steven_chen1
Collaborator
Collaborator

[ FlexSim 22.2.4 ]

Hello,

I would like to re-open this topic: Using OPC UA to connect Fanuc robot - FlexSim Community

In conclusion, build-in Emulation GUI tool doesn't support specifying array index, we need to use internal Emulation in Process Flow.

So we can set node id to following format, where the %s is array index.

ns=2;s=Model;DiscreteInput[%s]


But it fails to read correct value of array, which is always zero.

I use OPC UA ANSI C Demo Server (Windows) as OPC UA server for testing.

UaExpert to modify node value, I set all boolean values to true.

Could you find out what is wrong in my model?

opcua_instance_v22.2.fsm

01.png



0 Likes
Accepted solutions (1)
260 Views
14 Replies
Replies (14)
Message 2 of 15

Jeanette_Fullmer
Community Manager
Community Manager

@Luciano Cavallero, @Tancredi Canonico, @Fiorenzo A, can you please take a look at this emulation-related question?

0 Likes
Message 3 of 15

lcavallero
Contributor
Contributor

Some OPC UA Server doesn't support direct access to a single element of an array ( the 'index range' functionality is not supported): please check if your server support this feature.

To avoid problem, if possible, transform your array of boolean into a set of single bool variables.

NOTE: the UaExpert client read and write all the array elements at once.

0 Likes
Message 4 of 15

jason_lightfootVL7B4
Autodesk
Autodesk

Hi @Steven Chen,

We haven't heard back from you. Were you able to solve your problem? If so, please add and accept an answer to let others know the solution. Or please respond to the previous comment so that we can continue to help you.

If we don't hear back in the next 3 business days, we'll assume you were able to solve your problem and we'll close this case in our tracker.

0 Likes
Message 5 of 15

steven_chen1
Collaborator
Collaborator

I believe there is nothing to do at server side, because I am able to use Python to specify array index. I use UserCommand to run this Python code.

from opcua import Client

def read(url, node_id, array_index):
    client = Client(url)
    client.connect()
    value = client.get_node(node_id).get_value()[int(array_index)]    
    return value   


My goal is to do the same thing with emulation tool or internal emulation in process flow.

0 Likes
Message 6 of 15

jason_lightfootVL7B4
Autodesk
Autodesk

That expression seems to be reading the whole array from the server and not the element which would be the part of the node_id expression (in FlexSim including the %s parameter).

0 Likes
Message 7 of 15

Jeanette_Fullmer
Community Manager
Community Manager

Hi @Steven Chen,

We haven't heard back from you. Were you able to solve your problem? If so, please add and accept an answer to let others know the solution. Or please respond to the previous comment so that we can continue to help you.

If we don't hear back in the next 3 business days, we'll assume you were able to solve your problem and we'll close this case in our tracker. You can always comment back at any time to reopen your question.

0 Likes
Message 8 of 15

steven_chen1
Collaborator
Collaborator

You are right that we can't use node_id expression to get only one element. So this expression is not valid.

ns=2;s=Model;DiscreteInput[%s]


Because FlexSim can't read array from OPC UA server (value is zero instead of an array), so it seems no any possible solution by using build-in funtionality in FlexSim.

The only solution is using Python or C++ external code to achieve this.

0 Likes
Message 9 of 15

jason_lightfootVL7B4
Autodesk
Autodesk

It's not going to recognise the %s in Python - you'd need to test if you can read a single value from the array into Python using something like this for the nodeid:

ns=2;s=Model;DiscreteInput[5]


0 Likes
Message 10 of 15

steven_chen1
Collaborator
Collaborator
I tried but it's not valid expression for OPC UA node id.
0 Likes
Message 11 of 15

jason_lightfootVL7B4
Autodesk
Autodesk
Doesn't that then suggest that the server is not configured to serve individual array values as Luciano suggested might be the case?
0 Likes
Message 12 of 15

steven_chen1
Collaborator
Collaborator
I afraid it's not expected to modify server. I hope at least FlexSim can retrieve the whole array from OPC server, but currently the retrieved value is zero with FlexSim. Could you add this to dev list?
0 Likes
Message 13 of 15

steven_chen1
Collaborator
Collaborator
@Luciano Cavallero, could you help adding this to dev list? To enable OPC UA to retrieve whole array from server.
0 Likes
Message 14 of 15

lcavallero
Contributor
Contributor
Accepted solution

@Steven Chen : alredy in the dev list.

0 Likes
Message 15 of 15

steven_chen1
Collaborator
Collaborator
Thank you.
0 Likes