Prerequisites
A session with the server must be established.
Description
The following dialog shows an example implementation of the History Read service. Press the button “Show Code” to display the corresponding code, and the button “Help” to show this documentation page.
Press the button “...” right of the field “Variable” to open a window to browse the address space and select a historizing variable. After pressing the button “OK” the NodeId will be shown in the corresponding field.
You can specify a time range by checking the boxes right of the input fields “Start Time” and “End Time” and entering the desired values. Clicking on the arrow in the input field opens a calendar for picking the date. The time can be entered directly.
In addtion you can specify the maximum number of values to be returned in the field “Num Values” and include the bounding values specified above by checking the box right of “Include Bounds”.
On pressing the button “Read History” the response is listed at “History Read Response”. Check the box in front of “Use Asynchronous Pattern” to call “BeginHistoryRead” instead of “HistoryRead”.
If a maximum number of values is specified above, a continuation point is set. Pressing the button “Read History” again returns values starting at that continuation point. After pressing the button “Releasse Continuation Point” returned values are starting at the start time specified above.
Sample Code
The following code reads the historical data for a variable in a specified time range and displays the result in a list.
try
{
Session session = m_parent.Session;
if (session == null)
{
return;
}
ReadRawModifiedDetails details = m_details as ReadRawModifiedDetails;
HistoryReadValueIdCollection nodesToRead = new HistoryReadValueIdCollection();
if (m_nodeToContinue == null)
{
m_dataset.Tables[0].Rows.Clear();
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 = false;
details.ReturnBounds = ReturnBoundsCK.Checked;
nodesToRead.Add(
new HistoryReadValueId() {
NodeId = nodeId });
m_details = details;
m_nodeToContinue = nodesToRead[0];
}
else
{
nodesToRead.Add(m_nodeToContinue);
}
Cursor = Cursors.WaitCursor;
List<HistoryDataReadResult> results = session.HistoryReadRaw(
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;
}
}
catch (Exception exception)
{
ExceptionDlg.Show(this.Text, exception);
m_nodeToContinue = null;
}
finally
{
Cursor = Cursors.Default;
}