UA Bundle SDK .NET  2.2.1.258
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Groups Pages
History Read – History Read Processed

Prerequisites

A session with the server must be established.

Description

The following dialog shows an example implementation of the History Read service with data processing. Press the button “Show Code” to display the corresponding code, and the button “Help” to show this documentation page.

Sample Code

The following code reads the historical data for a variable in a specified time range. It displays a list of aggregated values, calculated from the history of the variable using the given processing interval and aggregate calculation.

try
{
// get the current session from the parent form.
Session session = m_parent.Session;
// nothing to do if no session.
if (session == null)
{
return;
}
// parse the object id.
NodeId nodeId = NodeId.Parse(NodeIdTB.Text);
ReadProcessedDetails details = m_details as ReadProcessedDetails;
HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();
if (m_nodeToContinue == null)
{
m_dataset.Tables[0].Rows.Clear();
details = new ReadProcessedDetails();
details.StartTime = StartTimeDP.Value.ToUniversalTime();
details.EndTime = EndTimeDP.Value.ToUniversalTime();
details.ProcessingInterval = (double)ProcessingIntervalUD.Value;
details.AggregateConfiguration = new AggregateConfiguration() { UseServerCapabilitiesDefaults = true };
// add one combination of a node id an aggregate type.
nodesToRead.Add(new HistoryReadValueId() { NodeId = nodeId });
details.AggregateType.Add(((AvailableAggregate)AggregateTypeCB.SelectedItem).NodeId);
m_details = details;
m_nodeToContinue = nodesToRead[0];
}
else
{
nodesToRead.Add(m_nodeToContinue);
}
// this is a blocking call so show the wait cursor.
Cursor = Cursors.WaitCursor;
// fetch the history (with a 10s timeout).
List<HistoryDataReadResult> results = session.HistoryReadProcessed(
nodesToRead,
details,
new RequestSettings() { OperationTimeout = 10000 });
// check for operation error.
if (StatusCode.IsBad(results[0].StatusCode))
{
m_parent.ShowError(this, "Read history call failed: " + results[0].StatusCode.ToString());
m_details = null;
m_nodeToContinue = null;
return;
}
// update controls.
if (results[0].DataValues != null)
{
foreach (DataValue value in results[0].DataValues)
{
AddValue(value, null);
}
m_dataset.AcceptChanges();
}
// save continuation point.
if (!ByteString.IsNull(results[0].ContinuationPoint))
{
m_nodeToContinue.ContinuationPoint = results[0].ContinuationPoint;
ReleaseContinuationPointBTN.Visible = true;
}
else
{
m_nodeToContinue = null;
ReleaseContinuationPointBTN.Visible = false;
}
}