コード例 #1
0
        /// <summary>
        /// Releases any continuation points.
        /// </summary>
        private void ReleaseContinuationPoints()
        {
            if (m_details != null)
            {
                HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();
                nodesToRead.Add(m_nodeToRead);

                HistoryReadResultCollection results         = null;
                DiagnosticInfoCollection    diagnosticInfos = null;

                m_session.HistoryRead(
                    null,
                    new ExtensionObject(m_details),
                    TimestampsToReturn.Neither,
                    true,
                    nodesToRead,
                    out results,
                    out diagnosticInfos);

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

                NextBTN.Visible = false;
                StopBTN.Enabled = false;
                GoBTN.Visible   = true;
                m_details       = null;
                m_nodeToRead    = null;
            }
        }
コード例 #2
0
        /// <summary>
        /// Continues a read operation.
        /// </summary>
        private void ReadNext(ReadEventDetails details, HistoryReadValueId nodeToRead)
        {
            HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();

            nodesToRead.Add(nodeToRead);

            HistoryReadResultCollection results         = null;
            DiagnosticInfoCollection    diagnosticInfos = null;

            ResponseHeader responseHeader = m_session.HistoryRead(
                null,
                new ExtensionObject(details),
                TimestampsToReturn.Neither,
                false,
                nodesToRead,
                out results,
                out diagnosticInfos);

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

            if (StatusCode.IsBad(results[0].StatusCode))
            {
                throw ServiceResultException.Create(results[0].StatusCode, 0, diagnosticInfos, responseHeader.StringTable);
            }

            // display results.
            HistoryEvent data = ExtensionObject.ToEncodeable(results[0].HistoryData) as HistoryEvent;

            ResultsLV.AddEventHistory(data);

            // check if a continuation point exists.
            if (results[0].ContinuationPoint != null && results[0].ContinuationPoint.Length > 0)
            {
                nodeToRead.ContinuationPoint = results[0].ContinuationPoint;

                NextBTN.Visible = true;
                StopBTN.Enabled = true;
                GoBTN.Visible   = false;
                m_details       = details;
                m_nodeToRead    = nodeToRead;
            }

            // all done.
            else
            {
                NextBTN.Visible = false;
                StopBTN.Enabled = false;
                GoBTN.Visible   = true;
                m_details       = null;
                m_nodeToRead    = null;
            }
        }
コード例 #3
0
        /// <summary>
        /// Saves a continuation point for later use.
        /// </summary>
        private void SaveContinuationPoint(HistoryReadDetails details, HistoryReadValueId nodeToRead, byte[] continuationPoint)
        {
            // clear existing continuation point.
            if (m_nodeToContinue != null)
            {
                HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();
                nodesToRead.Add(m_nodeToContinue);

                HistoryReadResultCollection results         = null;
                DiagnosticInfoCollection    diagnosticInfos = null;

                m_session.HistoryRead(
                    null,
                    new ExtensionObject(m_details),
                    TimestampsToReturn.Neither,
                    true,
                    nodesToRead,
                    out results,
                    out diagnosticInfos);

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

            m_details        = null;
            m_nodeToContinue = null;

            // save new continutation point.
            if (continuationPoint != null && continuationPoint.Length > 0)
            {
                m_details        = details;
                m_nodeToContinue = nodeToRead;
                m_nodeToContinue.ContinuationPoint = continuationPoint;
            }

            // update controls.
            if (m_nodeToContinue != null)
            {
                GoBTN.Visible   = false;
                NextBTN.Visible = true;
                NextBTN.Enabled = true;
                StopBTN.Enabled = true;
            }
            else
            {
                GoBTN.Visible   = true;
                GoBTN.Enabled   = true;
                NextBTN.Visible = false;
                StopBTN.Enabled = false;
            }
        }
コード例 #4
0
        /// <summary>
        /// Fetches the recent history.
        /// </summary>
        private void ReadHistory(ReadEventDetails details, NodeId areaId)
        {
            HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();
            HistoryReadValueId           nodeToRead  = new HistoryReadValueId();

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

            HistoryReadResultCollection results         = null;
            DiagnosticInfoCollection    diagnosticInfos = null;

            m_session.HistoryRead(
                null,
                new ExtensionObject(details),
                TimestampsToReturn.Neither,
                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);
            }

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

            foreach (HistoryEventFieldList e in events.Events)
            {
                DisplayEvent(e.EventFields);
            }

            // release continuation points.
            if (results[0].ContinuationPoint != null && results[0].ContinuationPoint.Length > 0)
            {
                nodeToRead.ContinuationPoint = results[0].ContinuationPoint;

                m_session.HistoryRead(
                    null,
                    new ExtensionObject(details),
                    TimestampsToReturn.Neither,
                    true,
                    nodesToRead,
                    out results,
                    out diagnosticInfos);
            }
        }
