Exemple #1
0
        /// <summary>
        /// Pushes the next raw value into the stream.
        /// </summary>
        /// <param name="value">The data value to append to the stream.</param>
        /// <returns>True if successful, false if the source timestamp has been superceeded by values already in the stream.</returns>
        public bool PushRawValue(DataValue value)
        {
            if (value == null)
            {
                return false;
            }

            if (CompareTimestamps(value.SourceTimestamp, m_lastRawTimestamp) < 0)
            {
                return false;
            }

            LinkedListNode<DataValue> node = m_values.AddLast(value);
            m_lastRawTimestamp = value.SourceTimestamp;

            if (IsGood(value))
            {
                if (CompareTimestamps(m_lastRawTimestamp, m_nextSlice.StartTime) <= 0)
                {
                    m_nextSlice.EarlyBound = node;
                }

                if (CompareTimestamps(m_lastRawTimestamp, m_nextSlice.EndTime) >= 0)
                {
                    m_nextSlice.LateBound = node;
                    m_nextSlice.Complete = true;
                }
            }

            return true;
        }
        /// <summary>
        /// Reads the data for an item at the specified times.
        /// </summary>
        private StatusCode ReadAtTime(HdaHistoryReadAtTimeRequest request)
        {
            string methodName = "IOPCHDA_SyncRead.ReadAtTime";

            IntPtr ppItemValues;
            IntPtr ppErrors;

            System.Runtime.InteropServices.ComTypes.FILETIME[] pTimestamps = new System.Runtime.InteropServices.ComTypes.FILETIME[request.ReqTimes.Count];

            for (int ii = 0; ii < pTimestamps.Length; ii++)
            {
                pTimestamps[ii] = ComUtils.GetFILETIME(request.ReqTimes[ii]);
            }

            try
            {
                IOPCHDA_SyncRead server = BeginComCall<IOPCHDA_SyncRead>(methodName, true);

                server.ReadAtTime(
                    pTimestamps.Length,
                    pTimestamps,
                    1,
                    new int[] { request.ServerHandle },
                    out ppItemValues,
                    out ppErrors);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
                return StatusCodes.BadUnexpectedError;
            }
            finally
            {
                EndComCall(methodName);
            }

            // check for error.
            int[] errors = ComUtils.GetInt32s(ref ppErrors, 1, true);

            if (errors[0] < 0)
            {
                return StatusCodes.BadNodeIdUnknown;
            }

            // check if operation halted.
            request.Completed = true;

            // unmarshal the results.
            OPCHDA_ITEM result = (OPCHDA_ITEM)Marshal.PtrToStructure(ppItemValues, typeof(OPCHDA_ITEM));

            if (result.dwCount > 0)
            {
                object[] values = ComUtils.GetVARIANTs(ref result.pvDataValues, result.dwCount, true);
                int[] qualities = ComUtils.GetInt32s(ref result.pdwQualities, result.dwCount, true);
                DateTime[] timestamps = ComUtils.GetDateTimes(ref result.pftTimeStamps, result.dwCount, true);

                request.Results = new DataValueCollection(result.dwCount);

                for (int ii = 0; ii < result.dwCount; ii++)
                {
                    DataValue value = new DataValue();
                    value.Value = ComUtils.ProcessComValue(values[ii]);
                    value.StatusCode = ComUtils.GetHdaQualityCode(Utils.ToUInt32(qualities[ii]));
                    value.SourceTimestamp = timestamps[ii];
                    request.Results.Add(value);
                }
            }

            Marshal.FreeCoTaskMem(ppItemValues);

            if (result.dwCount == 0)
            {
                return StatusCodes.GoodNoData;
            }

            return StatusCodes.Good;
        }
        /// <summary>
        /// Reads the raw modified data for an item.
        /// </summary>
        private StatusCode ReadModified(HdaHistoryReadRawModifiedRequest request)
        {
            string methodName = "IOPCHDA_SyncRead.ReadModified";

            OPCHDA_TIME htStartTime = ConvertTime(request.StartTime);
            OPCHDA_TIME htEndTime = ConvertTime(request.EndTime);

            int maxReturnValues = request.MaxReturnValues;

            if (m_maxReturnValues > 0 && maxReturnValues > m_maxReturnValues)
            {
                maxReturnValues = m_maxReturnValues;
            }

            IntPtr ppItemValues;
            IntPtr ppErrors;

            try
            {
                IOPCHDA_SyncRead server = BeginComCall<IOPCHDA_SyncRead>(methodName, true);

                server.ReadModified(
                    ref htStartTime,
                    ref htEndTime,
                    maxReturnValues,
                    1,
                    new int[] { request.ServerHandle },
                    out ppItemValues,
                    out ppErrors);
            }
            catch (Exception e)
            {
                if (ComUtils.IsUnknownError(e, ResultIds.E_NOTIMPL))
                {
                    ComCallError(methodName, e);
                }

                return StatusCodes.BadNoData;
            }
            finally
            {
                EndComCall(methodName);
            }

            // check for error.
            int[] errors = ComUtils.GetInt32s(ref ppErrors, 1, true);

            if (errors[0] < 0)
            {
                return StatusCodes.BadNodeIdUnknown;
            }

            // check if operation halted.
            request.Completed = errors[0] != ResultIds.S_MOREDATA;

            // unmarshal the results.
            OPCHDA_MODIFIEDITEM result = (OPCHDA_MODIFIEDITEM)Marshal.PtrToStructure(ppItemValues, typeof(OPCHDA_MODIFIEDITEM));

            if (result.dwCount > 0)
            {
                object[] values = ComUtils.GetVARIANTs(ref result.pvDataValues, result.dwCount, true);
                int[] qualities = ComUtils.GetInt32s(ref result.pdwQualities, result.dwCount, true);
                DateTime[] timestamps = ComUtils.GetDateTimes(ref result.pftTimeStamps, result.dwCount, true);
                DateTime[] modificationTimes = ComUtils.GetDateTimes(ref result.pftModificationTime, result.dwCount, true);
                string[] userNames = ComUtils.GetUnicodeStrings(ref result.szUser, result.dwCount, true);
                int[] editTypes = ComUtils.GetInt32s(ref result.pEditType, result.dwCount, true);

                request.Results = new DataValueCollection(result.dwCount);
                request.ModificationInfos = new ModificationInfoCollection(result.dwCount);

                for (int ii = 0; ii < result.dwCount; ii++)
                {
                    DataValue value = new DataValue();
                    value.Value = ComUtils.ProcessComValue(values[ii]);
                    value.StatusCode = ComUtils.GetHdaQualityCode(Utils.ToUInt32(qualities[ii]));
                    value.SourceTimestamp = timestamps[ii];
                    request.Results.Add(value);

                    ModificationInfo modification = new ModificationInfo();
                    modification.ModificationTime = modificationTimes[ii];
                    modification.UpdateType = (HistoryUpdateType)editTypes[ii];
                    modification.UserName = userNames[ii];
                    request.ModificationInfos.Add(modification);
                }

                if (!request.Completed)
                {
                    request.StartTime = request.Results[request.Results.Count-1].SourceTimestamp;
                }
            }

            Marshal.FreeCoTaskMem(ppItemValues);

            if (result.dwCount == 0)
            {
                return StatusCodes.GoodNoData;
            }

            if (maxReturnValues > 0 && !request.Completed)
            {
                return StatusCodes.GoodMoreData;
            }

            return StatusCodes.Good;
        }
