/// <summary> /// Follows hierarchial references from the current node and updates the tree. /// </summary> private void Browse(TreeNode parent) { parent.Nodes.Clear(); ReferenceDescription start = parent.Tag as ReferenceDescription; ListOfBrowseDescription nodesToBrowse = new ListOfBrowseDescription(); BrowseDescription nodeToBrowse = new BrowseDescription(); nodeToBrowse.NodeId = new NodeId(start.NodeId); nodeToBrowse.BrowseDirection = BrowseDirection.Forward_0; nodeToBrowse.ReferenceTypeId = new NodeId(ReferenceTypes.HierarchicalReferences); nodeToBrowse.IncludeSubtypes = true; nodeToBrowse.ResultMask = (uint)DataTypes.EnumToMask(BrowseResultMask.All_63); nodeToBrowse.NodeClassMask = 0; nodesToBrowse.Add(nodeToBrowse); ListOfBrowseResult results; ListOfDiagnosticInfo diagnosticInfos; m_client.Browse( m_client.CreateRequestHeader(), null, 0, nodesToBrowse, out results, out diagnosticInfos); if (results != null && results.Count > 0) { BrowseResult result = results[0]; if (result.References != null) { foreach (ReferenceDescription reference in result.References) { TreeNode child = new TreeNode(reference.DisplayName.Text); child.Tag = reference; child.Nodes.Add(new TreeNode()); parent.Nodes.Add(child); } } } }
/// <summary> /// Returns the value of an attribute. /// </summary> public void Read( ReadValueId request, DataValue result, DiagnosticInfo diagnosticInfo) { lock (m_lock) { // find the node to read. Node source = m_nodes.Find(request.NodeId); result.ServerTimestamp = DateTime.UtcNow; if (source == null) { result.StatusCode = new StatusCode(StatusCodes.BadNodeIdUnknown); return; } result.Value = Variant.Null; // switch on the attribute value. switch (request.AttributeId) { case Attributes.NodeId: { result.Value = new Variant(source.NodeId); break; } case Attributes.NodeClass: { result.Value = new Variant(DataTypes.EnumToMask(source.NodeClass)); break; } case Attributes.BrowseName: { result.Value = new Variant(source.BrowseName); break; } case Attributes.DisplayName: { result.Value = new Variant(source.DisplayName); break; } case Attributes.Description: { result.Value = new Variant(source.Description); break; } case Attributes.WriteMask: { result.Value = new Variant(source.WriteMask); break; } case Attributes.UserWriteMask: { result.Value = new Variant(source.UserWriteMask); break; } case Attributes.Value: { // check if another component has installed a read callback. ReadValueEventHandler callback = null; if (m_callbacks.TryGetValue(source.NodeId.Identifier, out callback)) { result.Value = new Variant(callback()); break; } // use the value cached in the node otherwise. VariableNode variable = source as VariableNode; if (variable != null) { result.Value = variable.Value; result.SourceTimestamp = DateTime.UtcNow; // The Value attribute requires a SourceTimestamp. break; } VariableTypeNode variableType = source as VariableTypeNode; if (variableType != null) { result.Value = variableType.Value; result.SourceTimestamp = DateTime.UtcNow; // The Value attribute requires a SourceTimestamp. break; } result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid); break; } case Attributes.DataType: { VariableNode variable = source as VariableNode; if (variable != null) { result.Value = new Variant(variable.DataType); break; } VariableTypeNode variableType = source as VariableTypeNode; if (variableType != null) { result.Value = new Variant(variableType.DataType); break; } result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid); break; } case Attributes.ValueRank: { VariableNode variable = source as VariableNode; if (variable != null) { result.Value = new Variant(variable.ValueRank); break; } VariableTypeNode variableType = source as VariableTypeNode; if (variableType != null) { result.Value = new Variant(variableType.ValueRank); break; } result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid); break; } case Attributes.MinimumSamplingInterval: { VariableNode variable = source as VariableNode; if (variable != null) { result.Value = new Variant(variable.MinimumSamplingInterval); break; } result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid); break; } case Attributes.Historizing: { VariableNode variable = source as VariableNode; if (variable != null) { result.Value = new Variant(variable.Historizing); break; } result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid); break; } case Attributes.AccessLevel: { VariableNode variable = source as VariableNode; if (variable != null) { result.Value = new Variant(variable.AccessLevel); break; } result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid); break; } case Attributes.UserAccessLevel: { VariableNode variable = source as VariableNode; if (variable != null) { result.Value = new Variant(variable.UserAccessLevel); break; } result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid); break; } case Attributes.EventNotifier: { ObjectNode objectn = source as ObjectNode; if (objectn != null) { result.Value = new Variant(objectn.EventNotifier); break; } ViewNode view = source as ViewNode; if (view != null) { result.Value = new Variant(view.EventNotifier); break; } result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid); break; } case Attributes.Executable: { MethodNode method = source as MethodNode; if (method != null) { result.Value = new Variant(method.Executable); break; } result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid); break; } case Attributes.UserExecutable: { MethodNode method = source as MethodNode; if (method != null) { result.Value = new Variant(method.UserExecutable); break; } result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid); break; } case Attributes.ContainsNoLoops: { ViewNode view = source as ViewNode; if (view != null) { result.Value = new Variant(view.ContainsNoLoops); break; } result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid); break; } case Attributes.InverseName: { ReferenceTypeNode referenceType = source as ReferenceTypeNode; if (referenceType != null) { result.Value = new Variant(referenceType.InverseName); break; } result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid); break; } case Attributes.IsAbstract: { DataTypeNode dataType = source as DataTypeNode; if (dataType != null) { result.Value = new Variant(dataType.IsAbstract); break; } ReferenceTypeNode referenceType = source as ReferenceTypeNode; if (referenceType != null) { result.Value = new Variant(referenceType.IsAbstract); break; } ObjectTypeNode objectType = source as ObjectTypeNode; if (objectType != null) { result.Value = new Variant(objectType.IsAbstract); break; } VariableTypeNode variableType = source as VariableTypeNode; if (variableType != null) { result.Value = new Variant(variableType.IsAbstract); break; } result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid); break; } case Attributes.Symmetric: { ReferenceTypeNode referenceType = source as ReferenceTypeNode; if (referenceType != null) { result.Value = new Variant(referenceType.Symmetric); break; } result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid); break; } default: { result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid); break; } } } }