Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [milo-dev] Problem in assigning numeric value to nodeID

To start with just create regular VariableNodes. Look at how any of the nodes in the addVariableNodes() function are added.

The custom datatype is another more advanced example that you don't need to worry about yet.

On Thu, Dec 5, 2019 at 6:09 AM J Dhanasekar <jdhanasekar@xxxxxxxxxxxxxxxxxx> wrote:
Ok.. I should not create VariableNode Under "Myobjec". I should follow the implementation  of "CustomDataTypeVariable" and create new VariableNode. 
Am I correct?.

On Thu, Dec 5, 2019 at 7:25 PM Kevin Herron <kevinherron@xxxxxxxxx> wrote:
What you've actually done here is add a new instance declaration variable to the "MyObject" type. If you found this instance declaration it would have the NodeId you configured, but what your'e looking at in the screenshot is an instantiated instance of MyObject created by NodeFactory, and all the NodeIds in new instances are derived.

If you're just trying to add some simple test nodes to the address space you're going about it the wrong way. 

On Thu, Dec 5, 2019 at 5:29 AM J Dhanasekar <jdhanasekar@xxxxxxxxxxxxxxxxxx> wrote:
I am sharing the same,


private void addCustomObjectTypeAndInstance(UaFolderNode rootFolder) {

logger.info("dhanasekar @ExampleNamespac.j getNodeContext()={}",getNodeContext());
// Define a new ObjectType called "MyObjectType".
UaObjectTypeNode objectTypeNode = UaObjectTypeNode.builder(getNodeContext())
.setNodeId(newNodeId("ObjectTypes/MyObjectType"))
.setBrowseName(newQualifiedName("MyObjectType"))
.setDisplayName(LocalizedText.english("MyObjectType"))
.setIsAbstract(false)
.build();

logger.info("dhanasekar @ExampleNamespac.j newQualifiedName()={}",newQualifiedName("Foo"));
// "Foo" and "Bar" are members. These nodes are what are called "instance declarations" by the spec.
UaVariableNode foo = UaVariableNode.builder(getNodeContext())
.setNodeId(newNodeId("ObjectTypes/MyObjectType.Foo"))
.setAccessLevel(ubyte(AccessLevel.getMask(AccessLevel.READ_WRITE)))
.setBrowseName(newQualifiedName("Foo"))
.setDisplayName(LocalizedText.english("Foo"))
.setDataType(Identifiers.Int16)
.setTypeDefinition(Identifiers.BaseDataVariableType)
.build();

//dhanasekar object intentiated of Reference
foo.addReference(new Reference(
foo.getNodeId(),
Identifiers.HasModellingRule,
Identifiers.ModellingRule_Mandatory.expanded(),
true
));

//method
foo.setValue(new DataValue(new Variant(0)));
objectTypeNode.addComponent(foo);

UaVariableNode bar = UaVariableNode.builder(getNodeContext())
.setNodeId(newNodeId("ObjectTypes/MyObjectType.Bar"))
.setAccessLevel(ubyte(AccessLevel.getMask(AccessLevel.READ_WRITE)))
.setBrowseName(newQualifiedName("Bar"))
.setDisplayName(LocalizedText.english("Bar"))
.setDataType(Identifiers.String)
.setTypeDefinition(Identifiers.BaseDataVariableType)
.build();

bar.addReference(new Reference(
bar.getNodeId(),
Identifiers.HasModellingRule,
Identifiers.ModellingRule_Mandatory.expanded(),
true
));

bar.setValue(new DataValue(new Variant("bar")));
objectTypeNode.addComponent(bar);


// dhanasekar -- Starting
// Adding code for flip
UaVariableNode flip = UaVariableNode.builder(getNodeContext())
.setNodeId(newNodeId(12345))
.setAccessLevel(ubyte(AccessLevel.getMask(AccessLevel.READ_WRITE)))
.setBrowseName(newQualifiedName("Flip"))
.setDisplayName(LocalizedText.english("Flip"))
.setDataType(Identifiers.Int32)
.setTypeDefinition(Identifiers.BaseDataVariableType)
.build();
logger.info("dhanasekar @ExampleNamespac.j flip.getNodeId()={}",flip.getNodeId());

flip.addReference(new Reference(
flip.getNodeId(),
Identifiers.HasModellingRule,
Identifiers.ModellingRule_Mandatory.expanded(),
true
));

flip.setValue(new DataValue(new Variant(0)));
objectTypeNode.addComponent(flip);

// Adding code for flop

UaVariableNode flop = UaVariableNode.builder(getNodeContext())
.setNodeId(newNodeId("ObjectTypes/MyObjectType.Flop"))
.setAccessLevel(ubyte(AccessLevel.getMask(AccessLevel.READ_WRITE)))
.setBrowseName(newQualifiedName("Flop"))
.setDisplayName(LocalizedText.english("Flop"))
.setDataType(Identifiers.Boolean)
.setTypeDefinition(Identifiers.BaseDataVariableType)
.build();

flop.addReference(new Reference(
flop.getNodeId(),
Identifiers.HasModellingRule,
Identifiers.ModellingRule_Mandatory.expanded(),
true
));

flop.setValue(new DataValue(new Variant(0)));
objectTypeNode.addComponent(flop);

// dhanasekar -- Ending

// Tell the ObjectTypeManager about our new type.
// This let's us use NodeFactory to instantiate instances of the type.
getServer().getObjectTypeManager().registerObjectType(
objectTypeNode.getNodeId(),
UaObjectNode.class,
UaObjectNode::new
);

// Add the inverse SubtypeOf relationship.
objectTypeNode.addReference(new Reference(
objectTypeNode.getNodeId(),
Identifiers.HasSubtype,
Identifiers.BaseObjectType.expanded(),
false
));


// Add type definition and declarations to address space.
getNodeManager().addNode(objectTypeNode);
getNodeManager().addNode(foo);
getNodeManager().addNode(bar);
//dhanasekar
getNodeManager().addNode(flip);
getNodeManager().addNode(flop);
//dhanasekar

// Use NodeFactory to create instance of MyObjectType called "MyObject".
// NodeFactory takes care of recursively instantiating MyObject member nodes
// as well as adding all nodes to the address space.
try {
UaObjectNode myObject = (UaObjectNode) getNodeFactory().createNode(
newNodeId("HelloWorld/MyObject"),
objectTypeNode.getNodeId(),
false
);
myObject.setBrowseName(newQualifiedName("MyObject"));
myObject.setDisplayName(LocalizedText.english("MyObject"));

// Add forward and inverse references from the root folder.
rootFolder.addOrganizes(myObject);

myObject.addReference(new Reference(
myObject.getNodeId(),
Identifiers.Organizes,
rootFolder.getNodeId().expanded(),
false
));
} catch (UaException e) {
logger.error("Error creating MyObjectType instance: {}", e.getMessage(), e);
}
}