Exemple #4
0
 public override string ToString(DataValue dv)
 {
   DateTime dt = DateTime.Parse(dv.ToString());
   return dt.ToLocalTime().ToString();
 }
        /// <summary>
        /// Writes an DataValue array to the stream.
        /// </summary>
        public void WriteDataValue(string fieldName, DataValue value)
        {
            if (BeginField(fieldName, value == null, true))
            {
                PushNamespace(Namespaces.OpcUaXsd);

                if (value != null)
                {
                    WriteVariant("Value", value.WrappedValue);
                    WriteStatusCode("StatusCode", value.StatusCode);
                    WriteDateTime("SourceTimestamp", value.SourceTimestamp);
                    WriteUInt16("SourcePicoseconds", value.SourcePicoseconds);
                    WriteDateTime("ServerTimestamp", value.ServerTimestamp);
                    WriteUInt16("ServerPicoseconds", value.ServerPicoseconds);
                }

                PopNamespace();
                
                EndField(fieldName);
            }
        }                
Exemple #6
0
        /// <summary>
        /// Reads an DataValue from the stream.
        /// </summary>
        public DataValue ReadDataValue(string fieldName)
        {
            DataValue value = new DataValue();

            if (BeginField(fieldName, true))
            {
                PushNamespace(Namespaces.OpcUaXsd);
                
                value.WrappedValue      = ReadVariant("Value");
                value.StatusCode        = ReadStatusCode("StatusCode");
                value.SourceTimestamp   = ReadDateTime("SourceTimestamp");
                value.SourcePicoseconds = ReadUInt16("SourcePicoseconds");
                value.ServerTimestamp   = ReadDateTime("ServerTimestamp");
                value.ServerPicoseconds = ReadUInt16("ServerPicoseconds");

                PopNamespace();
                
                EndField(fieldName);
            }

            return value;
        }
Exemple #7
0
 public DataValue() { m_value = new Opc.Ua.DataValue();  }
Exemple #8
0
 public DataValue()
 {
     m_value = new Opc.Ua.DataValue();
 }
Exemple #9
0
        /// <summary>
        /// Writes the value of an attribute.
        /// </summary>
        /// <param name="attributeId">The attribute id.</param>
        /// <param name="value">The value.</param>
        /// <returns>The result of write operation.</returns>
        public ServiceResult Write(uint attributeId, DataValue value)
        {
            if (!SupportsAttribute(attributeId))
            {
                return StatusCodes.BadAttributeIdInvalid;
            }
            
            // check for read only attributes.
            switch (attributeId)
            {
                case Attributes.NodeId:
                case Attributes.NodeClass:
                {
                    return StatusCodes.BadNotWritable;
                }
            }

            // check data type.
            if (attributeId != Attributes.Value)
            {
                if (Attributes.GetDataTypeId(attributeId) != TypeInfo.GetDataTypeId(value))
                {
                    return StatusCodes.BadTypeMismatch;
                }
            }

            return Write(attributeId, value.Value);
        }
