Пример #1
0
 /// <summary>
 /// Reads the data at the specified time for an item.
 /// </summary>
 protected override void HistoryReadAtTime(
     UaServerContext context,
     ReadAtTimeDetails details,
     TimestampsToReturn timestampsToReturn,
     IList <HistoryReadValueId> nodesToRead,
     IList <HistoryReadResult> results,
     IList <ServiceResult> errors,
     List <UaNodeHandle> nodesToProcess,
     IDictionary <NodeId, NodeState> cache)
 {
     throw new NotImplementedException();
 }
Пример #2
0
        /// <summary>
        /// Fetches the recent history.
        /// </summary>
        private void ReadAtTime()
        {
            ReadAtTimeDetails details = new ReadAtTimeDetails();

            // generate times
            DateTime startTime = StartTimeDP.Value.ToUniversalTime();

            for (int ii = 0; ii < MaxReturnValuesNP.Value; ii++)
            {
                details.ReqTimes.Add(startTime.AddMilliseconds((double)(ii * TimeStepNP.Value)));
            }

            HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();
            HistoryReadValueId           nodeToRead  = new HistoryReadValueId();

            nodeToRead.NodeId = m_nodeId;
            nodesToRead.Add(nodeToRead);

            HistoryReadResultCollection results         = null;
            DiagnosticInfoCollection    diagnosticInfos = null;

            m_session.HistoryRead(
                null,
                new ExtensionObject(details),
                TimestampsToReturn.Both,
                false,
                nodesToRead,
                out results,
                out diagnosticInfos);

            ClientBase.ValidateResponse(results, nodesToRead);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);

            if (StatusCode.IsBad(results[0].StatusCode))
            {
                throw new ServiceResultException(results[0].StatusCode);
            }

            HistoryData values = ExtensionObject.ToEncodeable(results[0].HistoryData) as HistoryData;

            DisplayResults(values);

            // save any continuation point.
            SaveContinuationPoint(details, nodeToRead, results[0].ContinuationPoint);
        }
 /// <summary>
 /// Reads the history for the variable value.
 /// </summary>
 protected virtual ServiceResult HistoryReadAtTime(
     ISystemContext context, 
     BaseVariableState      source,
     ReadAtTimeDetails      details, 
     TimestampsToReturn     timestampsToReturn, 
     bool                   releaseContinuationPoints, 
     HistoryReadValueId     nodeToRead, 
     HistoryReadResult      result)
 {
     return StatusCodes.BadHistoryOperationUnsupported;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HdaHistoryReadRawModifiedRequest"/> class.
 /// </summary>
 /// <param name="itemId">The item id.</param>
 /// <param name="details">The details.</param>
 /// <param name="nodeToRead">The node to read.</param>
 public HdaHistoryReadAtTimeRequest(string itemId, ReadAtTimeDetails details, HistoryReadValueId nodeToRead)
     :
     base(itemId, details, nodeToRead)
 {
     ReqTimes = details.ReqTimes;
 }
Пример #5
0
        /// <summary>
        /// Reads the history of an HDA item.
        /// </summary>
        private ServiceResult HistoryReadAtTime(
            ServerSystemContext context,
            ComHdaClient client,
            ReadAtTimeDetails details,
            TimestampsToReturn timestampsToReturn,
            HistoryReadValueId nodeToRead,
            HdaParsedNodeId parsedNodeId,
            HistoryReadResult result)
        {
            // create the request or load it from a continuation point.
            HdaHistoryReadAtTimeRequest request = null;

            if (nodeToRead.ContinuationPoint == null)
            {
                request = new HdaHistoryReadAtTimeRequest(parsedNodeId.RootId, details, nodeToRead);
            }
            else
            {
                request = LoadContinuationPoint(context, nodeToRead.ContinuationPoint) as HdaHistoryReadAtTimeRequest;

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

            // fetch the data.
            result.StatusCode = client.ReadHistory(request);

            // fill in the results.
            if (request.Results != null)
            {
                HistoryData data = new HistoryData();
                data.DataValues = request.Results;
                result.HistoryData = new ExtensionObject(data);
            }

            // create a new continuation point.
            if (!request.Completed)
            {
                result.ContinuationPoint = SaveContinuationPoint(context, request);
            }

            return result.StatusCode;
        }
Пример #6
0
        /// <summary>
        /// Reads processed history data.
        /// </summary>
        protected override void HistoryReadAtTime(
            ServerSystemContext context,
            ReadAtTimeDetails details,
            TimestampsToReturn timestampsToReturn,
            IList<HistoryReadValueId> nodesToRead,
            IList<HistoryReadResult> results,
            IList<ServiceResult> errors,
            List<NodeHandle> nodesToProcess,
            IDictionary<NodeId, NodeState> cache)
        {
            ComHdaClientManager system = (ComHdaClientManager)this.SystemContext.SystemHandle;
            ComHdaClient client = (ComHdaClient)system.SelectClient((ServerSystemContext)SystemContext, false);

            for (int ii = 0; ii < nodesToProcess.Count; ii++)
            {
                NodeHandle handle = nodesToProcess[ii];
                HistoryReadValueId nodeToRead = nodesToRead[handle.Index];
                HistoryReadResult result = results[handle.Index];

                // check if the node id has been parsed.
                HdaParsedNodeId parsedNodeId = handle.ParsedNodeId as HdaParsedNodeId;

                if (parsedNodeId == null)
                {
                    errors[handle.Index] = StatusCodes.BadNodeIdInvalid;
                    continue;
                }

                // read the history of an item.
                if (parsedNodeId.RootType == HdaModelUtils.HdaItem)
                {
                    errors[handle.Index] = HistoryReadAtTime(
                        context,
                        client,
                        details,
                        timestampsToReturn,
                        nodeToRead,
                        parsedNodeId,
                        result);

                    continue;
                }

                errors[handle.Index] = StatusCodes.BadHistoryOperationUnsupported;
            }
        }
Пример #7
0
        /// <summary>
        /// Reads the history of values for a set of variables at given time.
        /// </summary>
        static void HistoryReadAtTime(Session session)
        {
            // translate browse paths.
            IList<NodeOfInterest> nodeIds = GetNodeIds(session, Opc.Ua.Objects.ObjectsFolder, 
                VariableBrowsePaths.ToArray());


            DiagnosticInfoCollection diagnosticInfos;

            ReadAtTimeDetails readDetails = new ReadAtTimeDetails();

            readDetails.ReqTimes = new DateTimeCollection();

            for (int jj = 0; jj < 10; jj++)
            {
                readDetails.ReqTimes.Add(new DateTime(2008, 01, 01, 12, 0, jj));
                readDetails.ReqTimes.Add(new DateTime(2008, 01, 01, 12, 0, jj, (int) 500));
            }

            ExtensionObject eo = new ExtensionObject(readDetails.TypeId, readDetails);

            HistoryReadValueIdCollection idCollection = new HistoryReadValueIdCollection();
            for (int ii = 0; ii < nodeIds.Count; ii++)
            {
                HistoryReadValueId readValueId = new HistoryReadValueId();
                readValueId.NodeId = nodeIds[ii].NodeId;
                readValueId.Processed = false;
                idCollection.Add(readValueId);
            }

            HistoryReadResultCollection historyReadResults;

            ResponseHeader responseHeader =
                session.HistoryRead(null, eo, TimestampsToReturn.Both, true,
                idCollection, out historyReadResults, out diagnosticInfos);

            // process results.

            for (int ii = 0; ii < historyReadResults.Count; ii++)
            {
                HistoryReadResult historyReadResult = historyReadResults[ii];
                HistoryData historyData = null;
                DataValueCollection dataValues = null;
                if (historyReadResult.HistoryData != null)
                {
                    historyData = ExtensionObject.ToEncodeable(historyReadResult.HistoryData) as HistoryData;
                    dataValues = historyData.DataValues;
                }

                ServiceResult result = Session.GetResult(historyReadResult.StatusCode, ii, diagnosticInfos, responseHeader);
                Console.WriteLine("HistoryRead result code for {0}:  {1}", VariableBrowsePaths[ii], result.StatusCode.ToString());

                if (StatusCode.IsBad(historyReadResult.StatusCode))
                {
                    continue;
                }

                if (dataValues == null)
                {
                    Console.WriteLine("dataValues == null");
                    continue;
                }

                for (int jj = 0; jj < dataValues.Count; jj++)
                {

                    DataValue dataValue = dataValues[jj];

                    // write value.
                    Console.WriteLine("{0}: V={1}, Q={2}, SrvT={3}, SrcT={4}", jj,
                        dataValue.Value == null ? "null" : dataValue.Value.ToString(),
                        dataValue.StatusCode.ToString(),
                        dataValue.ServerTimestamp, dataValue.SourceTimestamp);
                }
            }
        }
        /// <summary>
        /// Reads history data at specified times.
        /// </summary>
        protected virtual void HistoryReadAtTime(
            ServerSystemContext context,
            ReadAtTimeDetails details,
            TimestampsToReturn timestampsToReturn,
            IList<HistoryReadValueId> nodesToRead,
            IList<HistoryReadResult> results,
            IList<ServiceResult> errors,
            List<NodeHandle> nodesToProcess,
            IDictionary<NodeId, NodeState> cache)
        {
            for (int ii = 0; ii < nodesToProcess.Count; ii++)
            {
                NodeHandle handle = nodesToProcess[ii];

                // validate node.
                NodeState source = ValidateNode(context, handle, cache);

                if (source == null)
                {
                    continue;
                }

                errors[handle.Index] = StatusCodes.BadHistoryOperationUnsupported;
            }
        }
Пример #9
0
        /// <summary>
        /// Reads the history of values for a set of variables at given time.
        /// </summary>
        static void HistoryReadAtTime(Session session)
        {
            // translate browse paths.
            IList <NodeOfInterest> nodeIds = GetNodeIds(session, Opc.Ua.Objects.ObjectsFolder,
                                                        VariableBrowsePaths.ToArray());


            DiagnosticInfoCollection diagnosticInfos;

            ReadAtTimeDetails readDetails = new ReadAtTimeDetails();

            readDetails.ReqTimes = new DateTimeCollection();

            for (int jj = 0; jj < 10; jj++)
            {
                readDetails.ReqTimes.Add(new DateTime(2008, 01, 01, 12, 0, jj));
                readDetails.ReqTimes.Add(new DateTime(2008, 01, 01, 12, 0, jj, (int)500));
            }

            ExtensionObject eo = new ExtensionObject(readDetails.TypeId, readDetails);

            HistoryReadValueIdCollection idCollection = new HistoryReadValueIdCollection();

            for (int ii = 0; ii < nodeIds.Count; ii++)
            {
                HistoryReadValueId readValueId = new HistoryReadValueId();
                readValueId.NodeId    = nodeIds[ii].NodeId;
                readValueId.Processed = false;
                idCollection.Add(readValueId);
            }

            HistoryReadResultCollection historyReadResults;

            ResponseHeader responseHeader =
                session.HistoryRead(null, eo, TimestampsToReturn.Both, true,
                                    idCollection, out historyReadResults, out diagnosticInfos);

            // process results.

            for (int ii = 0; ii < historyReadResults.Count; ii++)
            {
                HistoryReadResult   historyReadResult = historyReadResults[ii];
                HistoryData         historyData       = null;
                DataValueCollection dataValues        = null;
                if (historyReadResult.HistoryData != null)
                {
                    historyData = ExtensionObject.ToEncodeable(historyReadResult.HistoryData) as HistoryData;
                    dataValues  = historyData.DataValues;
                }

                ServiceResult result = Session.GetResult(historyReadResult.StatusCode, ii, diagnosticInfos, responseHeader);
                Console.WriteLine("HistoryRead result code for {0}:  {1}", VariableBrowsePaths[ii], result.StatusCode.ToString());

                if (StatusCode.IsBad(historyReadResult.StatusCode))
                {
                    continue;
                }

                if (dataValues == null)
                {
                    Console.WriteLine("dataValues == null");
                    continue;
                }

                for (int jj = 0; jj < dataValues.Count; jj++)
                {
                    DataValue dataValue = dataValues[jj];

                    // write value.
                    Console.WriteLine("{0}: V={1}, Q={2}, SrvT={3}, SrcT={4}", jj,
                                      dataValue.Value == null ? "null" : dataValue.Value.ToString(),
                                      dataValue.StatusCode.ToString(),
                                      dataValue.ServerTimestamp, dataValue.SourceTimestamp);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Creates the read requests.
        /// </summary>
        private List<HdaReadRequest> CreateReadRequests(
            Session session,
            DateTime[] timestamps,
            int[] serverHandles, 
            ReadAtTimeDetails details)
        {
            if (m_configuration.MaxReturnValues > 0 && timestamps.Length > m_configuration.MaxReturnValues)
            {
                throw ComUtils.CreateComException(ResultIds.E_MAXEXCEEDED);
            }

            details.ReqTimes.AddRange(timestamps);

            // build the list of requests.
            List<HdaReadRequest> requests = new List<HdaReadRequest>();

            for (int ii = 0; ii < serverHandles.Length; ii++)
            {
                HdaReadRequest request = new HdaReadRequest();
                requests.Add(request);

                // look up server handle.
                request.Handle = m_itemManager.LookupHandle(serverHandles[ii]);

                if (request.Handle == null)
                {
                    request.Error = ResultIds.E_INVALIDHANDLE;
                    continue;
                }
                
                // set node id to use.
                request.NodeId = request.Handle.NodeId;
                request.ClientHandle = request.Handle.ClientHandle;
            }

            return requests;
        }
Пример #11
0
        /// <summary>
        /// Reads the data at the specified times.
        /// </summary>
        public int[] ReadAtTime(
            int transactionId,
            DateTime[] timestamps,
            int[] serverHandles,
            out int cancelId)
        {
            Session session = ThrowIfNotConnected();

            // create the read requests.
            ReadAtTimeDetails details = new ReadAtTimeDetails();

            List<HdaReadRequest> requests = CreateReadRequests(
                session,
                timestamps,
                serverHandles,
                details);

            // queue the transaction.
            int[] errors = CreateTransaction(
                TransationType.Read,
                transactionId, 
                new ExtensionObject(details),
                requests,
                false,
                out cancelId);

            // return the initial results.
            return errors;
        }
Пример #12
0
        /// <summary>
        /// Reads the data at the specified times.
        /// </summary>
        public List<HdaReadRequest> ReadAtTime(
            DateTime[] timestamps,
            int[] serverHandles)
        {
            Session session = ThrowIfNotConnected();
            
            // create the read requests.
            ReadAtTimeDetails details = new ReadAtTimeDetails();

            List<HdaReadRequest> requests = CreateReadRequests(
                session,
                timestamps,
                serverHandles,
                details);

            ExtensionObject extension = new ExtensionObject(details);

            // fetch all of the values.
            if (ReadNext(session, extension, requests, false))
            {
                ReadNext(session, extension, requests, true);
            }
            
            return requests;
        }
Пример #13
0
        /// <summary>
        /// Fetches the recent history.
        /// </summary>
        private void ReadAtTime()
        {
            ReadAtTimeDetails details = new ReadAtTimeDetails();
            
            // generate times
            DateTime startTime = StartTimeDP.Value.ToUniversalTime();

            for (int ii = 0; ii < MaxReturnValuesNP.Value; ii++)
            {
                details.ReqTimes.Add(startTime.AddMilliseconds((double)(ii*TimeStepNP.Value)));
            }

            HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();
            HistoryReadValueId nodeToRead = new HistoryReadValueId();
            nodeToRead.NodeId = m_nodeId;
            nodesToRead.Add(nodeToRead);

            HistoryReadResultCollection results = null;
            DiagnosticInfoCollection diagnosticInfos = null;

            m_session.HistoryRead(
                null,
                new ExtensionObject(details),
                TimestampsToReturn.Both,
                false,
                nodesToRead,
                out results,
                out diagnosticInfos);

            ClientBase.ValidateResponse(results, nodesToRead);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);

            if (StatusCode.IsBad(results[0].StatusCode))
            {
                throw new ServiceResultException(results[0].StatusCode);
            }

            HistoryData values = ExtensionObject.ToEncodeable(results[0].HistoryData) as HistoryData;
            DisplayResults(values);

            // save any continuation point.
            SaveContinuationPoint(details, nodeToRead, results[0].ContinuationPoint);
        }
        /// <summary>
        /// Reads the data at the specified time for an item.
        /// </summary>
        protected override void HistoryReadAtTime(
            ServerSystemContext context,
            ReadAtTimeDetails details,
            TimestampsToReturn timestampsToReturn,
            IList<HistoryReadValueId> nodesToRead,
            IList<HistoryReadResult> results,
            IList<ServiceResult> errors,
            List<NodeHandle> nodesToProcess,
            IDictionary<NodeId, NodeState> cache)
        {
            for (int ii = 0; ii < nodesToRead.Count; ii++)
            {
                NodeHandle handle = nodesToProcess[ii];
                HistoryReadValueId nodeToRead = nodesToRead[handle.Index];
                HistoryReadResult result = results[handle.Index];

                HistoryReadRequest request = null;
                
                try
                {
                    // validate node.
                    NodeState source = ValidateNode(context, handle, cache);

                    if (source == null)
                    {
                        continue;
                    }

                    // load an exising request.
                    if (nodeToRead.ContinuationPoint != null)
                    {
                        request = LoadContinuationPoint(context, nodeToRead.ContinuationPoint);

                        if (request == null)
                        {
                            errors[handle.Index] = StatusCodes.BadContinuationPointInvalid;
                            continue;
                        }
                    }

                    // create a new request.
                    else
                    {
                        request = CreateHistoryReadRequest(
                            context,
                            details,
                            handle,
                            nodeToRead);
                    }

                    // process values until the max is reached.
                    HistoryData data = new HistoryData();

                    while (request.NumValuesPerNode == 0 || data.DataValues.Count < request.NumValuesPerNode)
                    {
                        if (request.Values.Count == 0)
                        {
                            break;
                        }

                        DataValue value = request.Values.First.Value;
                        request.Values.RemoveFirst();
                        data.DataValues.Add(value);
                    }

                    errors[handle.Index] = ServiceResult.Good;

                    // check if a continuation point is requred.
                    if (request.Values.Count > 0)
                    {
                        result.ContinuationPoint = SaveContinuationPoint(context, request);
                    }

                    // check if no data returned.
                    else
                    {
                        errors[handle.Index] = StatusCodes.GoodNoData;
                    }

                    // return the data.
                    result.HistoryData = new ExtensionObject(data);
                }
                catch (Exception e)
                {
                    errors[handle.Index] = ServiceResult.Create(e, StatusCodes.BadUnexpectedError, "Unexpected error processing request.");
                }
            }
        }
        /// <summary>
        /// Creates a new history request.
        /// </summary>
        private HistoryReadRequest CreateHistoryReadRequest(
            ServerSystemContext context,
            ReadAtTimeDetails details,
            NodeHandle handle,
            HistoryReadValueId nodeToRead)
        {
            bool applyIndexRangeOrEncoding = (nodeToRead.ParsedIndexRange != NumericRange.Empty || !QualifiedName.IsNull(nodeToRead.DataEncoding));

            ArchiveItemState item = handle.Node as ArchiveItemState;

            if (item == null)
            {
                throw new ServiceResultException(StatusCodes.BadNotSupported);
            }

            item.ReloadFromSource(context);

            // find the start and end times.
            DateTime startTime = DateTime.MaxValue;
            DateTime endTime = DateTime.MinValue;

            for (int ii = 0; ii < details.ReqTimes.Count; ii++)
            {
                if (startTime > details.ReqTimes[ii])
                {
                    startTime = details.ReqTimes[ii];
                }

                if (endTime < details.ReqTimes[ii])
                {
                    endTime = details.ReqTimes[ii];
                }
            }
            
            DataView view = item.ReadHistory(startTime, endTime, false);

            LinkedList<DataValue> values = new LinkedList<DataValue>();

            for (int ii = 0; ii < details.ReqTimes.Count; ii++)
            {
                bool dataBeforeIgnored = false;
                bool dataAfterIgnored = false;

                // find the value at the time.
                int index = item.FindValueAtOrBefore(view, details.ReqTimes[ii], !details.UseSimpleBounds, out dataBeforeIgnored);

                if (index < 0)
                {
                    values.AddLast(new DataValue(StatusCodes.BadNoData, details.ReqTimes[ii]));
                    continue;
                }

                // nothing more to do if a raw value exists.
                if ((DateTime)view[index].Row[0] == details.ReqTimes[ii])
                {
                    values.AddLast((DataValue)view[index].Row[2]);
                    continue;
                }
                
                DataValue before = (DataValue)view[index].Row[2];
                DataValue value;

                // find the value after the time.
                int afterIndex = item.FindValueAfter(view, index, !details.UseSimpleBounds, out dataAfterIgnored);

                if (afterIndex < 0)
                {
                    // use stepped interpolation if no end bound exists.
                    value = AggregateCalculator.SteppedInterpolate(details.ReqTimes[ii], before);

                    if (StatusCode.IsNotBad(value.StatusCode) && dataBeforeIgnored)
                    {
                        value.StatusCode = value.StatusCode.SetCodeBits(StatusCodes.UncertainDataSubNormal);
                    }

                    values.AddLast(value);
                    continue;
                }

                // use stepped or slopped interpolation depending on the value.
                if (item.ArchiveItem.Stepped)
                {
                    value = AggregateCalculator.SteppedInterpolate(details.ReqTimes[ii], before);

                    if (StatusCode.IsNotBad(value.StatusCode) && dataBeforeIgnored)
                    {
                        value.StatusCode = value.StatusCode.SetCodeBits(StatusCodes.UncertainDataSubNormal);
                    }
                }
                else
                {
                    value = AggregateCalculator.SlopedInterpolate(details.ReqTimes[ii], before, (DataValue)view[afterIndex].Row[2]);

                    if (StatusCode.IsNotBad(value.StatusCode) && (dataBeforeIgnored || dataAfterIgnored))
                    {
                        value.StatusCode = value.StatusCode.SetCodeBits(StatusCodes.UncertainDataSubNormal);
                    }
                }

                values.AddLast(value);
            }

            HistoryReadRequest request = new HistoryReadRequest();
            request.Values = values;
            request.NumValuesPerNode = 0;
            request.Filter = null;
            return request;
        }