How Do I Manage Errors and Warnings in the NI-SCOPE .NET Class Library?

The underlying NI-SCOPE driver reports any errors or warnings as error codes. Negative return values indicate errors, whereas positive values indicate warnings. In case of warnings, a warning event is raised that you can subscribe to.

Errors

The NI-SCOPE .NET API converts the negative error codes into exceptions and throws these exceptions. All exceptions that the API throws are either .NET-defined or IVI-defined; none of them are custom exceptions. The exception message for driver errors has the driver error code appended at the end.

Warnings

Warnings are communicated as events. To receive warnings, you must subscribe to the Warning event as follows:
  • Driver Warning
    VB.NET
    
    AddHandler scopeSession.DriverOperation.Warning, New EventHandler(Of ScopeWarningEventArgs)(AddressOf DriverOperation_Warning)
    Private Sub DriverOperation_Warning(ByVal sender As Object, ByVal e As ScopeWarningEventArgs)
        'Code to handle Warnings. 
    End Sub
    C#
    
    scopeSession.DriverOperation.Warning += new EventHandler<ScopeWarningEventArgs>(DriverOperation_Warning);
    void DriverOperation_Warning(object sender, ScopeWarningEventArgs e)
    {
        //Code to handle Warnings.
    }
    Note National Instruments recommends subscribing to the warning event immediately after creating the NIScope object, to avoid missing any warnings that might occur.
  • InterchangeCheck WarningInterchangeCheck warnings are communicated as events. To receive warnings, you must subscribe to the InterchangeCheckWarning event as follows:
    VB.NET
    
    AddHandler scopeSession.DriverOperation.InterchangeCheckWarning, AddressOf DriverOperation_InterchangeCheckWarning
    Private Sub DriverOperation_InterchangeCheckWarning(ByVal sender As Object, ByVal e As ScopeInterchangeCheckWarningEventArgs)
        'Code to handle InterchangeCheckWarnings. 
    End Sub
    C#
    
    scopeSession.DriverOperation.InterchangeCheckWarning += new EventHandler<ScopeInterchangeCheckWarningEventArgs>(DriverOperation_InterchangeCheckWarning);
    void DriverOperation_InterchangeCheckWarning(object sender,  ScopeInterchangeCheckWarningEventArgs e)
    {
        //Code to handle InterchangeCheckWarnings.
    }
  • Coercion WarningCoercionWarnings are communicated as events. To receive warnings, your must subscribe to the Coercion event as follows:
    VB.NET
    
    AddHandler scopeSession.DriverOperation.Coercion, AddressOf DriverOperation_CoercionWarning
    Private Sub DriverOperation_CoercionWarning(ByVal sender As Object, ByVal e As ScopeCoercionEventArgs)
        'Code to handle CoercionWarnings. 
    End Sub
    C#
    
    scopeSession.DriverOperation.Coercion += new EventHandler<ScopeCoercionEventArgs>(DriverOperation_CoercionWarning);
    void DriverOperation_CoercionWarning(object sender, ScopeCoercionEventArgs e)
    {
        //Code to handle CoercionWarnings.
    }

Each warning EventArgs class contains a read-only property Text to get the description of that event. For example:

  • Ivi.Driver.CoercionEventArgs
    VB.NET
    
    Private Sub DriverOperation_CoercionWarning(ByVal sender As Object, ByVal e As Ivi.Driver.CoercionEventArgs)
        Dim description As string = e.Text
    End Sub
    C#
    
    void DriverOperation_CoercionWarning(object sender, Ivi.Driver.CoercionEventArgs e)
    {
        string description = e.Text;
    }
  • Ivi.Driver.InterchangeCheckWarningEventArgs
    VB.NET
    
    Private Sub DriverOperation_InterchangeCheckWarning(ByVal sender As Object, ByVal e As Ivi.Driver.InterchangeCheckWarningEventArgs)
        Dim description As string = e.Text 
    End Sub
    C#
    
    void DriverOperation_InterchangeCheckWarning(object sender, Ivi.Driver.InterchangeCheckWarningEventArgs e)
    {
        string description = e.Text;
    }