Exemple #10
0
        /// <summary>
        /// Reads the value of a attribute.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="attributeId">The attribute id.</param>
        /// <param name="value">The value.</param>
        /// <returns>The result of read operation.</returns>
        public ServiceResult Read(IOperationContext context, uint attributeId, DataValue value)
        {
            if (!SupportsAttribute(attributeId))
            {
                return StatusCodes.BadAttributeIdInvalid;
            }

            value.Value      = Read(attributeId);
            value.StatusCode = StatusCodes.Good;

            if (attributeId == Attributes.Value)
            {
                value.SourceTimestamp = DateTime.UtcNow;
            }

            return ServiceResult.Good;
        }
        /// <summary>
        /// Returns the data value displayed in the control.
        /// </summary>
        public void SetDataValue(DataValue value, TypeInfo targetType)
        {
            DataTypeCB.SelectedItem = BuiltInType.Null;
            ValueRankCB.SelectedItem = ValueRankOptions.Scalar;

            StatusCode = StatusCodes.Good;
            SourceTimestamp = DateTime.MinValue;
            ServerTimestamp = DateTime.MinValue;

            if (value != null)
            {
                SetValue(value.WrappedValue);

                StatusCode = value.StatusCode;
                SourceTimestamp = value.SourceTimestamp;
                ServerTimestamp = value.ServerTimestamp;

                StatusCodeCK.Checked = true;
                SourceTimestampCK.Checked = true;
                ServerTimestampCK.Checked = true;
            }

            // allow data type to be changed by default.
            DataTypeCB.Enabled = true;

            if (targetType != null)
            {
                DataType = targetType.BuiltInType;
                ValueRank = targetType.ValueRank;

                DataTypeCB.Enabled = false;
                ValueRankCB.Enabled = false;
            }
        }
        /// <summary>
        /// Returns the data value displayed in the control.
        /// </summary>
        public DataValue GetDataValue()
        {
            DataValue value = new DataValue();
            value.WrappedValue = GetValue();

            if (ShowStatusTimestamp)
            {
                value.StatusCode = StatusCode;
                value.SourceTimestamp = SourceTimestamp;
                value.ServerTimestamp = ServerTimestamp;
            }

            return value;
        }
        public Variant ReadVariant(string fieldName)
        {
            // read the encoding byte.
            byte encodingByte = m_reader.ReadByte();

            Variant value = new Variant();

            if ((encodingByte & (byte)VariantArrayEncodingBits.Array) != 0)
            {
                // read the array length.
                int length = m_reader.ReadInt32();

                if (length < 0)
                {
                    return value;
                }

                Array array = null;

                BuiltInType builtInType = (BuiltInType)(encodingByte & (byte)VariantArrayEncodingBits.TypeMask);
                
                switch (builtInType)
                {
                    case BuiltInType.Boolean:
                    {
                        bool[] values = new bool[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadBoolean(null);
                        }
                        
                        array = values;
                        break;
                    }

                    case BuiltInType.SByte:
                    {
                        sbyte[] values = new sbyte[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadSByte(null);
                        }
                        
                        array = values;
                        break;
                    }

                    case BuiltInType.Byte:
                    {
                        byte[] values = new byte[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadByte(null);
                        }

                        array = values;
                        break;
                    }

                    case BuiltInType.Int16:
                    {
                        short[] values = new short[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadInt16(null);
                        }
                        
                        array = values;
                        break;
                    }

                    case BuiltInType.UInt16:
                    {
                        ushort[] values = new ushort[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadUInt16(null);
                        }
                        
                        array = values;
                        break;
                    }

                    case BuiltInType.Int32:
                    case BuiltInType.Enumeration:
                    {
                        int[] values = new int[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadInt32(null);
                        }
                        
                        array = values;
                        break;
                    }

                    case BuiltInType.UInt32:
                    {
                        uint[] values = new uint[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadUInt32(null);
                        }
                        
                        array = values;
                        break;
                    }

                    case BuiltInType.Int64:
                    {
                        long[] values = new long[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadInt64(null);
                        }
                        
                        array = values;
                        break;
                    }

                    case BuiltInType.UInt64:
                    {
                        ulong[] values = new ulong[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadUInt64(null);
                        }
                        
                        array = values;
                        break;
                    }

                    case BuiltInType.Float:
                    {
                        float[] values = new float[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadFloat(null);
                        }
                        
                        array = values;
                        break;
                    }

                    case BuiltInType.Double:
                    {
                        double[] values = new double[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadDouble(null);
                        }
                        
                        array = values;
                        break;
                    }

                    case BuiltInType.String:
                    {
                        string[] values = new string[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadString(null);
                        }
                        
                        array = values;
                        break;
                    }

                    case BuiltInType.DateTime:
                    {
                        DateTime[] values = new DateTime[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadDateTime(null);
                        }
                        
                        array = values;
                        break;
                    }

                    case BuiltInType.Guid:
                    {
                        Uuid[] values = new Uuid[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadGuid(null);
                        }
                        
                        array = values;
                        break;
                    }

                    case BuiltInType.ByteString:
                    {
                        byte[][] values = new byte[length][];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadByteString(null);
                        }
                        
                        array = values;
                        break;
                    }

                    case BuiltInType.XmlElement:
                    {
                        try
                        {
                            XmlElement[] values = new XmlElement[length];

                            for (int ii = 0; ii < values.Length; ii++)
                            {
                                values[ii] = ReadXmlElement(null);
                            }

                            array = values;
                        }
                        catch(Exception ex)
                        {
                            Utils.Trace(ex, "Error reading variant.");
                        }

                        break;
                    }
                        
                    case BuiltInType.NodeId:
                    {
                        NodeId[] values = new NodeId[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadNodeId(null);
                        }
                        
                        array = values;
                        break;
                    }
                        
                    case BuiltInType.ExpandedNodeId:
                    {
                        ExpandedNodeId[] values = new ExpandedNodeId[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadExpandedNodeId(null);
                        }
                        
                        array = values;
                        break;
                    }
                        
                    case BuiltInType.StatusCode:
                    {
                        StatusCode[] values = new StatusCode[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadStatusCode(null);
                        }
                        
                        array = values;
                        break;
                    }
                        
                    case BuiltInType.QualifiedName:
                    {
                        QualifiedName[] values = new QualifiedName[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadQualifiedName(null);
                        }
                        
                        array = values;
                        break;
                    }
                        
                    case BuiltInType.LocalizedText:
                    {
                        LocalizedText[] values = new LocalizedText[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadLocalizedText(null);
                        }
                        
                        array = values;
                        break;
                    }
                        
                    case BuiltInType.ExtensionObject:
                    {
                        ExtensionObject[] values = new ExtensionObject[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadExtensionObject();
                        }
                        
                        array = values;
                        break;
                    }
                        
                    case BuiltInType.DataValue:
                    {
                        DataValue[] values = new DataValue[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadDataValue(null);
                        }
                        
                        array = values;
                        break;
                    }
                        
                    case BuiltInType.Variant:
                    {
                        Variant[] values = new Variant[length];

                        for (int ii = 0; ii < values.Length; ii++)
                        {
                            values[ii] = ReadVariant(null);
                        }
                        
                        array = values;
                        break;
                    }

                    default:
                    {
                        throw new ServiceResultException(
                            StatusCodes.BadDecodingError,
                            Utils.Format("Cannot decode unknown type in Variant object (0x{0:X2}).", encodingByte)); 
                    }
                }

                if (array == null)
                {
                    value = new Variant(StatusCodes.BadEncodingError);
                }
                else
                {
                    // check for multi-dimensional arrays.
                    if ((encodingByte & (byte)VariantArrayEncodingBits.ArrayDimensions) != 0)
                    {
                        Int32Collection dimensions = ReadInt32Array(null);

                        if (dimensions != null && dimensions.Count > 0)
                        {
                            value = new Variant(new Matrix(array, builtInType, dimensions.ToArray()));
                        }
                        else
                        {
                            value = new Variant(new Matrix(array, builtInType));
                        }
                    }
                    else
                    {
                        value = new Variant(array);
                    }
                }
            }

            else
            {
                switch ((BuiltInType)encodingByte)
                {
                    case BuiltInType.Null:
                    {
                        value.Value = null;
                        break;
                    }

                    case BuiltInType.Boolean:
                    {
                        value.Set(ReadBoolean(null));
                        break;
                    }

                    case BuiltInType.SByte:
                    {
                        value.Set(ReadSByte(null));
                        break;
                    }

                    case BuiltInType.Byte:
                    {
                        value.Set(ReadByte(null));
                        break;
                    }

                    case BuiltInType.Int16:
                    {
                        value.Set(ReadInt16(null));
                        break;
                    }

                    case BuiltInType.UInt16:
                    {
                        value.Set(ReadUInt16(null));
                        break;
                    }

                    case BuiltInType.Int32:
                    case BuiltInType.Enumeration:
                    {
                        value.Set(ReadInt32(null));
                        break;
                    }

                    case BuiltInType.UInt32:
                    {
                        value.Set(ReadUInt32(null));
                        break;
                    }

                    case BuiltInType.Int64:
                    {
                        value.Set(ReadInt64(null));
                        break;
                    }

                    case BuiltInType.UInt64:
                    {
                        value.Set(ReadUInt64(null));
                        break;
                    }

                    case BuiltInType.Float:
                    {
                        value.Set(ReadFloat(null));
                        break;
                    }

                    case BuiltInType.Double:
                    {
                        value.Set(ReadDouble(null));
                        break;
                    }

                    case BuiltInType.String:
                    {
                        value.Set(ReadString(null));
                        break;
                    }

                    case BuiltInType.DateTime:
                    {
                        value.Set(ReadDateTime(null));
                        break;
                    }

                    case BuiltInType.Guid:
                    {
                        value.Set(ReadGuid(null));
                        break;
                    }

                    case BuiltInType.ByteString:
                    {
                        value.Set(ReadByteString(null));
                        break;
                    }

                    case BuiltInType.XmlElement:
                    {
                        try
                        {
                            value.Set(ReadXmlElement(null));
                        }
                        catch(Exception ex)
                        {
                            Utils.Trace(ex, "Error reading xml element for variant.");
                            value.Set(StatusCodes.BadEncodingError);
                        }                        
                        break;
                    }

                    case BuiltInType.NodeId:
                    {
                        value.Set(ReadNodeId(null));
                        break;
                    }

                    case BuiltInType.ExpandedNodeId:
                    {
                        value.Set(ReadExpandedNodeId(null));
                        break;
                    }
                        
                    case BuiltInType.StatusCode:
                    {
                        value.Set(ReadStatusCode(null));
                        break;
                    }

                    case BuiltInType.QualifiedName:
                    {
                        value.Set(ReadQualifiedName(null));
                        break;
                    }

                    case BuiltInType.LocalizedText:
                    {
                        value.Set(ReadLocalizedText(null));
                        break;
                    }

                    case BuiltInType.ExtensionObject:
                    {
                        value.Set(ReadExtensionObject());
                        break;
                    }

                    case BuiltInType.DataValue:
                    {
                        value.Set(ReadDataValue(null));
                        break;
                    }

                    default:
                    {
                        throw new ServiceResultException(
                            StatusCodes.BadDecodingError,
                            Utils.Format("Cannot decode unknown type in Variant object (0x{0:X2}).", encodingByte)); 
                    }
                }
            }

            return value;
        }
        /// <summary>
        /// Reads an DataValue from the stream.
        /// </summary>
        public DataValue ReadDataValue(string fieldName)
        {
            // read the encoding byte.
            byte encodingByte = m_reader.ReadByte();

            DataValue value = new DataValue();
                        
            // read the fields of the DataValue structure.
            if ((encodingByte & (byte)DataValueEncodingBits.Value) != 0)
            {
                value.WrappedValue = ReadVariant(null);
            }

            if ((encodingByte & (byte)DataValueEncodingBits.StatusCode) != 0)
            {
                value.StatusCode = ReadStatusCode(null);
            }

            if ((encodingByte & (byte)DataValueEncodingBits.SourceTimestamp) != 0)
            {
                value.SourceTimestamp = ReadDateTime(null);
            }

            if ((encodingByte & (byte)DataValueEncodingBits.SourcePicoseconds) != 0)
            {
                value.SourcePicoseconds = ReadUInt16(null);
            }
            
            if ((encodingByte & (byte)DataValueEncodingBits.ServerTimestamp) != 0)
            {
                value.ServerTimestamp = ReadDateTime(null);
            }

            if ((encodingByte & (byte)DataValueEncodingBits.ServerPicoseconds) != 0)
            {
                value.ServerPicoseconds = ReadUInt16(null);
            }
            
            return value;
        }
 /// <summary>
 /// Updates the row with the node to read.
 /// </summary>
 public void UpdateRow(DataRow row, DataValue value)
 {
     row[6] = value;
     row[7] = (value.WrappedValue.TypeInfo != null) ? value.WrappedValue.TypeInfo.ToString() : String.Empty;
     row[8] = value.WrappedValue;
     row[9] = value.StatusCode;
     row[10] = (value.SourceTimestamp != DateTime.MinValue) ? Utils.Format("{0:hh:mm:ss.fff}", value.SourceTimestamp.ToLocalTime()) : String.Empty;
     row[11] = (value.ServerTimestamp != DateTime.MinValue) ? Utils.Format("{0:hh:mm:ss.fff}", value.ServerTimestamp.ToLocalTime()) : String.Empty;
 }
        /// <summary>
        /// Reads the value for the specified attribute.
        /// </summary>
        public override void Read(
            OperationContext context,
            double maxAge,
            IList<ReadValueId> nodesToRead,
            IList<DataValue> values,
            IList<ServiceResult> errors)
        {
            ServerSystemContext systemContext = SystemContext.Copy(context);
            IDictionary<NodeId, NodeState> operationCache = new NodeIdDictionary<NodeState>();
            List<DataSourceClient.ReadRequest> readRequests = new List<DataSourceClient.ReadRequest>();

            lock (Lock)
            {
                for (int ii = 0; ii < nodesToRead.Count; ii++)
                {
                    ReadValueId nodeToRead = nodesToRead[ii];

                    // skip items that have already been processed.
                    if (nodeToRead.Processed)
                    {
                        continue;
                    }

                    // check for valid handle.
                    NodeHandle handle = GetManagerHandle(systemContext, nodeToRead.NodeId, operationCache);

                    if (handle == null)
                    {
                        continue;
                    }

                    // owned by this node manager.
                    nodeToRead.Processed = true;

                    // create an initial value.
                    DataValue value = values[ii] = new DataValue();

                    value.Value = null;
                    value.ServerTimestamp = DateTime.UtcNow;
                    value.SourceTimestamp = DateTime.MinValue;
                    value.StatusCode = StatusCodes.Good;

                    // check if the node is a area in memory.
                    if (handle.Node == null)
                    {
                        errors[ii] = StatusCodes.BadNodeIdUnknown;
                        continue;
                    }

                    if (nodeToRead.AttributeId == Attributes.Value)
                    {
                        // check if the request if for a remote node.
                        RemoteNode remoteNode = null;

                        if (m_remoteNodes.TryGetValue(handle.NodeId, out remoteNode))
                        {
                            DataSourceClient.ReadRequest request = new DataSourceClient.ReadRequest();
                            request.RemoteId = remoteNode.RemoteId;
                            request.ReadValueId = nodeToRead;
                            request.Value = value;
                            request.Index = ii;
                            readRequests.Add(request);

                            errors[ii] = StatusCodes.BadNoCommunication;
                            continue;
                        }
                    }

                    // read the attribute value.
                    errors[ii] = handle.Node.ReadAttribute(
                        systemContext,
                        nodeToRead.AttributeId,
                        nodeToRead.ParsedIndexRange,
                        nodeToRead.DataEncoding,
                        value);
                }

                // check for nothing to do.
                if (readRequests.Count == 0)
                {
                    return;
                }
            }

            // read from the remote data source.
            List<ServiceResult> results = m_source.Read(readRequests);

            for (int ii = 0; ii < readRequests.Count; ii++)
            {
                values[readRequests[ii].Index] = readRequests[ii].Value;
                errors[readRequests[ii].Index] = results[ii];
            }
        }