On Thu, Dec 5, 2019 at 6:56 PM Kevin Herron <kevinherron@xxxxxxxxx> wrote:
Yes, more code is necessary to help debug.

On Thu, Dec 5, 2019 at 5:20 AM J Dhanasekar <jdhanasekar@xxxxxxxxxxxxxxxxxx> wrote:
You want me to provide complete code for further debug??..

On Thu, Dec 5, 2019 at 6:46 PM Kevin Herron <kevinherron@xxxxxxxxx> wrote:
This looks okay on its own, we'll need to see more of the surrounding code for additional context.

On Thu, Dec 5, 2019 at 5:15 AM J Dhanasekar <jdhanasekar@xxxxxxxxxxxxxxxxxx> wrote:
Attaching the screenshot,

image.png

On Thu, Dec 5, 2019 at 6:34 PM J Dhanasekar <jdhanasekar@xxxxxxxxxxxxxxxxxx> wrote:
Hi Milo,

I have created variableNode and I have assigned numeric ID,

UaVariableNode flip = UaVariableNode.builder(getNodeContext())
.setNodeId(newNodeId(12345))
.setAccessLevel(ubyte(AccessLevel.getMask(AccessLevel.READ_WRITE)))
.setBrowseName(newQualifiedName("Flip"))
.setDisplayName(LocalizedText.english("Flip"))
.setDataType(Identifiers.Int32)
.setTypeDefinition(Identifiers.BaseDataVariableType)
.build();

But, I am not getting numeric ID  "12345" in browser window, Instead I am getting string value "ns=2;s=HelloWorld/MyObject/2:Flip".

Can you please help me to solve this issue ?.

Thanks,
Dhanasekar
_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/milo-dev
_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/milo-dev
_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/milo-dev
_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/milo-dev
_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/milo-dev
_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/milo-dev
_______________________________________________
milo-dev mailing list
milo-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/milo-dev

Back to the top