コード例 #5
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);
        }
コード例 #6
0
        /// <summary>
        /// Fetches the recent history.
        /// </summary>
        private void ReadProcessed()
        {
            AvailableAggregate aggregate = (AvailableAggregate)AggregateCB.SelectedItem;

            ReadProcessedDetails details = new ReadProcessedDetails();

            details.StartTime          = StartTimeDP.Value.ToUniversalTime();
            details.EndTime            = EndTimeDP.Value.ToUniversalTime();
            details.ProcessingInterval = (double)ResampleIntervalNP.Value;
            details.AggregateType.Add(aggregate.NodeId);
            details.AggregateConfiguration.UseServerCapabilitiesDefaults = true;

            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);
        }
コード例 #7
0
        /// <summary>
        /// Invokes the HistoryRead service.
        /// </summary>
        public virtual ResponseHeader HistoryRead(
            RequestHeader requestHeader,
            ExtensionObject historyReadDetails,
            TimestampsToReturn timestampsToReturn,
            bool releaseContinuationPoints,
            HistoryReadValueIdCollection nodesToRead,
            out HistoryReadResultCollection results,
            out DiagnosticInfoCollection diagnosticInfos)
        {
            results         = null;
            diagnosticInfos = null;

            ValidateRequest(requestHeader);

            // Insert implementation.

            return(CreateResponse(requestHeader, StatusCodes.BadServiceUnsupported));
        }
コード例 #8
0
        /// <summary>
        /// Fetches the recent history.
        /// </summary>
        private void ReadRaw(bool isReadModified)
        {
            ReadRawModifiedDetails details = new ReadRawModifiedDetails();

            details.StartTime        = (StartTimeCK.Checked)?StartTimeDP.Value.ToUniversalTime():DateTime.MinValue;
            details.EndTime          = (EndTimeCK.Checked)?EndTimeDP.Value.ToUniversalTime():DateTime.MinValue;
            details.NumValuesPerNode = (MaxReturnValuesCK.Checked)?(uint)MaxReturnValuesNP.Value:0;
            details.IsReadModified   = isReadModified;
            details.ReturnBounds     = (isReadModified)?false:ReturnBoundsCK.Checked;

            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);
        }
コード例 #9
0
        public void HistoryRead(bool eventDetails)
        {
            HistoryReadResultCollection results         = null;
            DiagnosticInfoCollection    diagnosticInfos = null;

            // there are no historizing nodes, but create some real ones
            var testSet = GetTestSetSimulation(Session.NamespaceUris);
            HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection(
                testSet.Select(nodeId => new HistoryReadValueId {
                NodeId = nodeId
            }));

            var responseHeader = Session.HistoryRead(
                null,
                eventDetails ? ReadEventDetails() : ReadRawModifiedDetails(),
                TimestampsToReturn.Source,
                false,
                nodesToRead,
                out results,
                out diagnosticInfos);

            Session.ValidateResponse(results, nodesToRead);
            Session.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
        }
コード例 #10
0
ファイル: ReadHistoryDlg.cs プロジェクト: neobox3000/UA-.NET
        private void ReleaseContinuationPoints()
        {
            ReadRawModifiedDetails details = new ReadRawModifiedDetails();

            HistoryReadValueId nodeToRead = new HistoryReadValueId();

            nodeToRead.NodeId = m_nodeId;

            if (m_result != null)
            {
                nodeToRead.ContinuationPoint = m_result.ContinuationPoint;
            }

            HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();

            nodesToRead.Add(nodeToRead);

            HistoryReadResultCollection results         = null;
            DiagnosticInfoCollection    diagnosticInfos = null;

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

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

            m_result = null;

            ShowResults();
        }
