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
ClassCastExeption: CacheVariabel
January 2, 2015
16:24, EET
Avatar
Ibrahim
Member
Members
Forum Posts: 78
Member Since:
August 20, 2014
sp_UserOfflineSmall Offline

Hello,
i have a device, which has digital outputs. I want to control them via OPCUA. So i created the adressspace with UaModeler an exported it to an xml file.
I loaded this xml file in the Java Application. I also used the codegenerator to create the needed classes.
Now when i try to call The Method createInstance,to create an instance of the generated Types, i get a ClassCastException.
This is how i’m using the method:

final NodeId digitalOutputID = new NodeId(ns, “DigitalOutputID”);
digitalOutputs = createInstance(DigitalOutputs.class, “DigitalOutputs”);
digitalOutputFolder.addComponent(digitalOutputs);

And this is the Exeption:
Exception in thread “main” java.lang.ClassCastException: com.prosysopc.ua.server.nodes.CacheVariable cannot be cast to opcua.DigitalOutputs

BTW: The method “createInstance” works for the FolderType.

Hope, you can help me.

Thanks

January 5, 2015
8:26, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1026
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

Without seeing how you loaded that model, it’s not easy to say, but from above info I would assume the model is only loaded and not registered.
On server side, the model must be both loaded and registered to the UaServer. With only the model loaded, the server knows how the types are composed in UA terms (meaning the Types exists in the address space), but it cannot instantiate correct Java classes unless the model is also registered, because the instantiation algorithm uses only the actual type nodes in the address space (e.g. a CacheVariable is used by default for a UA Variable unless something overrides that, which model registering does)

i.e. call UaServer.registerAndLoadModel(CodegenModel codegenModel, URI nodeSetXml), which does internally call:
UaServer.registerModel and UaServer.getAddressSpace().loadModel
You can also call those separately if you wish

See SampleConsoleServer.loadInformationModels for example

– Bjarne

January 5, 2015
9:48, EET
Avatar
Ibrahim
Member
Members
Forum Posts: 78
Member Since:
August 20, 2014
sp_UserOfflineSmall Offline

Hi Bjarne,
thanks. Your advice helped me a lot. It was in deed the Method registerAndLoadModel(), which i did not call. After calling it, the Server starts without Exceptions and i can browse through the Adressspace with UaExpert.
Thanks.

Ghoddan

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
20 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: 738

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1524

Posts: 6451

Newest Members:

jonathonmcintyre, fannielima, kristiewinkle8, rust, christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettinger

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

Administrators: admin: 1