Exemple #17
0
        /// <summary>
        /// Adds a value to the grid.
        /// </summary>
        private void AddValue(DataValue value, ModificationInfo modificationInfo)
        {
            DataRow row = m_dataset.Tables[0].NewRow();

            row[0] = m_nextId++;
            row[1] = value.SourceTimestamp.ToLocalTime().ToString("HH:mm:ss.fff");
            row[2] = value.WrappedValue;
            row[3] = new StatusCode(value.StatusCode.Code);

            if (value.WrappedValue.TypeInfo != null)
            {
                row[4] = value.WrappedValue.TypeInfo.BuiltInType.ToString();
            }
            else
            {
                row[4] = String.Empty;
            }

            m_dataset.Tables[0].Rows.Add(row);
        }
Exemple #18
0
        /// <summary>
        /// Writes an DataValue array to the stream.
        /// </summary>
        public void WriteDataValue(string fieldName, DataValue value)
        {
            if (value == null)
            {
                WriteSimpleField(fieldName, null, false);
                return;
            }

            PushStructure(fieldName);

            if (value != null)
            {
                if (value.WrappedValue.TypeInfo != null && value.WrappedValue.TypeInfo.BuiltInType != BuiltInType.Null)
                {
                    WriteVariant("Value", value.WrappedValue);
                }

                if (value.StatusCode != StatusCodes.Good)
                {
                    WriteStatusCode("StatusCode", value.StatusCode);
                }

                if (value.SourceTimestamp != DateTime.MinValue)
                {
                    WriteDateTime("SourceTimestamp", value.SourceTimestamp);

                    if (value.SourcePicoseconds != 0)
                    {
                        WriteUInt16("SourcePicoseconds", value.SourcePicoseconds);
                    }
                }

                if (value.ServerTimestamp != DateTime.MinValue)
                {
                    WriteDateTime("ServerTimestamp", value.ServerTimestamp);

                    if (value.ServerPicoseconds != 0)
                    {
                        WriteUInt16("ServerPicoseconds", value.ServerPicoseconds);
                    }
                }
            }

            PopStructure();
        }                
