Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Problem with Method NodeId in IoListener
March 22, 2023
17:04, EET
Avatar
APesce
Italy
Member
Members
Forum Posts: 10
Member Since:
December 21, 2022
sp_UserOfflineSmall Offline

Good morning,
I have a problem with recognizing a method node when it is intercept to by the IoListener.

I created an information model with multiple devices, where the same method is contained.

root
+ Objects
++DeviceSet
+++ Device_01 (type: MyDeviceType)
++++ SwitchOn()

+++ Device_02 (type: MyDeviceType)
++++ SwitchOn()

When I browse the method node and when I run it, the MyIoListener method launchs:

public Boolean onGetUserExecutable(ServiceContext serviceContext, NodeId nodeId, UaMethod uaMethod)

Where
nodeId = uaMethod = Device_01:SwitchOn() = Device_02:SwitchOn()

The logged in user can execute Device_01:SwitchOn(), but not Device_02:SwitchOn().
How do I manage the UserExecutable?

March 23, 2023
9:16, EET
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 346
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

I would need some more information on your Methods.

When you say “multiple devices, where the same method is contained”, do you mean literally the same Method as in the exact same Method Node or two separate instances of the Method Node?

You’re saying that “nodeId = uaMethod = Device_01:SwitchOn() = Device_02:SwitchOn()” but I’m not exactly sure what you mean with this. Does this mean that the Method Nodes have the same NodeId, which would mean that they’re actually the same Node, or something else?

March 23, 2023
10:33, EET
Avatar
APesce
Italy
Member
Members
Forum Posts: 10
Member Since:
December 21, 2022
sp_UserOfflineSmall Offline

I created with UaModeler a new type (MyDeviceType), which contains the SwitchOn() method.
I generated the classes with the CodeGen and created two instances of MyDeviceType.

I noticed that the two method nodes Device_01:SwitchOn() and Device_02:SwitchOn() have the same NodeId.

When the MyIoListener.onGetUserExecutable(…) method is called I would need to know which SwitchOn() I am calling.

public Boolean onGetUserExecutable(ServiceContext serviceContext, NodeId nodeId, UaMethod uaMethod) {
System.out.prinln("nodeId: " + nodeId);
System.out.prinln("uaMethod: " + uaMethod.getNodeId());
return true; // How to return false in Device_02:SwitchOn() ?
}

If I perform a call Device_01:SwitchOn() or Device_02:SwitchOn(), it prints:

nodeId: ns=4;i=7014
uaMethod: ns=4;i=7014
March 23, 2023
11:49, EET
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 346
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

Since the Nodes have the same NodeId, they are both the same Node. In OPC UA it is allowed for different instances of an ObjectType to Reference a shared Method Node instead of creating unique Method Nodes. This is also how the SDK creates instances of ObjectTypes by default.

As onGetUserExecutable identifies the Method Node based on its NodeId, it is impossible for it to provide different values for UserExecutable Attribute based on the “parent” Node of the SwitchOn Method Node.

Therefore you have two options:

The first option is to set the UserExecutable to true for the Method Node and have the onCall method of CallableListener check the objectId and have the Method call fail depending on which Object the Method was called for. This can also be done when using the static implementation of the Method as the generated interface will have the Node the Method was called for as one of its parameters.

The problem with this approach is that it doesn’t provide Clients the information on whether or not they can execute the Method.

The second option is to create TypeDefinitionBasedNodeBuilderConfiguration with MethodInstantiationLogic set to UNIQUE. You can do this using the following code:

TypeDefinitionBasedNodeBuilderConfiguration.Builder conf = TypeDefinitionBasedNodeBuilderConfiguration.builder(MethodInstantiationLogic.UNIQUE);
// …
// setting other parameters for conf
// …
nodeManagerUaNode.setNodeBuilderConfiguration(conf.build());

where nodeManagerUaNode is an instance of a class that extends NodeManagerUaNode. This should be done before creating the instances of MyDeviceType with nodeManagerUaNode and it will make it so that unique Method Nodes are created for all instances of MyDeviceType (and any other ObjectTypes that have Methods). The SwitchOn Method Nodes will now have unique NodeIds, which allows you to configure onGetUserExecutable to provide different values for them.

If you are expecting to create only few instances of MyDeviceType then there should be no problem using this option. But if you need to create thousands of instances of MyDeviceType, then you might have to consider how much memory is required for all the unique instances of SwitchOn Method as opposed to one shared instance.

March 27, 2023
18:23, EEST
Avatar
APesce
Italy
Member
Members
Forum Posts: 10
Member Since:
December 21, 2022
sp_UserOfflineSmall Offline

Hi Matti,
I tried your solution but doesn’t work. I found a workaround: I force to create a new method node with PlainMethodInstantiationStrategy:

NodeBuilderConfiguration conf = new NodeBuilderConfiguration();
conf.addOptional(PFIds.MyDeviceType_SwitchOn);
conf.setInstantiationStrategy(PFIds.MyDeviceType_SwitchOn, new PlainMethodInstantiationStrategy());

Thank you for your help!

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
54 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Heikki Tahvanainen: 402

hbrackel: 144

rocket science: 88

pramanj: 86

Francesco Zambon: 83

Ibrahim: 78

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

Member Stats:

Guest Posters: 0

Members: 734

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1523

Posts: 6449

Newest Members:

christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettinger, howardkennerley, Thomassnism, biancacraft16, edgardo3518

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0

Administrators: admin: 1