Opc.Ua.Sample.Program.HistoryReadAtTime C# (CSharp) Méthode

HistoryReadAtTime() static private méthode

Reads the history of values for a set of variables at given time.
static private HistoryReadAtTime ( Session session ) : void
session Session
Résultat void
        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);
                }
            }
        }