Exemple #19
0
 public DataValue(Opc.Ua.DataValue value)
 {
     m_value = value;
 }
        /// <summary>
        /// Reads the value for the specified attribute.
        /// </summary>
        public virtual void Read(
            OperationContext     context, 
            double               maxAge, 
            IList<ReadValueId>   nodesToRead, 
            IList<DataValue>     values, 
            IList<ServiceResult> errors)
        {
            ServerSystemContext systemContext = m_systemContext.Copy(context);
            IDictionary<NodeId,NodeState> operationCache = new NodeIdDictionary<NodeState>();
            List<NodeHandle> nodesToValidate = new List<NodeHandle>();

            lock (Lock)
            {
                for (int ii = 0; ii < nodesToRead.Count; ii++)
                {                    
                    ReadValueId nodeToRead = nodesToRead[ii];

                    // skip items that have already been processed.
                    if (nodeToRead.Processed)
                    {
                        continue;
                    }
                    
                    // check for valid handle.
                    NodeHandle handle = GetManagerHandle(systemContext, nodeToRead.NodeId, operationCache);

                    if (handle == null)
                    {
                        continue;
                    }

                    // owned by this node manager.
                    nodeToRead.Processed = true;
                    
                    // create an initial value.
                    DataValue value = values[ii] = new DataValue();
                    
                    value.Value           = null;
                    value.ServerTimestamp = DateTime.UtcNow;
                    value.SourceTimestamp = DateTime.MinValue;
                    value.StatusCode      = StatusCodes.Good;

                    // check if the node is a area in memory.
                    if (handle.Node == null)
                    {
                        errors[ii] = StatusCodes.BadNodeIdUnknown;
                        
                        // must validate node in a seperate operation
                        handle.Index = ii;
                        nodesToValidate.Add(handle);
                        
                        continue;
                    }

                    // read the attribute value.
                    errors[ii] = handle.Node.ReadAttribute(
                        systemContext,
                        nodeToRead.AttributeId,
                        nodeToRead.ParsedIndexRange,
                        nodeToRead.DataEncoding,
                        value);
                }

                // check for nothing to do.
                if (nodesToValidate.Count == 0)
                {
                    return;
                }
            }

            // validates the nodes (reads values from the underlying data source if required).
            Read(
                systemContext,
                nodesToRead,
                values,
                errors,
                nodesToValidate,
                operationCache);
        }
