DAQ-DNC prepares various events for each component.
Example) When an error occurs: OnError event, input task execution: OnTaskInput event
By writing your own code when an event occurs, you can create an application with a higher degree of freedom.
The following is an example of writing error information on the label when a DncDaq error event occurs.
1. Automatically generate event handlers in Visual Studio
With DncDaq selected on the Visual Studio Designer screen, select an event from the Properties window.
Since the event list is displayed on the screen, by clicking in the OnError field, the code that describes the processing when the event occurs is automatically generated.
・Property window screen
・Automatically generated event handler code
private void dncDaq1_OnError_1(object sender, short DeviceNo, dnc.common.DncErrorEventArgs e)
{
}
2. Write the process when an event occurs in the automatically generated code
Write the process to be executed when an event occurs in the event handler.
At this time, depending on the processing of Dnc, the event handler may be executed in another thread.
Invoke is required to operate the control of UI thread in the processing of the event that occurred in another thread.
Please use InvokeRequired to determine whether Invoke is required or not.
・Example of writing code in an automatically generated event handler
private void dncDaq1_OnError_1(object sender, short DeviceNo, dnc.common.DncErrorEventArgs e)
{
if (InvokeRequired == true)
{
//----------------------------------------
// Link the status information in the event argument to the label.
// Since the error event is executed in another thread, use Invoke to operate the form control.
//----------------------------------------
Invoke(new Action(() => txtDaqError.Text = "Device No.: " + DeviceNo.ToString() +
"Error Type: " + e.ErrorType.ToString() +
"Error No.: " + e.Error.ToString() +
"Parameter: " + e.Param.ToString()));
}
else
{
//----------------------------------------
// Link the status information in the event argument to the label.
// Since Invoke is unnecessary, you can operate the form control directly.
//----------------------------------------
txtDaqError.Text = "Device No.: " + DeviceNo.ToString() +
"Error Type: " + e.ErrorType.ToString() +
"Error No.: " + e.Error.ToString() +
"Parameter: " + e.Param.ToString();
}
}