コード例 #11
0
        /// <summary>
        /// Invokes the HistoryRead service.
        /// </summary>
        /// <param name="requestHeader">The request header.</param>
        /// <param name="historyReadDetails">The history read details.</param>
        /// <param name="timestampsToReturn">The timestamps to return.</param>
        /// <param name="releaseContinuationPoints">if set to <c>true</c> continuation points are released.</param>
        /// <param name="nodesToRead">The nodes to read.</param>
        /// <param name="results">The results.</param>
        /// <param name="diagnosticInfos">The diagnostic information for the results.</param>
        /// <returns>
        /// Returns a <see cref="ResponseHeader"/> object
        /// </returns>
        public override ResponseHeader HistoryRead(
            RequestHeader                   requestHeader, 
            ExtensionObject                 historyReadDetails, 
            TimestampsToReturn              timestampsToReturn, 
            bool                            releaseContinuationPoints, 
            HistoryReadValueIdCollection    nodesToRead, 
            out HistoryReadResultCollection results, 
            out DiagnosticInfoCollection    diagnosticInfos)
        {
            OperationContext context = ValidateRequest(requestHeader, RequestType.HistoryRead);
            
            try
            {
                if (nodesToRead == null || nodesToRead.Count == 0)
                {            
                    throw new ServiceResultException(StatusCodes.BadNothingToDo);
                }

                m_serverInternal.NodeManager.HistoryRead(
                    context,
                    historyReadDetails,
                    timestampsToReturn,
                    releaseContinuationPoints,
                    nodesToRead,
                    out results,
                    out diagnosticInfos);            

                return CreateResponse(requestHeader, context.StringTable);   
            }
            catch (ServiceResultException e)
            {
                lock (ServerInternal.DiagnosticsLock)
                {
                    ServerInternal.ServerDiagnostics.RejectedRequestsCount++;

                    if (IsSecurityError(e.StatusCode))
                    {
                        ServerInternal.ServerDiagnostics.SecurityRejectedRequestsCount++;
                    }
                }

                throw TranslateException(context, e);
            }  
            finally
            {
                OnRequestComplete(context);
            } 
        }
コード例 #12
0
        public static void GetData(TimeSeriesBlock tsb)
        {
            if (session != null)
            {
                ReadRawModifiedDetails details = new ReadRawModifiedDetails();
                details.StartTime        = startTime;
                details.EndTime          = endTime;
                details.NumValuesPerNode = 0;
                details.IsReadModified   = false;
                details.ReturnBounds     = true;

                var nodesToRead = new HistoryReadValueIdCollection();
                for (int i = 0; i < tsb.opcNodes.Count; i++)
                {
                    var      nodeToRead = new HistoryReadValueId();
                    string[] split      = tsb.opcNodes[i].Split(',');
                    nodeToRead.NodeId = new NodeId(split[1], (ushort)Convert.ToInt32(split[0]));
                    nodesToRead.Add(nodeToRead);
                }

                table = new List <List <object> >();

                HistoryReadResultCollection results         = null;
                DiagnosticInfoCollection    diagnosticInfos = null;

                bool loop = true;
                while (loop)
                {
                    session.HistoryRead(
                        null,
                        new ExtensionObject(details),
                        TimestampsToReturn.Both,
                        false,
                        nodesToRead,
                        out results,
                        out diagnosticInfos);

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

                    foreach (var res in results)
                    {
                        if (StatusCode.IsBad(res.StatusCode))
                        {
                            throw new ServiceResultException(res.StatusCode);
                        }
                    }

                    var historyData1 = ExtensionObject.ToEncodeable(results[0].HistoryData) as HistoryData;
                    var historyData2 = ExtensionObject.ToEncodeable(results[1].HistoryData) as HistoryData;
                    for (int i = 0; i < historyData1.DataValues.Count; i++)
                    {
                        var row = new List <object>();
                        row.Add(historyData1.DataValues[i].SourceTimestamp);
                        row.Add(historyData1.DataValues[i].Value);
                        row.Add(historyData2.DataValues[i].Value);
                        table.Add(row);
                    }

                    for (int i = 0; i < results.Count; i++)
                    {
                        if (results[i].ContinuationPoint == null || results[i].ContinuationPoint.Length == 0)
                        {
                            loop = false;
                            break;
                        }
                        nodesToRead[i].ContinuationPoint = results[i].ContinuationPoint;
                    }
                }
            }
        }