Exemple #21
0
        /// <summary>
        /// Converts a list of test values to a list of DataValues.
        /// </summary>
        private SortedDictionary<DateTime, DataValue> ToDataValues(ValueType[] values)
        {
            SortedDictionary<DateTime, DataValue> dvs = new SortedDictionary<DateTime, DataValue>();

            if (values != null)
            {
                foreach (ValueType value in values)
                {
                    DataValue dv = new DataValue();
                    dv.Value = ValidateValue(value.Value);
                    dv.StatusCode = ValidateQuality(value.Quality);
                    dv.SourceTimestamp = ValidateTimestamp(value.Timestamp);
                    dv.Comment = value.Comment;
                    dvs[dv.SourceTimestamp] = dv;
                }
            }

            return dvs;
        }
        /// <summary>
        /// Reads the initial value for a monitored item.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="handle">The item handle.</param>
        /// <param name="monitoredItem">The monitored item.</param>
        protected virtual void ReadInitialValue(
            ServerSystemContext context,
            NodeHandle handle,
            MonitoredItem monitoredItem)
        {
            DataValue initialValue = new DataValue();

            initialValue.Value = null;
            initialValue.ServerTimestamp = DateTime.UtcNow;
            initialValue.SourceTimestamp = DateTime.MinValue;
            initialValue.StatusCode = StatusCodes.BadWaitingForInitialData;

            ServiceResult error = handle.Node.ReadAttribute(
                context,
                monitoredItem.AttributeId,
                monitoredItem.IndexRange,
                monitoredItem.DataEncoding,
                initialValue);

            monitoredItem.QueueValue(initialValue, error);
        }
        /// <summary>
        /// Simulates a block by updating the state of the tags belonging to the condition.
        /// </summary>
        /// <param name="counter">The number of simulation cycles that have elapsed.</param>
        /// <param name="index">The index of the block within the system.</param>
        /// <param name="generator">An object which generates random data.</param>
        public void DoSimulation(long counter, int index, Opc.Ua.Test.DataGenerator generator)
        {
            try
            {
                TagsChangedEventHandler onTagsChanged = null;
                List<UnderlyingSystemTag> snapshots = new List<UnderlyingSystemTag>();

                // update the tags.
                lock (m_tags)
                {
                    onTagsChanged = OnTagsChanged;

                    // do nothing if not monitored.
                    if (onTagsChanged == null)
                    {
                        return;
                    }

                    for (int ii = 0; ii < m_tags.Count; ii++)
                    {
                        UnderlyingSystemTag tag = m_tags[ii];
                        UpdateTagValue(tag, generator);

                        DataValue value = new DataValue();

                        value.Value = tag.Value;
                        value.StatusCode = StatusCodes.Good;
                        value.SourceTimestamp = tag.Timestamp;
                 
                        if (counter % (8 + (index%4)) == 0)
                        {
                            UpdateTagMetadata(tag, generator);
                        }

                        snapshots.Add(tag.CreateSnapshot());
                    }
                }

                // report any tag changes after releasing the lock.
                if (onTagsChanged != null)
                {
                    onTagsChanged(snapshots);
                }
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error running simulation for block {0}", m_name);
            }
        }
Exemple #24
0
        static void HistoryUpdate(Session session)
        {
            DiagnosticInfoCollection diagnosticInfos;

            // translate browse paths.
            IList<NodeOfInterest> nodeIds;

            nodeIds = GetNodeIds(session, Opc.Ua.Objects.ObjectsFolder,
                VariableBrowsePaths.ToArray());

            ExtensionObjectCollection eoc = new ExtensionObjectCollection();
            for (int ii = 0; ii < nodeIds.Count; ii++)
            {
                UpdateDataDetails updateDetails = new UpdateDataDetails();

                updateDetails.NodeId = nodeIds[ii].NodeId;
                updateDetails.PerformInsertReplace = PerformUpdateType.Update;
                updateDetails.UpdateValues = new DataValueCollection();

                for (int jj = 0; jj <= 5; jj++)
                {
                    DataValue dv = new DataValue(new Variant(jj*10), StatusCodes.Good, new DateTime(2008, 01, 01, 12, 0, jj*2));
                    updateDetails.UpdateValues.Add(dv);
                }
                ExtensionObject eo = new ExtensionObject(updateDetails.TypeId, updateDetails);
                eoc.Add(eo);
            }

            HistoryUpdateResultCollection historyUpdateResults;

            ResponseHeader responseHeader =
                session.HistoryUpdate(null, eoc, out historyUpdateResults, out diagnosticInfos);

            
            // process results.

            for (int ii = 0; ii < historyUpdateResults.Count; ii++)
            {
                HistoryUpdateResult historyUpdateResult = historyUpdateResults[ii];

                Console.WriteLine("HistoryUpdate result code for {0}:  {1}", VariableBrowsePaths[ii], historyUpdateResult.StatusCode.ToString());

                if (StatusCode.IsGood(historyUpdateResult.StatusCode))
                {
                    for (int jj = 0; jj < historyUpdateResult.OperationResults.Count; jj++)
                    {
                        Console.WriteLine("    {0}: {1}", jj, historyUpdateResult.OperationResults[jj]);
                    }
                    Console.WriteLine("");
                }
            }
        }
Exemple #25
0
 public virtual string ToString(DataValue dv)
 {
   return dv.Value.ToString();
 }
Exemple #26
0
 private static void Save(uint id, DataValue value)
 {
     lock (m_publishes)
     {
         m_publishes.Enqueue(value);
     }
 }
