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
Model is working with ProSys SampleServer but not with the C# UA Server
July 12, 2023
14:02, EEST
Avatar
Walter Machines
Member
Members
Forum Posts: 3
Member Since:
July 12, 2023
sp_UserOfflineSmall Offline

We have a OPC UA Server running written with C# and UA and a custom Model
Everything work fine if we use the C# client.
Now we need a Java client and we write a short client and implement the model.
Always if we cast to our custom class:
HelicheckType hc = (HelicheckType)m_client.getAddressSpace().getNode(node_id_helicheck);
we get the error:
java.lang.ClassCastException: com.prosysopc.ua.types.opcua.client.BaseObjectTypeImpl cannot be cast to util.opc_ua.helicheck.HelicheckType

Now I take the ProSys SampleServer, load our Model and try the client again and everything works fine.
What could be the reason? Is there something, what we should care about?

July 12, 2023
14:30, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

From the “HelicheckType hc = …” I assume you have run the included Codegen tool of the SDK?

Assuming you would have included the output resource files to classpath, SDK should be able to automatically discover the generated classes. The Codegen outputs a META-INF/services/com.prosysopc.ua.client.ClientCodegenModelProvider file (and it must be as-is in the classpath i.e. so that the path starts from META-INF within the classpath), which is then used internally via java ServiceLoader when the UaClient is created.

In other cases the model must be manually registered before you connect via UaClient.registerModel(XXXClientInformationModel.MODEL) where the XXXClientInformationModel is output by the generator. The XXX is the prefix, if any, from the codegen configuration, e.g. in di_adi_plcopen.xml in the configexamples in codegen folder of the SDK distribution zip, there is:

<namespaceMapping>
<uri>http://opcfoundation.org/UA/DI…..ri&gt;
<packageName>com.prosysopc.ua.types.di</packageName>
<prefix>Di</prefix>
</namespaceMapping>

So it would be DiClientInformationModel. If you do not set any, it is just ClientInformationModel, though I would recommend to set a prefix as the SDK already contains the core namespace without prefix and thus it is important that you do NOT use com.prosysopc.ua.types.opcua.client.ClientInformationModel, but the one you generated.

July 12, 2023
16:06, EEST
Avatar
Walter Machines
Member
Members
Forum Posts: 3
Member Since:
July 12, 2023
sp_UserOfflineSmall Offline

Hello,
thank you for the quick reply.
Yes we use the Codegen from the SDK.
I think we register the model in the right way because it’s working if I connect my ProSys Client with my ProSys Server but not with the C# Server. which include the same model.

July 12, 2023
17:16, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Sorry, it is a bit hard to say, I would need more details.

Basically what the client side does during .getNode is that it checks the HasTypeDefinition Reference of the node, then it tries to find the best UaNode interface implementation for it. If a (generated, registered) type is a direct match, that is used, otherwise it will look for the supertypes of the type definition until it finds a match (because this must/will also work without Codegen). Since all types derive from the core namespace types which is generated by us and is internal to the SDK, it will eventually use those.

The com.prosysopc.ua.types.opcua.client.BaseObjectTypeImpl is the root type for all Object types (and part of the core namespace). So either the HasTypeDefinition pointed to it directly (and you basically might have the wrong nodeid?) or there is no more specific subtype registered.

Is there any chance that the NodeId was wrong? Note that if you did use the index-based NodeId, it can be different in each server.

And if possible please doublecheck the model registration in the client. Sorry to doubt, but this kind of an error typically would happen if the model is not registered (and thus everything just uses the core namespace types, thus the cast will fail). If you do not have any manual code and rely on the automatic logic for the registartion, could you temporarily add the client.registerModel call just in case to see if it helps?

Can you check using either UaExpert or https://www.prosysopc.com/products/opc-ua-browser/ does the type node exist in the server and is the HasTypeDefinition Reference correct on the node you are trying to getNode()? And compare the node on the 2 servers, are there any differences etc. ?

P.S.
Maybe at some point SDK could tell this automatically (if the given Class is not registered), but basically at the moment just blindly casts the resulted UaNode to the given class type.

July 12, 2023
18:09, EEST
Avatar
Walter Machines
Member
Members
Forum Posts: 3
Member Since:
July 12, 2023
sp_UserOfflineSmall Offline

I already check both server with UaExpert and on both the type node exists and are the same, there is only one difference:
UaExpert show me on the Server which the cast is working inside the references more Components
But with UaExpert all values are there.on both servers.
If I read my structure seperate I can get all values.

July 13, 2023
8:45, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Is it possible to send screenshots where the Attributes and References are visible for the “…ace().getNode(node_id_helicheck);” ‘node_id_helicheck’ node, and then possibly the HasTypeDefinition target type as well? If yes, please send them to uajava-support@prosysopc.com and mention this thread. Additionally, if possible, could you send the model nodeset xml file as well?
Basically I would be looking something I could reproduce locally or enough information.

You could try checking client.getRegisteredClasses().getClass or containsClass to doublecheck was the type (HelicheckType.class) registered (or note that it is the implementation classes, so it would be HelicheckTypeImpl.class in practice, but that does implement the interface). The ExpandedNodeId parameter must be given in the Namespace uri-form, not the index one (Codegen outputs use the uri form, because it cannot know the index beforehand, and also the index could be multiple matches if the application connects to multiple servers etc.). You should be able to get the correct via ExpandedNodeId.parseExpandedNodeId(string) and give it the string within the @TypeDefinitionId annotation of the generated class, e.g. for AnalogItemType it would be “nsu=http://opcfoundation.org/UA/;i=2368”, because the generated class has @TypeDefinitionId(“nsu=http://opcfoundation.org/UA/;i=2368”).

July 13, 2023
8:50, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

P.S.
Call the client.getRegisteredClasses() only after connect(), because the automatic model resolving (if isAutoDiscoverCodegenModels() is true and by default it is) technically only happens as that point before the actual connection happens (some day maybe after construction, but that wouldn’t allow configuring AutoDiscoverCodegenModels with the current way).

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
45 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: 726

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1529

Posts: 6471

Newest Members:

gabriellabachus, Deakin, KTP25Zof, Wojciech Kubala, efrennowell431, wilfredostuart, caitlynfajardo, jeromechubb7, franciscagrimwad, adult_gallery

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

Administrators: admin: 1