A object which maps a COM DA item to a UA variable.
Inheritance: BaseDataVariableState
Ejemplo n.º 1
0
        /// <summary>
        /// Adds a request for the specified source.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="nodeToRead">The node to read.</param>
        /// <param name="value">The value.</param>
        /// <param name="queued">if set to <c>true</c> [queued].</param>
        /// <returns></returns>
        public StatusCode Add(NodeState source, ReadValueId nodeToRead, DataValue value, out bool queued)
        {
            queued = true;

            // read item value.
            DaItemState item = source as DaItemState;

            if (item != null)
            {
                return(Add(item, nodeToRead, out queued));
            }

            // read vendor defined property value.
            DaPropertyState daProperty = source as DaPropertyState;

            if (daProperty != null)
            {
                return(Add(daProperty, nodeToRead, out queued));
            }

            // read UA defined property value.
            PropertyState uaProperty = source as PropertyState;

            if (uaProperty != null)
            {
                return(Add(uaProperty, nodeToRead, out queued));
            }

            queued = false;
            return(StatusCodes.Good);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a write request for a DA item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="nodeToWrite">The node to write.</param>
        /// <param name="index">The index associated with the value.</param>
        /// <returns>StatusCode.Good if the write is allowed. An error code otherwise.</returns>
        private StatusCode Add(DaItemState item, WriteValue nodeToWrite, int index)
        {
            if (nodeToWrite.AttributeId != Attributes.Value)
            {
                return(StatusCodes.BadNotWritable);
            }

            //if (nodeToWrite.ParsedIndexRange != NumericRange.Empty)
            //{
            //    return StatusCodes.BadIndexRangeInvalid;
            //}

            if (nodeToWrite.Value.ServerTimestamp != DateTime.MinValue)
            {
                return(StatusCodes.BadWriteNotSupported);
            }

            if (item.Element.DataType != 0)
            {
                if (!CheckDataType(item.Element.DataType, nodeToWrite.Value.WrappedValue))
                {
                    return(StatusCodes.BadTypeMismatch);
                }
            }

            WriteRequest request = new WriteRequest(item.ItemId, nodeToWrite.Value, index);

            Add(request);
            return(StatusCodes.Good);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a read request for the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="nodeToRead">The node to read.</param>
        /// <param name="queued">if set to <c>true</c> if a request was created.</param>
        /// <returns>Any error.</returns>
        private StatusCode Add(DaItemState item, ReadValueId nodeToRead, out bool queued)
        {
            queued = true;

            switch (nodeToRead.AttributeId)
            {
            case Attributes.Value:
            {
                nodeToRead.Handle = Add(item.ItemId);
                break;
            }

            case Attributes.Description:
            {
                nodeToRead.Handle = Add(item.ItemId, PropertyIds.Description);
                break;
            }

            case Attributes.DataType:
            case Attributes.ValueRank:
            {
                nodeToRead.Handle = Add(item.ItemId, PropertyIds.DataType);
                break;
            }

            case Attributes.AccessLevel:
            case Attributes.UserAccessLevel:
            {
                nodeToRead.Handle = Add(item.ItemId, PropertyIds.AccessRights);
                break;
            }

            case Attributes.MinimumSamplingInterval:
            {
                nodeToRead.Handle = Add(item.ItemId, PropertyIds.ScanRate);
                break;
            }

            default:
            {
                queued = false;
                break;
            }
            }

            return(StatusCodes.Good);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds a write request for a DA item.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="nodeToWrite">The node to write.</param>
        /// <param name="index">The index associated with the value.</param>
        /// <param name="queued">If set to <c>true</c> then the a request was added.</param>
        /// <returns>
        /// StatusCode.Good if the write is allowed. An error code otherwise.
        /// </returns>
        public StatusCode Add(NodeState source, WriteValue nodeToWrite, int index, out bool queued)
        {
            queued = true;

            DaItemState item = source as DaItemState;

            if (item != null)
            {
                return(Add(item, nodeToWrite, index));
            }

            DaPropertyState property = source as DaPropertyState;

            if (property != null)
            {
                return(Add(property, nodeToWrite, index));
            }

            queued = false;
            return(StatusCodes.Good);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the result.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="source">The source.</param>
        /// <param name="nodeToRead">The node to read.</param>
        /// <param name="value">The value.</param>
        /// <param name="diagnosticsMasks">The diagnostics masks.</param>
        /// <returns></returns>
        public ServiceResult GetResult(
            ISystemContext context,
            NodeState source,
            ReadValueId nodeToRead,
            DataValue value,
            DiagnosticsMasks diagnosticsMasks)
        {
            ReadRequest request = nodeToRead.Handle as ReadRequest;

            if (request == null)
            {
                return(StatusCodes.Good);
            }

            // read item value.
            DaItemState item = source as DaItemState;

            if (item != null)
            {
                return(request.GetResult(context, item, nodeToRead, value, diagnosticsMasks));
            }

            // read vendor defined property value.
            DaPropertyState daProperty = source as DaPropertyState;

            if (daProperty != null)
            {
                return(request.GetResult(context, daProperty, nodeToRead, value, diagnosticsMasks));
            }

            // read UA defined property value.
            PropertyState uaProperty = source as PropertyState;

            if (uaProperty != null)
            {
                return(request.GetResult(context, uaProperty, nodeToRead, value, diagnosticsMasks));
            }

            return(StatusCodes.Good);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds the specified property read to the request list.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="nodeToRead">The node to read.</param>
        /// <param name="queued">if set to <c>true</c> [queued].</param>
        /// <returns></returns>
        private StatusCode Add(PropertyState property, ReadValueId nodeToRead, out bool queued)
        {
            queued = false;

            DaItemState item = property.Parent as DaItemState;

            if (item == null)
            {
                return(StatusCodes.Good);
            }

            if (nodeToRead.AttributeId != Attributes.Value)
            {
                return(StatusCodes.Good);
            }

            queued = true;

            switch (property.SymbolicName)
            {
            case Opc.Ua.BrowseNames.EURange:
            {
                nodeToRead.Handle = Add(item.ItemId, PropertyIds.HighEU, PropertyIds.LowEU);
                break;
            }

            case Opc.Ua.BrowseNames.InstrumentRange:
            {
                nodeToRead.Handle = Add(item.ItemId, PropertyIds.HighIR, PropertyIds.LowIR);
                break;
            }

            case Opc.Ua.BrowseNames.EngineeringUnits:
            {
                nodeToRead.Handle = Add(item.ItemId, PropertyIds.EngineeringUnits);
                break;
            }

            case Opc.Ua.BrowseNames.EnumStrings:
            {
                nodeToRead.Handle = Add(item.ItemId, PropertyIds.EuInfo);
                break;
            }

            case Opc.Ua.BrowseNames.LocalTime:
            {
                nodeToRead.Handle = Add(item.ItemId, PropertyIds.TimeZone);
                break;
            }

            case Opc.Ua.BrowseNames.TrueState:
            {
                nodeToRead.Handle = Add(item.ItemId, PropertyIds.CloseLabel);
                break;
            }

            case Opc.Ua.BrowseNames.FalseState:
            {
                nodeToRead.Handle = Add(item.ItemId, PropertyIds.OpenLabel);
                break;
            }

            default:
            {
                queued = false;
                break;
            }
            }

            return(StatusCodes.Good);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the result for the read operation.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="property">The property.</param>
        /// <param name="nodeToRead">The node to read.</param>
        /// <param name="value">The value.</param>
        /// <param name="diagnosticsMasks">The diagnostics masks.</param>
        /// <returns></returns>
        public ServiceResult GetResult(
            ISystemContext context,
            PropertyState property,
            ReadValueId nodeToRead,
            DataValue value,
            DiagnosticsMasks diagnosticsMasks)
        {
            DaItemState item = property.Parent as DaItemState;

            if (item == null)
            {
                return(StatusCodes.BadNodeIdUnknown);
            }

            if (nodeToRead.AttributeId != Attributes.Value)
            {
                return(StatusCodes.BadAttributeIdInvalid);
            }

            switch (property.SymbolicName)
            {
            case Opc.Ua.BrowseNames.EURange:
            {
                double high = this.GetPropertyValue <double>(Opc.Ua.Com.PropertyIds.HighEU, value, true);

                if (StatusCode.IsBad(value.StatusCode))
                {
                    return(value.StatusCode);
                }

                double low = this.GetPropertyValue <double>(Opc.Ua.Com.PropertyIds.LowEU, value, true);

                if (StatusCode.IsBad(value.StatusCode))
                {
                    return(value.StatusCode);
                }

                value.Value = new Range(high, low);
                break;
            }

            case Opc.Ua.BrowseNames.InstrumentRange:
            {
                double high = this.GetPropertyValue <double>(Opc.Ua.Com.PropertyIds.HighIR, value, true);

                if (StatusCode.IsBad(value.StatusCode))
                {
                    return(value.StatusCode);
                }

                double low = this.GetPropertyValue <double>(Opc.Ua.Com.PropertyIds.LowIR, value, true);

                if (StatusCode.IsBad(value.StatusCode))
                {
                    return(value.StatusCode);
                }

                value.Value = new Range(high, low);
                break;
            }

            case Opc.Ua.BrowseNames.EngineeringUnits:
            {
                string units = this.GetPropertyValue <string>(Opc.Ua.Com.PropertyIds.EngineeringUnits, value, true);

                if (StatusCode.IsBad(value.StatusCode))
                {
                    return(value.StatusCode);
                }

                value.Value = new EUInformation(units, Namespaces.ComInterop);
                break;
            }

            case Opc.Ua.BrowseNames.EnumStrings:
            {
                string[] strings = this.GetPropertyValue <string[]>(Opc.Ua.Com.PropertyIds.EuInfo, value, true);

                if (StatusCode.IsBad(value.StatusCode))
                {
                    return(value.StatusCode);
                }

                if (strings != null)
                {
                    LocalizedText[] texts = new LocalizedText[strings.Length];

                    for (int ii = 0; ii < texts.Length; ii++)
                    {
                        texts[ii] = new LocalizedText(strings[ii]);
                    }

                    value.Value = texts;
                }

                break;
            }

            case Opc.Ua.BrowseNames.LocalTime:
            {
                int timebias = this.GetPropertyValue <int>(Opc.Ua.Com.PropertyIds.TimeZone, value, true);

                if (StatusCode.IsBad(value.StatusCode))
                {
                    return(value.StatusCode);
                }

                TimeZoneDataType timeZone = new TimeZoneDataType();
                timeZone.Offset = (short)timebias;
                timeZone.DaylightSavingInOffset = false;

                value.Value = timeZone;
                break;
            }

            case Opc.Ua.BrowseNames.TrueState:
            {
                string description = this.GetPropertyValue <string>(Opc.Ua.Com.PropertyIds.CloseLabel, value, false);

                if (StatusCode.IsGood(value.StatusCode))
                {
                    value.Value = new LocalizedText(description);
                }

                break;
            }

            case Opc.Ua.BrowseNames.FalseState:
            {
                string description = this.GetPropertyValue <string>(Opc.Ua.Com.PropertyIds.OpenLabel, value, false);

                if (StatusCode.IsGood(value.StatusCode))
                {
                    value.Value = new LocalizedText(description);
                }

                break;
            }

            default:
            {
                return(StatusCodes.BadAttributeIdInvalid);
            }
            }

            // check if the property value is missing.
            if (value.StatusCode == StatusCodes.BadNotFound)
            {
                return(StatusCodes.BadNodeIdUnknown);
            }

            return(ApplyIndexRangeAndDataEncoding(context, nodeToRead, value));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the result for the read operayoin.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="item">The item.</param>
        /// <param name="nodeToRead">The node to read.</param>
        /// <param name="value">The value.</param>
        /// <param name="diagnosticsMasks">The diagnostics masks.</param>
        /// <returns></returns>
        public ServiceResult GetResult(
            ISystemContext context,
            DaItemState item,
            ReadValueId nodeToRead,
            DataValue value,
            DiagnosticsMasks diagnosticsMasks)
        {
            if (nodeToRead.AttributeId == Attributes.Value)
            {
                ServiceResult result = GetItemValue(m_value, value, diagnosticsMasks);

                if (ServiceResult.IsBad(result))
                {
                    return(result);
                }

                return(ApplyIndexRangeAndDataEncoding(context, nodeToRead, value));
            }

            switch (nodeToRead.AttributeId)
            {
            case Attributes.Description:
            {
                string description = this.GetPropertyValue <string>(Opc.Ua.Com.PropertyIds.Description, value, false);

                if (StatusCode.IsGood(value.StatusCode))
                {
                    value.Value = new LocalizedText(description);
                }

                break;
            }

            case Attributes.DataType:
            {
                short datatype = this.GetPropertyValue <short>(Opc.Ua.Com.PropertyIds.DataType, value, false);

                if (StatusCode.IsGood(value.StatusCode))
                {
                    value.Value = ComUtils.GetDataTypeId(datatype);
                }

                break;
            }

            case Attributes.ValueRank:
            {
                short datatype = this.GetPropertyValue <short>(Opc.Ua.Com.PropertyIds.DataType, value, false);

                if (StatusCode.IsGood(value.StatusCode))
                {
                    value.Value = ComUtils.GetValueRank(datatype);
                }

                break;
            }

            case Attributes.AccessLevel:
            case Attributes.UserAccessLevel:
            {
                int accessRights = this.GetPropertyValue <int>(Opc.Ua.Com.PropertyIds.AccessRights, value, false);

                if (StatusCode.IsGood(value.StatusCode))
                {
                    value.Value = (byte)accessRights;
                }

                break;
            }

            case Attributes.MinimumSamplingInterval:
            {
                float scanRate = this.GetPropertyValue <float>(Opc.Ua.Com.PropertyIds.ScanRate, value, false);

                if (StatusCode.IsGood(value.StatusCode))
                {
                    value.Value = (double)scanRate;
                }

                break;
            }

            default:
            {
                return(StatusCodes.BadAttributeIdInvalid);
            }
            }

            // check if the property value is missing.
            if (value.StatusCode == StatusCodes.BadNotFound)
            {
                return(StatusCodes.BadAttributeIdInvalid);
            }

            return(ApplyIndexRangeAndDataEncoding(context, nodeToRead, value));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Removes a request for the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="monitoredItem">The monitored item.</param>
        private void Remove(DaItemState item, MonitoredItem monitoredItem)
        {
            if (monitoredItem.AttributeId == Attributes.Value)
            {
                SubscribeItemRequest request = FindItemRequest(item.ItemId, false);

                if (request != null)
                {
                    request.Remove(monitoredItem);
                }
            }
            else
            {
                int propertyId = SubscribePropertyRequest.DaItemAttributeToDaProperty(monitoredItem.AttributeId);

                if (propertyId < 0)
                {
                    return;
                }

                SubscribePropertyRequest request = FindPropertyRequest(item.ItemId, false);

                if (request != null)
                {
                    request.Remove(m_context, monitoredItem);

                    if (request.MonitoredItems.Count == 0)
                    {
                        m_subscribedProperties.Remove(item.ItemId);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds a request for the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="monitoredItem">The monitored item.</param>
        private void Add(DaItemState item, MonitoredItem monitoredItem)
        {
            if (monitoredItem.AttributeId == Attributes.Value)
            {
                SubscribeItemRequest request = FindItemRequest(item.ItemId, true);

                if (request != null)
                {
                    request.Add(monitoredItem);
                }
            }
            else
            {
                int propertyId = SubscribePropertyRequest.DaItemAttributeToDaProperty(monitoredItem.AttributeId);

                if (propertyId < 0)
                {
                    return;
                }

                SubscribePropertyRequest request = FindPropertyRequest(item.ItemId, true);

                if (request != null)
                {
                    request.Add(m_context, monitoredItem);
                }
            }
        }