コード例 #13
0
ファイル: Opc.Ua.Client.cs プロジェクト: zryska/UA-.NET
        /// <summary>
        /// Invokes the HistoryRead service.
        /// </summary>
        public virtual ResponseHeader HistoryRead(
            RequestHeader                   requestHeader,
            ExtensionObject                 historyReadDetails,
            TimestampsToReturn              timestampsToReturn,
            bool                            releaseContinuationPoints,
            HistoryReadValueIdCollection    nodesToRead,
            out HistoryReadResultCollection results,
            out DiagnosticInfoCollection    diagnosticInfos)
        {
            HistoryReadRequest request = new HistoryReadRequest();
            HistoryReadResponse response = null;

            request.RequestHeader             = requestHeader;
            request.HistoryReadDetails        = historyReadDetails;
            request.TimestampsToReturn        = timestampsToReturn;
            request.ReleaseContinuationPoints = releaseContinuationPoints;
            request.NodesToRead               = nodesToRead;

            UpdateRequestHeader(request, requestHeader == null, "HistoryRead");

            try
            {
                if (UseTransportChannel)
                {
                    IServiceResponse genericResponse = TransportChannel.SendRequest(request);

                    if (genericResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }

                    ValidateResponse(genericResponse.ResponseHeader);
                    response = (HistoryReadResponse)genericResponse;
                }
                else
                {
                    HistoryReadResponseMessage responseMessage = InnerChannel.HistoryRead(new HistoryReadMessage(request));

                    if (responseMessage == null || responseMessage.HistoryReadResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }

                    response = responseMessage.HistoryReadResponse;
                    ValidateResponse(response.ResponseHeader);
                }

                results         = response.Results;
                diagnosticInfos = response.DiagnosticInfos;
            }
            finally
            {
                RequestCompleted(request, response, "HistoryRead");
            }

            return response.ResponseHeader;
        }
コード例 #14
0
ファイル: Opc.Ua.Client.cs プロジェクト: zryska/UA-.NET
        /// <summary>
        /// Finishes an asynchronous invocation of the HistoryRead service.
        /// </summary>
        public ResponseHeader EndHistoryRead(
            IAsyncResult                    result,
            out HistoryReadResultCollection results,
            out DiagnosticInfoCollection    diagnosticInfos)
        {
            HistoryReadResponse response = null;

            try
            {
                if (UseTransportChannel)
                {
                    IServiceResponse genericResponse = TransportChannel.EndSendRequest(result);

                    if (genericResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }

                    ValidateResponse(genericResponse.ResponseHeader);
                    response = (HistoryReadResponse)genericResponse;
                }
                else
                {
                    HistoryReadResponseMessage responseMessage = InnerChannel.EndHistoryRead(result);

                    if (responseMessage == null || responseMessage.HistoryReadResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }

                    response = responseMessage.HistoryReadResponse;
                    ValidateResponse(response.ResponseHeader);
                }

                results         = response.Results;
                diagnosticInfos = response.DiagnosticInfos;
            }
            finally
            {
                RequestCompleted(null, response, "HistoryRead");
            }

            return response.ResponseHeader;
        }
コード例 #15
0
        /// <summary>
        /// Reads the last date in the archive (truncates milliseconds and converts to local).
        /// </summary>
        private DateTime ReadLastDate()
        {
            ReadRawModifiedDetails details = new ReadRawModifiedDetails();

            details.StartTime        = DateTime.MinValue;
            details.EndTime          = DateTime.UtcNow.AddDays(1);
            details.NumValuesPerNode = 1;
            details.IsReadModified   = false;
            details.ReturnBounds     = false;

            HistoryReadValueId nodeToRead = new HistoryReadValueId();

            nodeToRead.NodeId = m_nodeId;

            HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();

            nodesToRead.Add(nodeToRead);

            HistoryReadResultCollection results         = null;
            DiagnosticInfoCollection    diagnosticInfos = null;

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

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

            if (StatusCode.IsBad(results[0].StatusCode))
            {
                return(DateTime.MinValue);
            }

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

            if (results == null)
            {
                return(DateTime.MinValue);
            }

            DateTime endTime = data.DataValues[0].SourceTimestamp;

            if (results[0].ContinuationPoint != null && results[0].ContinuationPoint.Length > 0)
            {
                nodeToRead.ContinuationPoint = results[0].ContinuationPoint;

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

                Session.ValidateResponse(results, nodesToRead);
                Session.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
            }

            endTime = new DateTime(endTime.Year, endTime.Month, endTime.Day, endTime.Hour, endTime.Minute, endTime.Second, 0, DateTimeKind.Utc);
            endTime = endTime.AddSeconds(1);
            endTime = endTime.ToLocalTime();

            return(endTime);
        }
