ConstructIdForComponent() публичный статический Метод

Constructs the node identifier for a component.
public static ConstructIdForComponent ( NodeState component, ushort namespaceIndex ) : Opc.Ua.NodeId
component NodeState The component.
namespaceIndex ushort Index of the namespace.
Результат Opc.Ua.NodeId
Пример #1
0
        /// <summary>
        /// Creates the NodeId for the specified node.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="node">The node.</param>
        /// <returns>The new NodeId.</returns>
        /// <remarks>
        /// This method is called by the NodeState.Create() method which initializes a Node from
        /// the type model. During initialization a number of child nodes are created and need to
        /// have NodeIds assigned to them. This implementation constructs NodeIds by constructing
        /// strings. Other implementations could assign unique integers or Guids and save the new
        /// Node in a dictionary for later lookup.
        /// </remarks>
        public override NodeId New(ISystemContext context, NodeState node)
        {
            // do not assign node id to server state nodes.
            if (node is ComServerStatusState)
            {
                return(node.NodeId);
            }

            return(DaModelUtils.ConstructIdForComponent(node, NamespaceIndex));
        }
Пример #2
0
        /// <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      = DaModelUtils.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.LocalTime, DataTypeIds.TimeZoneDataType, ValueRanks.Scalar);
                property.NodeId = DaModelUtils.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 = DaModelUtils.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 = DaModelUtils.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 = DaModelUtils.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;

                // check if CloseLabel is supported.
                if (element.CloseLabel != null)
                {
                    PropertyState property = this.AddProperty <LocalizedText>(Opc.Ua.BrowseNames.TrueState, DataTypeIds.LocalizedText, ValueRanks.Scalar);
                    property.NodeId = DaModelUtils.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 = DaModelUtils.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 = DaModelUtils.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;
        }