Exemple #27
0
        /// <summary>
        /// Reads the raw data for an item.
        /// </summary>
        private StatusCode ReadRaw(HdaHistoryReadRawModifiedRequest request)
        {
            string methodName = "IOPCHDA_SyncRead.ReadRaw";

            OPCHDA_TIME htStartTime = ConvertTime(request.StartTime);
            OPCHDA_TIME htEndTime = ConvertTime(request.EndTime);

            int maxReturnValues = request.MaxReturnValues;

            if (m_maxReturnValues > 0 && maxReturnValues > m_maxReturnValues)
            {
                maxReturnValues = m_maxReturnValues;
            }

            // must have a least two values.
            if (request.MaxReturnValues == 1 && request.TotalValuesReturned > 0)
            {
                maxReturnValues = 2;
            }

            IntPtr ppItemValues;
            IntPtr ppErrors;

            try
            {
                IOPCHDA_SyncRead server = BeginComCall<IOPCHDA_SyncRead>(methodName, true);

                server.ReadRaw(
                    ref htStartTime,
                    ref htEndTime,
                    maxReturnValues,
                    (request.ReturnBounds)?1:0,
                    1,
                    new int[] { request.ServerHandle },
                    out ppItemValues,
                    out ppErrors);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
                return StatusCodes.BadUnexpectedError;
            }
            finally
            {
                EndComCall(methodName);
            }

            // check for error.
            int[] errors = ComUtils.GetInt32s(ref ppErrors, 1, true);

            if (errors[0] < 0)
            {
                return StatusCodes.BadNodeIdUnknown;
            }

            // check if operation halted.
            request.Completed = errors[0] != ResultIds.S_MOREDATA;

            // unmarshal the results.
            OPCHDA_ITEM result = (OPCHDA_ITEM)Marshal.PtrToStructure(ppItemValues, typeof(OPCHDA_ITEM));

            if (result.dwCount > 0)
            {
                object[] values = ComUtils.GetVARIANTs(ref result.pvDataValues, result.dwCount, true);
                int[] qualities = ComUtils.GetInt32s(ref result.pdwQualities, result.dwCount, true);
                DateTime[] timestamps = ComUtils.GetDateTimes(ref result.pftTimeStamps, result.dwCount, true);

                request.Results = new DataValueCollection(result.dwCount);

                for (int ii = 0; ii < result.dwCount; ii++)
                {
                    // suppress previously returned values.
                    if (ii == 0 && request.TotalValuesReturned > 0)
                    {
                        if (request.StartTime < request.EndTime && timestamps[ii] <= request.StartTime)
                        {
                            continue;
                        }

                        if (request.StartTime > request.EndTime && timestamps[ii] >= request.StartTime)
                        {
                            continue;
                        }
                    }

                    DataValue value = new DataValue();
                    value.Value = ComUtils.ProcessComValue(values[ii]);
                    value.StatusCode = ComUtils.GetHdaQualityCode(Utils.ToUInt32(qualities[ii]));
                    value.SourceTimestamp = timestamps[ii];
                    request.Results.Add(value);
                }

                request.TotalValuesReturned += request.Results.Count;

                if (!request.Completed)
                {
                    request.StartTime = request.Results[request.Results.Count-1].SourceTimestamp;
                }
            }

            Marshal.FreeCoTaskMem(ppItemValues);

            if (result.dwCount == 0)
            {
                return StatusCodes.GoodNoData;
            }

            if (maxReturnValues > 0 && !request.Completed)
            {
                return StatusCodes.GoodMoreData;
            }

            return StatusCodes.Good;
        }
Exemple #28
0
        /// <summary>
        /// Handles change events raised by the node.
        /// </summary>
        /// <param name="context">The system context.</param>
        /// <param name="state">The node that raised the event.</param>
        /// <param name="masks">What caused the event to be raised</param>
        public void OnBufferChanged(int offset)
        {
            lock (m_dataLock)
            {
                if (m_monitoringTable != null)
                {
                    int elementOffet = (int)(offset / ElementSize);

                    MemoryBufferMonitoredItem[] monitoredItems = m_monitoringTable[elementOffet];

                    if (monitoredItems != null)
                    {
                        DataValue value = new DataValue();

                        value.WrappedValue = GetValueAtOffset(offset);
                        value.StatusCode = StatusCodes.Good;
                        value.ServerTimestamp = DateTime.UtcNow;
                        value.SourceTimestamp = m_lastScanTime;

                        for (int ii = 0; ii < monitoredItems.Length; ii++)
                        {
                            monitoredItems[ii].QueueValue(value, null);
                            m_updateCount++;
                        }
                    }
                }
            }
        }
