after i failed with my simplest example i can imagine, my 2nd approach: now i do it the same way as Lesson03:
I created a model that defines a type "WeldDevice" and create an object of that type in the code of the ua server.
In the startup method of my NodeManager class i write:
Code: Select all
this.InstanceNamespaceIndex = this.AddNamespaceUri("www.mycompany.com/Gws2UaWeldDeviceServer/dynamic");
var aWeldDevicesSettings = new CreateObjectSettings()
{
ParentNodeId = UnifiedAutomation.UaBase.ObjectIds.ObjectsFolder,
ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
RequestedNodeId = new NodeId("WeldDevices", this.InstanceNamespaceIndex),
BrowseName = new QualifiedName("WeldDevices", this.InstanceNamespaceIndex),
TypeDefinitionId = UnifiedAutomation.UaBase.ObjectTypeIds.FolderType
};
var aWeldDevicesObjectNode = this.CreateObject(Server.DefaultRequestContext, aWeldDevicesSettings);
CreateObjectSettings aWeldDeviceSettings = new CreateObjectSettings()
{
ParentNodeId = new NodeId("WeldDevices", this.InstanceNamespaceIndex),
ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
RequestedNodeId = new NodeId("DefaultWeldDevice", this.InstanceNamespaceIndex),
BrowseName = new QualifiedName("DefaultWeldDevice", this.TypeNamespaceIndex),
TypeDefinitionId = new NodeId(ObjectTypes.WeldDevice, this.TypeNamespaceIndex)
};
var aWeldDeviceObjectNode = this.CreateObject(Server.DefaultRequestContext, aWeldDeviceSettings);
var aCauseBadNodeIdErrorInUaExpert = true;
if (aCauseBadNodeIdErrorInUaExpert)
{
var aJobNumberVariableNode = this.SetVariableConfiguration(
new NodeId("DefaultWeldDevice", this.InstanceNamespaceIndex),
new QualifiedName("JobNumber", this.TypeNamespaceIndex),
NodeHandleType.ExternalPolled,
"MyUserData"
);
if(aJobNumberVariableNode.IsNullReference())
{
throw new InvalidOperationException();
}
}
Ok: The tree including the leaf node "JobNumber" is properly shown in the UaExpert.
Ok: when i click it, the ua library receives the value from my code via:
Code: Select all
public override DataValue ReadAttribute(RequestContext aRequestContext, NodeAttributeHandle aNodeHandle)
{
if( object.Equals(aNodeId.Identifier.ToString(), "DefaultWeldDevice.JobNumber"))
{
// This code is executed.
return new DataValue(new Variant((UInt32)1));
}
else
{
return base.ReadAttribute(aRequestContext, aNodeHandle);
}
}
What's wrong here? I mean the node is displayed and the value is requested and returned. actually everthing should be right then.
When i set aJobNumberVariableNode = false the value is still requested, the error disappears but still it displays not 1 as returned but a 0.