コード例 #16
0
ファイル: MasterNodeManager.cs プロジェクト: yuriik83/UA-.NET
        /// <summary>
        /// Reads the history of a set of items.
        /// </summary>
        public virtual void HistoryRead(
            OperationContext                context,
            ExtensionObject                 historyReadDetails, 
            TimestampsToReturn              timestampsToReturn, 
            bool                            releaseContinuationPoints, 
            HistoryReadValueIdCollection    nodesToRead, 
            out HistoryReadResultCollection results, 
            out DiagnosticInfoCollection    diagnosticInfos)
        {
            // validate history details parameter.
            if (ExtensionObject.IsNull(historyReadDetails))
            {
                throw new ServiceResultException(StatusCodes.BadHistoryOperationInvalid);
            }

            HistoryReadDetails details = historyReadDetails.Body as HistoryReadDetails;

            if (details == null)
            {
                throw new ServiceResultException(StatusCodes.BadHistoryOperationUnsupported);
            }
            
            // create result lists.
            bool diagnosticsExist = false;
            results = new HistoryReadResultCollection(nodesToRead.Count);
            diagnosticInfos = new DiagnosticInfoCollection(nodesToRead.Count);

            // pre-validate items.
            bool validItems = false;

            for (int ii = 0; ii < nodesToRead.Count; ii++)
            {
                HistoryReadResult result = null;
                DiagnosticInfo diagnosticInfo = null;

                // pre-validate and pre-parse parameter.
                ServiceResult error = HistoryReadValueId.Validate(nodesToRead[ii]);
                
                // return error status.
                if (ServiceResult.IsBad(error))
                {
                    nodesToRead[ii].Processed = true;
                    result = new HistoryReadResult();
                    result.StatusCode = error.Code;
                    
                    // add diagnostics if requested.
                    if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
                    {
                        diagnosticInfo = ServerUtils.CreateDiagnosticInfo(m_server, context, error);
                        diagnosticsExist = true;
                    }
                }

                // found at least one valid item.
                else
                {
                    nodesToRead[ii].Processed = false;
                    validItems = true;
                }

                results.Add(result);
                diagnosticInfos.Add(diagnosticInfo);
            } 
            
            // call each node manager.
            if (validItems)
            {
                List<ServiceResult> errors = new List<ServiceResult>(results.Count);

                for (int ii = 0; ii < nodesToRead.Count; ii++)
                {
                    errors.Add(null);
                }

                foreach (INodeManager nodeManager in m_nodeManagers)
                {
                    nodeManager.HistoryRead(
                        context,
                        details,
                        timestampsToReturn,
                        releaseContinuationPoints,
                        nodesToRead,
                        results,
                        errors);
                }
                                
                for (int ii = 0; ii < nodesToRead.Count; ii++)
                {
                    HistoryReadResult result = results[ii];
 
                    // set an error code for nodes that were not handled by any node manager.
                    if (!nodesToRead[ii].Processed)
                    {
                        nodesToRead[ii].Processed = true;
                        result = results[ii] = new HistoryReadResult();
                        result.StatusCode = StatusCodes.BadNodeIdUnknown;
                        errors[ii] = results[ii].StatusCode;
                    }
                    
                    // update the diagnostic info and ensure the status code in the result is the same as the error code.
                    if (errors[ii] != null && errors[ii].Code != StatusCodes.Good)
                    {
                        if (result == null)
                        {
                            result = results[ii] = new HistoryReadResult();
                        }

                        result.StatusCode = errors[ii].Code;
                        
                        // add diagnostics if requested.
                        if ((context.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
                        {
                            diagnosticInfos[ii] = ServerUtils.CreateDiagnosticInfo(m_server, context, errors[ii]);
                            diagnosticsExist = true;
                        }
                    }
                }
            }

            // clear the diagnostics array if no diagnostics requested or no errors occurred.
            UpdateDiagnostics(context, diagnosticsExist, ref diagnosticInfos);
        }
コード例 #17
0
        /// <summary>
        /// Invokes the HistoryRead service.
        /// </summary>
        public virtual ResponseHeader HistoryRead(
            RequestHeader                   requestHeader,
            ExtensionObject                 historyReadDetails,
            TimestampsToReturn              timestampsToReturn,
            bool                            releaseContinuationPoints,
            HistoryReadValueIdCollection    nodesToRead,
            out HistoryReadResultCollection results,
            out DiagnosticInfoCollection    diagnosticInfos)
        {
            results = null;
            diagnosticInfos = null;

            ValidateRequest(requestHeader);

            // Insert implementation.

            return CreateResponse(requestHeader, StatusCodes.BadServiceUnsupported);
        }
コード例 #18
0
ファイル: ReadHistoryDlg.cs プロジェクト: neobox3000/UA-.NET
        private void ReadProcessed()
        {
            ReadProcessedDetails details = new ReadProcessedDetails();

            details.StartTime          = StartTimeDP.Value.ToUniversalTime();
            details.EndTime            = EndTimeDP.Value.ToUniversalTime();
            details.ProcessingInterval = (double)ResampleIntervalNP.Value;

            NodeId aggregateId = null;

            switch ((string)AggregateCB.SelectedItem)
            {
            case BrowseNames.AggregateFunction_Interpolative: { aggregateId = ObjectIds.AggregateFunction_Interpolative; break; }

            case BrowseNames.AggregateFunction_TimeAverage: { aggregateId = ObjectIds.AggregateFunction_TimeAverage; break; }

            case BrowseNames.AggregateFunction_Average: { aggregateId = ObjectIds.AggregateFunction_Average; break; }

            case BrowseNames.AggregateFunction_Count: { aggregateId = ObjectIds.AggregateFunction_Count; break; }

            case BrowseNames.AggregateFunction_Maximum: { aggregateId = ObjectIds.AggregateFunction_Maximum; break; }

            case BrowseNames.AggregateFunction_Minimum: { aggregateId = ObjectIds.AggregateFunction_Minimum; break; }

            case BrowseNames.AggregateFunction_Total: { aggregateId = ObjectIds.AggregateFunction_Total; break; }
            }

            details.AggregateType.Add(aggregateId);

            HistoryReadValueId nodeToRead = new HistoryReadValueId();

            nodeToRead.NodeId = m_nodeId;

            if (m_result != null)
            {
                nodeToRead.ContinuationPoint = m_result.ContinuationPoint;
            }

            HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();

            nodesToRead.Add(nodeToRead);

            HistoryReadResultCollection results         = null;
            DiagnosticInfoCollection    diagnosticInfos = null;

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

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

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

            m_result = results[0];

            ShowResults();
        }
コード例 #19
0
ファイル: ReadHistoryDlg.cs プロジェクト: neobox3000/UA-.NET
        private void ReadRaw(bool isReadModified)
        {
            ReadRawModifiedDetails details = new ReadRawModifiedDetails();

            details.StartTime        = DateTime.MinValue;
            details.EndTime          = DateTime.MinValue;
            details.IsReadModified   = isReadModified;
            details.NumValuesPerNode = 0;
            details.ReturnBounds     = ReturnBoundsCK.Checked;

            if (StartTimeCK.Checked)
            {
                details.StartTime = StartTimeDP.Value.ToUniversalTime();
            }

            if (EndTimeCK.Checked)
            {
                details.EndTime = EndTimeDP.Value.ToUniversalTime();
            }

            if (MaxReturnValuesCK.Checked)
            {
                details.NumValuesPerNode = (uint)MaxReturnValuesNP.Value;
            }

            HistoryReadValueId nodeToRead = new HistoryReadValueId();

            nodeToRead.NodeId = m_nodeId;

            if (m_result != null)
            {
                nodeToRead.ContinuationPoint = m_result.ContinuationPoint;
            }

            HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();

            nodesToRead.Add(nodeToRead);

            HistoryReadResultCollection results         = null;
            DiagnosticInfoCollection    diagnosticInfos = null;

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

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

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

            m_result = results[0];

            ShowResults();
        }
コード例 #20
0
        public async Task <List <OPCUATag> > ReadRaw(string serverUrl, bool bIsReadModified, DateTime dateStartDateTime, DateTime dateEndDateTime, int iMaxReturnVal, List <string> lstNodeId)
        {
            List <OPCUATag>             tags = new List <OPCUATag>();
            HistoryReadResultCollection objHistoryReadResult = new HistoryReadResultCollection();

            try
            {
                Session session = await GetSessionAsync(serverUrl);

                ReadRawModifiedDetails details = new ReadRawModifiedDetails();
                details.StartTime        = DateTime.MinValue;
                details.EndTime          = DateTime.MinValue;
                details.IsReadModified   = bIsReadModified;
                details.NumValuesPerNode = 0;

                details.StartTime = dateStartDateTime.ToUniversalTime();

                details.EndTime = dateEndDateTime.ToUniversalTime();

                details.NumValuesPerNode = (uint)iMaxReturnVal;

                HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();

                foreach (string strNodeId in lstNodeId)//OA-2018-03-13
                {
                    HistoryReadValueId nodeToRead = new HistoryReadValueId();

                    nodeToRead.NodeId = (NodeId)strNodeId;//_reference.NodeId;

                    nodesToRead.Add(nodeToRead);
                }
                HistoryReadResultCollection HistoryResults  = null;
                DiagnosticInfoCollection    diagnosticInfos = null;

                session.HistoryRead(
                    null,
                    new ExtensionObject(details),
                    TimestampsToReturn.Source,
                    false,
                    nodesToRead,
                    out HistoryResults,
                    out diagnosticInfos);

                Session.ValidateResponse(HistoryResults, nodesToRead);
                Session.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);

                #region Prepare result
                objHistoryReadResult = HistoryResults;
                if (objHistoryReadResult.Count > 0)
                {
                    var m_index = 0;
                    foreach (var result in objHistoryReadResult)
                    {
                        HistoryData results = ExtensionObject.ToEncodeable(result.HistoryData) as HistoryData;
                        if (results == null)
                        {
                            return(tags);
                        }
                        for (int ii = 0; ii < results.DataValues.Count; ii++)
                        {
                            StatusCode status      = results.DataValues[ii].StatusCode;
                            string     index       = Utils.Format("[{0}]", m_index++);
                            var        timestamp   = results.DataValues[ii].SourceTimestamp.ToLocalTime();
                            var        sec         = results.DataValues[ii].SourceTimestamp.Millisecond;
                            string     value       = Utils.Format("{0}", results.DataValues[ii].WrappedValue);
                            string     quality     = Utils.Format("{0}", (StatusCode)status.CodeBits);
                            string     historyInfo = Utils.Format("{0:X2}", (int)status.AggregateBits);
                            var        date        = String.Format("{0}.{1}", timestamp.ToString("MM/dd/yyyy HH:mm:ss"), sec.ToString().PadLeft(3, '0'));
                            OPCUATag   tag         = new OPCUATag(index, date, value, quality);

                            tags.Add(tag);
                        }
                    }
                }
                #endregion

                return(tags);
            }
            catch (Exception e)
            {
                return(tags);
            }
        }
コード例 #21
0
        /// <summary>
        /// Returns the UTC timestamp of the first event in the archive.
        /// </summary>
        private DateTime ReadFirstDate()
        {
            // read the time of the first event in the archive.
            ReadEventDetails details = new ReadEventDetails();

            details.StartTime        = new DateTime(1970, 1, 1);
            details.EndTime          = DateTime.MinValue;
            details.NumValuesPerNode = 1;
            details.Filter           = new EventFilter();
            details.Filter.AddSelectClause(Opc.Ua.ObjectTypeIds.BaseEventType, Opc.Ua.BrowseNames.Time);

            HistoryReadValueId nodeToRead = new HistoryReadValueId();

            nodeToRead.NodeId = m_areaId;

            HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();

            nodesToRead.Add(nodeToRead);

            HistoryReadResultCollection results         = null;
            DiagnosticInfoCollection    diagnosticInfos = null;

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

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

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

            // get the data.
            HistoryEvent data = ExtensionObject.ToEncodeable(results[0].HistoryData) as HistoryEvent;

            // release the continuation point.
            if (results[0].ContinuationPoint != null)
            {
                nodeToRead.ContinuationPoint = results[0].ContinuationPoint;

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

                Session.ValidateResponse(results, nodesToRead);
                Session.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);
            }

            // check if an event found.
            if (data == null || data.Events.Count == 0 || data.Events[0].EventFields.Count == 0)
            {
                throw new ServiceResultException(StatusCodes.BadNoDataAvailable);
            }

            // get the event time.
            DateTime?eventTime = data.Events[0].EventFields[0].Value as DateTime?;

            if (eventTime == null)
            {
                throw new ServiceResultException(StatusCodes.BadTypeMismatch);
            }

            // return time as UTC value.
            return(eventTime.Value);
        }