

15:31, EET

October 9, 2012

I used the C++ sdk to create custom types. When instanciating them all the components of the types were instanciated.
Now I am wondering how to do the same in Java.
I tried the following
//create custom object type
final NodeId VegSensorTypeId = new NodeId(ns, “VegSensorType”);
UaObjectType vegSensorType = new UaObjectTypeNode(myNodeManager, VegSensorTypeId, “VegSensorType”, Locale.ENGLISH);
myNodeManager.addNodeAndReference(baseObjectType, vegSensorType, Identifiers.HasSubtype);
//Add a variable to object type
final NodeId hastighetId = new NodeId(ns, “Hastighet”);
UaVariableNode SpeedNode;
SpeedNode = new CacheVariable(myNodeManager, hastighetId, “Hastighet”, Locale.ENGLISH);
SpeedNode.setDataType(doubleType);
SpeedNode.setModellingRule(Identifiers.ModellingRule_Mandatory);
myNodeManager.addNodeAndReference(vegSensorType, SpeedNode, Identifiers.HasComponent);
// now instanciate my object type
final NodeId VegSensorId = new NodeId(ns, “VegSensor”);
VegSensor = new UaObjectNode(myNodeManager, VegSensorId, “VegSensor 1”, Locale.ENGLISH);
VegSensor.setTypeDefinition(vegSensorType);
//registrationPoint.addReference(VegSensor, Identifiers.HasComponent, false);
myNodeManager.addNodeAndReference(registrationPoint, VegSensor, Identifiers.Organizes);
The object is intanciated but its varaiable is not.
What is the correct way to do that ?
Thank you
7:21, EET

December 21, 2011

16:34, EEST

December 21, 2011

This has changed somewhat since the original posting here in 2012. Nowadays, the recommended way is to define types with UaModeler and then generate Java classes respective to the types using the Java Code Generator included in the Java SDK. After that you can use the NodeManagerUaNode.createInstance() method to instantiate your objects and variables – it will take care of building the “complete” object or variable for you.
See the SDK documentation for more details about the code generation (in codegen directory).
1 Guest(s)
