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
Bad_MethodInvalid message
July 4, 2017
17:42, EEST
Avatar
kapsl
Member
Members
Forum Posts: 57
Member Since:
December 20, 2016
sp_UserOfflineSmall Offline

Hi,
we created a model with UaModeler (with different namespace, subtyping, etc.)…

Now we instantiated this model on the server and can access it with UaExpert, But when I try to execute a method, I get the error Message: Bad_MethodInvalid The method id does not refer to a method for the specified object.

I can absolutely not explain this? At least when calling with UaExpert, it should get methodId and objectId right, isn’t it?

Greets Manu

July 7, 2017
10:58, EEST
Avatar
Heikki Tahvanainen
Member
Members
Forum Posts: 402
Member Since:
April 17, 2013
sp_UserOfflineSmall Offline

Hello Manu,

Thank you for the question. The mentioned error message Bad_MethodInvalid will be shown at least in the situation where a listener has not been created to handle the method calls. Please see method MyNodeManager.createMethodNode for an example about how the listener should be added.

Also, please see the server tutorial chapter “7. Method Manager” for further instructions on how to define methods in the server application.

Generally speaking, adding methods includes some amount of manual work at the moment. Meaning you cannot just load an information model and expect the methods to work out of the box.

July 7, 2017
12:19, EEST
Avatar
kapsl
Member
Members
Forum Posts: 57
Member Since:
December 20, 2016
sp_UserOfflineSmall Offline

Hi and thanks for your answer!

Actually I pretty much tried this… See the code below:

OPCUABrowsePath browsePath = new OPCUABrowsePath();
browsePath.append(null, “Types”);
browsePath.append(null, “ObjectTypes”);
browsePath.append(null, “BaseObjectType”);
browsePath.append(“http://mynamespace”, “AssetAdministrationShellType”);
browsePath.append(“http://mynamespace”, “DeviceType”);
browsePath.append(“http://mynamespace”, “Body”);
browsePath.append(“http://mynamespace”, “MethodSet”);
browsePath.append(“http://mynamespace”, “DoGlueOperation”); // This is the method

String indexedBrowsePath = browsePath.generateIndexedBrowsePath(getServer());
NodeId nodeID = null;

try {
nodeID = server.translateBrowsePathToNodeID(indexedBrowsePath);
} catch (Exception e) {
log.error(“Path for Lbr could not be found”, e);
}

UaNode myMethod;
try {
myMethod = (UaNode) getServer().getAddressSpace().getNode(nodeID);

// Create the listener that handles the method calls
myMethodManagerListener = new MyMethodManagerListener(myMethod);
MethodManagerUaNode m = (MethodManagerUaNode) this.getMethodManager();
m.addCallListener(myMethodManagerListener);

But I get the mentioned error?

Also I think the error message is missguiding, because in Specification Part 4 it says: Bad_MethodInvalid The method id does not refer to a method for the specified object.
Which would indicate the method was not found on that object and not that an implementation is missing…

July 11, 2017
13:58, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

A bit difficult to say what exactly goes wrong based on this information only. It might be that you are just calling the the method a bit wrong. Note that when you make a method call from the client, you need to provide both the NodeId of the Object that has the method and the NodeId of the method. The error indicates that the method that you are trying to call is not found from the object instance, which may very well be the case if the method is only in the type and there is no reference to the method node from the object instance.(I think the SDK does not find the method automatically from the type in this case)

But, if you are using UaModeler and code generation, the preferred way to implement methods is actually to define the method implementation in the generated class code. See the section 3.1.3 of the ReadmeSample.md in the codegen-directory for a bit more. If you are instantiating objects with ‘NodeManagerUaNode.createInstance()’ they should get all references (also to the methods) correctly.

July 13, 2017
15:52, EEST
Avatar
kapsl
Member
Members
Forum Posts: 57
Member Since:
December 20, 2016
sp_UserOfflineSmall Offline

HI Jouni,
actually the method call can’t be wrong, because the error occurs also, when we try the calling with UaExpert.

Sadly we can’t use the code generator. It is not powerful enough for more complicated models, so we have to instantiate stuff by code.

The same error occurs when calling method on the type or on an instance. Is there any way to model methods in UaModeler and then use them by code, without completely creating a new method? Must be, or – the codegenerator must somehow do the same?! What is the mistake in the code above – what more information do you need? Its the whole code for setting up the method implementation?!

lg

July 13, 2017
18:29, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Yes, the code generator is limited in the evaluation version of the SDK to 10 classes. The official version does not have that limitation.

As I mentioned, I cannot say what goes wrong based on the information above. I would need to see what the address space looks like and what parameters you provide for the call.

July 14, 2017
13:28, EEST
Avatar
kapsl
Member
Members
Forum Posts: 57
Member Since:
December 20, 2016
sp_UserOfflineSmall Offline

Actually the problem with the codegenerator is, that it doesn’t generate code for elements that are not strictly contained in a parent type. E.g. if we add methods to a normal FolderObject, this is not reflected in the generated code…

Basically the set up in the address space is pretty easy. We have a type, where there is a FolderObject an in this FolderObject there are methods. The error occurs, independently if there are any parameters to the method or no parameters at all.

So I tried to add a listener to the method with the above code – I tried to do this for the method in the type and also (with another browse path) for a method in the Objects folder. But it doesn’t work. Actually we can get it really simple, what would be the right way, if we would have modeled a single method in the Objects Folder (with UaModeler) and want to add a listener for it?

Thank you very much!

July 14, 2017
15:38, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Yes, the code generation only works for types: it creates a Java class for each OPC UA Object or Variable type.

If you wish to modify individual instances, then you can just add the nodes to these instances.

The question was actually, which parameters do you give for the Call service request, i.e. when you call UaClient.call(), which NodeId do you provide for objectId and which for methodId?

Do you manage to call MyMethod of the SampleConsoleServer? If yes, then you should be able to define your method exactly the same way as that method is defined in the SampleConsoleServer.

July 14, 2017
15:42, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

The other, UaModeler based option would be to create your own subtype of FolderType and define the method in there. And then instantiate your folders using this type, instead of the basic FolderType.

If you have just one folder with this method, it may be a bit overkill, though.

July 18, 2017
12:25, EEST
Avatar
kapsl
Member
Members
Forum Posts: 57
Member Since:
December 20, 2016
sp_UserOfflineSmall Offline

I tried with creating the Method manually (also this is not a really doable option in our case, because we need all the model from the UaModeler). It seems like it only works, when the method is created in the namspace of the instance nodes. I don’t get it completely, but it seems to be a namespace issue. The original method node (from UaModeler) is in a different namespace because it is subtyped, this leads the Server to create this BadMethodInvalid error…

July 18, 2017
13:12, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1026
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

OK, that is possible. At least the method node must be in the correct NodeManager. Also, when you add MethodManagerListener, it must be plugged to the correct MethodManager in the same NodeManager where the object is – not where the method node is.

I am still a bit unsure how you wish to model and use it with UaModeler, in practice. As mentioned, code generation only works with types. Still, you can define instances in Nodeset files – they will be loaded and created when you load the nodeset.

July 19, 2017
8:14, EEST
Avatar
kapsl
Member
Members
Forum Posts: 57
Member Since:
December 20, 2016
sp_UserOfflineSmall Offline

Hi,
I’m currently adding the methods manually by code. It is not nice, but it works.

The problem is, we have methods inside a folder and we really don’t want to generate a type for this folder, because it should be a general structure, shared between different devices to have this folder MethodSet (like in OPC UA DI). But then the methods inside can vary. As long as the codegenerator doesn’t support to generate classes for types, with subobjects (like in the figure below) it doesn’t help us so much. Because for every subobject of a type, we would have to generate an additional new type…

Type Device
Folder: MethodSet
Method1
Method2

lg Manu

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
15 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: 730

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1529

Posts: 6471

Newest Members:

toneylapham544, rondawolinski7, Marypof5711, roycedelargie91, kourtneyquisenbe, ellis87832073466, zkxwilliemae, gabriellabachus, Deakin, KTP25Zof

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

Administrators: admin: 1