Exemple #29
0
        /// <summary>
        /// Reads the raw data for an item.
        /// </summary>
        private StatusCode ReadProcessed(HdaHistoryReadProcessedRequest request)
        {
            string methodName = "IOPCHDA_SyncRead.ReadProcessed";

            DateTime startTime = request.StartTime;
            DateTime endTime = request.EndTime;

            // adjust the resample interval.
            if (m_maxReturnValues > 0 && request.ResampleInterval > 0)
            {
                double range = (startTime - endTime).TotalMilliseconds;
                double resampleInterval = request.ResampleInterval;

                if (Math.Abs(range/resampleInterval) > m_maxReturnValues)
                {
                    range = resampleInterval*m_maxReturnValues;

                    if (startTime > endTime)
                    {
                        range = -range;
                    }

                    endTime = startTime.AddMilliseconds(range);
                }
            }

            OPCHDA_TIME htStartTime = ConvertTime(startTime);
            OPCHDA_TIME htEndTime = ConvertTime(endTime);

            System.Runtime.InteropServices.ComTypes.FILETIME ftResampleInterval;

            ulong ticks = (ulong)request.ResampleInterval*TimeSpan.TicksPerMillisecond;
            ftResampleInterval.dwHighDateTime = (int)((0xFFFFFFFF00000000 & ticks) >> 32);
            ftResampleInterval.dwLowDateTime = (int)(ticks & 0x00000000FFFFFFFF);

            IntPtr ppItemValues;
            IntPtr ppErrors;

            try
            {
                IOPCHDA_SyncRead server = BeginComCall<IOPCHDA_SyncRead>(methodName, true);

                server.ReadProcessed(
                    ref htStartTime,
                    ref htEndTime,
                    ftResampleInterval,
                    1,
                    new int[] { request.ServerHandle },
                    new int[] { Utils.ToInt32(request.AggregateId) },
                    out ppItemValues,
                    out ppErrors);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
                return StatusCodes.BadUnexpectedError;
            }
            finally
            {
                EndComCall(methodName);
            }

            // check for error.
            int[] errors = ComUtils.GetInt32s(ref ppErrors, 1, true);

            if (errors[0] < 0)
            {
                if (errors[0] == ResultIds.E_NOT_AVAIL)
                {
                    return StatusCodes.BadAggregateNotSupported;
                }

                return StatusCodes.BadNodeIdUnknown;
            }

            // check if operation halted.
            request.Completed = endTime == request.EndTime;

            // unmarshal the results.
            OPCHDA_ITEM result = (OPCHDA_ITEM)Marshal.PtrToStructure(ppItemValues, typeof(OPCHDA_ITEM));

            if (result.dwCount > 0)
            {
                object[] values = ComUtils.GetVARIANTs(ref result.pvDataValues, result.dwCount, true);
                int[] qualities = ComUtils.GetInt32s(ref result.pdwQualities, result.dwCount, true);
                DateTime[] timestamps = ComUtils.GetDateTimes(ref result.pftTimeStamps, result.dwCount, true);

                request.Results = new DataValueCollection(result.dwCount);

                for (int ii = 0; ii < result.dwCount; ii++)
                {
                    DataValue value = new DataValue();
                    value.Value = ComUtils.ProcessComValue(values[ii]);
                    value.StatusCode = ComUtils.GetHdaQualityCode(Utils.ToUInt32(qualities[ii]));
                    value.SourceTimestamp = timestamps[ii];
                    request.Results.Add(value);
                }

                if (!request.Completed)
                {
                    request.StartTime = endTime;
                }
            }

            Marshal.FreeCoTaskMem(ppItemValues);

            if (result.dwCount == 0)
            {
                return StatusCodes.GoodNoData;
            }

            if (!request.Completed)
            {
                return StatusCodes.GoodMoreData;
            }

            return StatusCodes.Good;
        }
        /// <summary cref="IFilterTarget.GetAttributeValue" />
        public virtual object GetAttributeValue(
            FilterContext context, 
            NodeId typeDefinitionId, 
            IList<QualifiedName> relativePath, 
            uint attributeId, 
            NumericRange indexRange)
        {
            // check the type definition.
            if (!NodeId.IsNull(typeDefinitionId) && typeDefinitionId != ObjectTypes.BaseEventType)
            {
                if (!context.TypeTree.IsTypeOf(TypeDefinitionId, typeDefinitionId))
                {
                    return null;
                }
            }

            // read the child attribute.
            DataValue dataValue = new DataValue();   

            ServiceResult result = ReadChildAttribute(
                null,
                relativePath,
                0,
                attributeId,
                dataValue);
            
            if (ServiceResult.IsBad(result))
            {
                return null;
            }

            // apply any index range.
            object value = dataValue.Value;

            if (value != null)
            {
                result = indexRange.ApplyRange(ref value);
                
                if (ServiceResult.IsBad(result))
                {
                    return null;
                }
            }

            // return the result.
            return value;
        }
Exemple #31
0
        /// <summary>
        /// Reads the annotation data for an item.
        /// </summary>
        private StatusCode ReadAnnotations(HdaHistoryReadAnnotationRequest request)
        {
            string methodName = "IOPCHDA_SyncAnnotations.Read";

            OPCHDA_TIME htStartTime = ConvertTime(request.StartTime);
            OPCHDA_TIME htEndTime = ConvertTime(request.EndTime);

            IntPtr ppAnnotationValues;
            IntPtr ppErrors;

            try
            {
                IOPCHDA_SyncAnnotations server = BeginComCall<IOPCHDA_SyncAnnotations>(methodName, true);

                server.Read(
                    ref htStartTime,
                    ref htEndTime,
                    1,
                    new int[] { request.ServerHandle },
                    out ppAnnotationValues,
                    out ppErrors);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
                return StatusCodes.BadUnexpectedError;
            }
            finally
            {
                EndComCall(methodName);
            }

            // check for error.
            int[] errors = ComUtils.GetInt32s(ref ppErrors, 1, true);

            if (errors[0] < 0)
            {
                return StatusCodes.BadNodeIdUnknown;
            }

            // unmarshal the results.
            OPCHDA_ANNOTATION result = (OPCHDA_ANNOTATION)Marshal.PtrToStructure(ppAnnotationValues, typeof(OPCHDA_ANNOTATION));

            if (result.dwNumValues > 0)
            {
                DateTime[] timestamps = ComUtils.GetDateTimes(ref result.ftTimeStamps, result.dwNumValues, true);
                string[] annotations = ComUtils.GetUnicodeStrings(ref result.szAnnotation, result.dwNumValues, true);
                DateTime[] annotationTimes = ComUtils.GetDateTimes(ref result.ftAnnotationTime, result.dwNumValues, true);
                string[] userNames = ComUtils.GetUnicodeStrings(ref result.szUser, result.dwNumValues, true);

                request.Annotations = new List<DataValue>(result.dwNumValues);

                for (int ii = 0; ii < result.dwNumValues; ii++)
                {
                    Annotation annotation = new Annotation();
                    annotation.AnnotationTime = annotationTimes[ii];
                    annotation.Message = annotations[ii];
                    annotation.UserName = userNames[ii];

                    DataValue value = new DataValue(new Variant(new ExtensionObject(annotation)));
                    value.SourceTimestamp = timestamps[ii];
                    request.Annotations.Add(value);
                }
            }

            Marshal.FreeCoTaskMem(ppAnnotationValues);

            return StatusCodes.Good;
        }
Exemple #32
0
        /// <summary>
        /// Checks if the value is good according to the configuration rules.
        /// </summary>
        /// <param name="value">The value to test.</param>
        /// <returns>True if the value is good.</returns>
        public bool IsGood(DataValue value)
        {
            if (value == null)
            {
                return false;
            }

            if (m_configuration.TreatUncertainAsBad)
            {
                if (StatusCode.IsNotGood(value.StatusCode))
                {
                    return false;
                }
            }
            else
            {
                if (StatusCode.IsBad(value.StatusCode))
                {
                    return false;
                }
            }

            return true;
        }