Пример #1
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("");
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Deletes the history of values for a set of variables at given time.
        /// </summary>
        static void HistoryDeleteAtTime(Session session)
        {
            // translate browse paths.
            IList <NodeOfInterest> results = GetNodeIds(session, Opc.Ua.Objects.ObjectsFolder,
                                                        VariableBrowsePaths.ToArray());


            DiagnosticInfoCollection diagnosticInfos;

            ExtensionObjectCollection eoc = new ExtensionObjectCollection();

            for (int ii = 0; ii < results.Count; ii++)
            {
                DeleteAtTimeDetails deleteDetails = new DeleteAtTimeDetails();
                deleteDetails.ReqTimes = new DateTimeCollection();
                for (int jj = 0; jj < 5; jj++)
                {
                    deleteDetails.ReqTimes.Add(new DateTime(2008, 01, 01, 12, 0, jj * 2));
                }

                deleteDetails.NodeId    = results[ii].NodeId;
                deleteDetails.Processed = false;

                ExtensionObject eo = new ExtensionObject(deleteDetails.TypeId, deleteDetails);
                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("");
                }
            }
        }