Error and Warning Events

NI Vision for Visual Basic

Error and Warning Events

The CWIMAQ control also includes its own error and warning events, IMAQError and IMAQWarning. Although you normally use return codes for error checking of the methods used on the CWIMAQ control, you cannot use return codes for error checking in asynchronous operations such as a continuous acquisition because no methods are called after the first Start method. In this case, the CWIMAQ control generates its own error event if an error or warning occurs during an ongoing acquisition. You can develop an event handler to process these error and warning events. The following code shows the skeleton event functions for the CWIMAQ control.

CWIMAQ1_IMAQError (ByVal StatusCode As Long, ByVal ContextID As Long, ByVal ContextDescription As String)
CWIMAQ1_IMAQWarning (ByVal StatusCode As Long, ByVal ContextID As Long, ByVal ContextDescription As String)

The StatusCode variable that is passed to the event handler contains the value of the error or warning condition. The ContextID contains a value describing the operation where the error or warning occurred, and the ContextDescription contains a string describing the operation where the error or warning occurred.

The following code shows an example of how to use the CWIMAQ_IMAQError event in a Visual Basic application.

Private Sub CWIMAQ1_IMAQError(ByVal StatusCode As Long, ByVal ContextID As Long, ByVal ContextDescription As String)
MsgBox ContextDescription + ": CStr(StatusCode)
End Sub

By default, only asynchronous operations call error and warning events. You can set the ErrorEventMask property of the CWIMAQ control to specify the operations for which the error and warning events are called.