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
{
Session session = m_parent.Session;
if (session == null)
{
return;
}
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 };
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);
}
Cursor = Cursors.WaitCursor;
List<HistoryDataReadResult> results = session.HistoryReadProcessed(
nodesToRead,
details,
new RequestSettings() { OperationTimeout = 10000 });
{
m_parent.ShowError(
this,
"Read history call failed: " + results[0].
StatusCode.ToString());
m_details = null;
m_nodeToContinue = null;
return;
}
if (results[0].DataValues != null)
{
foreach (DataValue value in results[0].DataValues)
{
AddValue(value, null);
}
m_dataset.AcceptChanges();
}
if (!
ByteString.IsNull(results[0].ContinuationPoint))
{
m_nodeToContinue.ContinuationPoint = results[0].ContinuationPoint;
ReleaseContinuationPointBTN.Visible = true;
}
else
{
m_nodeToContinue = null;
ReleaseContinuationPointBTN.Visible = false;
}
}