/// <summary> /// Initializes the node from the element. /// </summary> /// <param name="context">The context.</param> /// <param name="element">The element.</param> /// <param name="namespaceIndex">Index of the namespace.</param> public void Initialize(ISystemContext context, DaElement element, ushort namespaceIndex) { m_element = element; if (element == null) { return; } this.NodeId = ModelUtils.ConstructIdForDaElement(element.ItemId, -1, namespaceIndex); this.BrowseName = new QualifiedName(element.Name, namespaceIndex); this.DisplayName = new LocalizedText(element.Name); }
/// <summary> /// Initializes the node from the element. /// </summary> /// <param name="context">The context.</param> /// <param name="itemId">The item id.</param> /// <param name="property">The property.</param> /// <param name="namespaceIndex">Index of the namespace.</param> public void Initialize(ISystemContext context, string itemId, DaProperty property, ushort namespaceIndex) { m_itemId = itemId; m_property = property; if (property == null) { return; } this.NodeId = ModelUtils.ConstructIdForDaElement(m_itemId, property.PropertyId, namespaceIndex); this.BrowseName = new QualifiedName(property.Name, namespaceIndex); this.DisplayName = new LocalizedText(property.Name); this.TypeDefinitionId = Opc.Ua.VariableTypeIds.PropertyType; this.Value = null; this.StatusCode = StatusCodes.BadWaitingForInitialData; this.Timestamp = DateTime.UtcNow; bool isArray = false; this.DataType = ComUtils.GetDataTypeId(property.DataType, out isArray); this.ValueRank = (isArray)?ValueRanks.OneOrMoreDimensions:ValueRanks.Scalar; this.ArrayDimensions = null; // assume that properties with item ids are writeable. the server may still reject the write. if (String.IsNullOrEmpty(property.ItemId)) { this.AccessLevel = AccessLevels.CurrentRead; } else { this.AccessLevel = AccessLevels.CurrentReadOrWrite; } this.UserAccessLevel = this.AccessLevel; this.MinimumSamplingInterval = MinimumSamplingIntervals.Indeterminate; this.Historizing = false; // add a reference to the parent node. NodeId parentNodeId = ModelUtils.ConstructIdForDaElement(itemId, -1, namespaceIndex); this.AddReference(ReferenceTypeIds.HasProperty, true, parentNodeId); }
/// <summary> /// Returns the next child. /// </summary> private NodeStateReference NextChild(Stage stage) { ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle; ComDaClient client = system.SelectClient((ServerSystemContext)SystemContext); DaElement element = null; if (stage == Stage.Children) { if (m_browser == null) { return(null); } element = m_browser.Next(); if (element == null) { return(null); } // construct the node. NodeState node = ModelUtils.ConstructElement(SystemContext, element, m_namespaceIndex); // return the reference. return(new NodeStateReference(ReferenceTypeIds.Organizes, false, node)); } if (stage == Stage.Properties) { if (m_properties == null) { return(null); } for (int ii = m_position; ii < m_properties.Length; ii++) { if (m_properties[ii].PropertyId <= PropertyIds.TimeZone) { continue; } m_position = ii + 1; // construct the node. NodeState node = ModelUtils.ConstructProperty(SystemContext, m_itemId, m_properties[ii], m_namespaceIndex); // return the reference. return(new NodeStateReference(ReferenceTypeIds.HasProperty, false, node)); } // all done. return(null); } if (stage == Stage.Parents) { if (m_parentId != null) { NodeId parentId = ModelUtils.ConstructIdForDaElement(m_parentId, -1, m_namespaceIndex); m_parentId = null; return(new NodeStateReference(ReferenceTypeIds.Organizes, true, parentId)); } } return(null); }
/// <summary> /// Initializes the node from the element. /// </summary> /// <param name="context">The context.</param> /// <param name="element">The element.</param> /// <param name="namespaceIndex">Index of the namespace.</param> public void Initialize(ISystemContext context, DaElement element, ushort namespaceIndex) { m_element = element; if (element == null) { return; } this.NodeId = ModelUtils.ConstructIdForDaElement(element.ItemId, -1, namespaceIndex); this.BrowseName = new QualifiedName(element.Name, namespaceIndex); this.DisplayName = new LocalizedText(element.Name); // check if TimeZone is supported. if (element.TimeZone != null) { PropertyState property = this.AddProperty <Range>(Opc.Ua.BrowseNames.TimeZone, DataTypeIds.TimeZoneDataType, ValueRanks.Scalar); property.NodeId = ModelUtils.ConstructIdForComponent(property, namespaceIndex); property.Value = new Range(element.HighIR, element.LowIR); } // set the TypeDefinition based on the ElementType. switch (element.ElementType) { case DaElementType.AnalogItem: { this.TypeDefinitionId = Opc.Ua.VariableTypeIds.AnalogItemType; // EURange is always present. PropertyState property = this.AddProperty <Range>(Opc.Ua.BrowseNames.EURange, DataTypeIds.Range, ValueRanks.Scalar); property.NodeId = ModelUtils.ConstructIdForComponent(property, namespaceIndex); property.Value = new Range(element.HighEU, element.LowEU); // check if InstrumentRange is supported. if (element.HighIR != 0 || element.LowIR != 0) { property = this.AddProperty <Range>(Opc.Ua.BrowseNames.InstrumentRange, DataTypeIds.Range, ValueRanks.Scalar); property.NodeId = ModelUtils.ConstructIdForComponent(property, namespaceIndex); property.Value = new Range(element.HighIR, element.LowIR); } // check if EngineeringUnits is supported. if (element.EngineeringUnits != null) { property = this.AddProperty <EUInformation>(Opc.Ua.BrowseNames.EngineeringUnits, DataTypeIds.EUInformation, ValueRanks.Scalar); property.NodeId = ModelUtils.ConstructIdForComponent(property, namespaceIndex); // use the server's namespace uri to qualify the engineering units. string namespaceUri = context.NamespaceUris.GetString(namespaceIndex); property.Value = new EUInformation(element.EngineeringUnits, namespaceUri); } break; } case DaElementType.DigitalItem: { this.TypeDefinitionId = Opc.Ua.VariableTypeIds.TwoStateDiscreteType; this.EnumStrings = new PropertyState <LocalizedText[]>(this); // check if CloseLabel is supported. if (element.CloseLabel != null) { PropertyState property = this.AddProperty <LocalizedText>(Opc.Ua.BrowseNames.TrueState, DataTypeIds.LocalizedText, ValueRanks.Scalar); property.NodeId = ModelUtils.ConstructIdForComponent(property, namespaceIndex); property.Value = element.CloseLabel; } // check if OpenLabel is supported. if (element.OpenLabel != null) { PropertyState property = this.AddProperty <LocalizedText>(Opc.Ua.BrowseNames.FalseState, DataTypeIds.LocalizedText, ValueRanks.Scalar); property.NodeId = ModelUtils.ConstructIdForComponent(property, namespaceIndex); property.Value = element.OpenLabel; } break; } case DaElementType.EnumeratedItem: { this.TypeDefinitionId = Opc.Ua.VariableTypeIds.MultiStateDiscreteType; // check if EuInfo is supported. if (element.EuInfo != null) { PropertyState property = this.AddProperty <LocalizedText[]>(Opc.Ua.BrowseNames.EnumStrings, DataTypeIds.LocalizedText, ValueRanks.OneDimension); property.NodeId = ModelUtils.ConstructIdForComponent(property, namespaceIndex); LocalizedText[] strings = new LocalizedText[element.EuInfo.Length]; for (int ii = 0; ii < strings.Length; ii++) { strings[ii] = element.EuInfo[ii]; } property.Value = strings; } break; } } if (element.Description != null) { this.Description = element.Description; } this.Value = null; this.StatusCode = StatusCodes.BadWaitingForInitialData; this.Timestamp = DateTime.UtcNow; bool isArray = false; this.DataType = ComUtils.GetDataTypeId(element.DataType, out isArray); this.ValueRank = (isArray)?ValueRanks.OneOrMoreDimensions:ValueRanks.Scalar; this.AccessLevel = AccessLevels.None; if ((element.AccessRights & OpcRcw.Da.Constants.OPC_READABLE) != 0) { this.AccessLevel |= AccessLevels.CurrentRead; } if ((element.AccessRights & OpcRcw.Da.Constants.OPC_WRITEABLE) != 0) { this.AccessLevel |= AccessLevels.CurrentWrite; } this.UserAccessLevel = this.AccessLevel; this.MinimumSamplingInterval = element.ScanRate; }