VintaSoft Twain .NET SDK v10.2
Vintasoft.Twain Namespace / Device Class / AsyncEvent Event
Example




In This Topic
    AsyncEvent Event (Device)
    In This Topic
    Occurs when the asynchronous device event is occurs.
    Syntax
    'Declaration
     
    Public Event AsyncEvent As EventHandler(Of DeviceAsyncEventArgs)
    'Usage
     
    Dim instance As Device
    Dim handler As EventHandler(Of DeviceAsyncEventArgs)
     
    AddHandler instance.AsyncEvent, handler
    public event EventHandler<DeviceAsyncEventArgs> AsyncEvent
    public: __event EventHandler<DeviceAsyncEventArgs*>* AsyncEvent
    public:
    event EventHandler<DeviceAsyncEventArgs^>^ AsyncEvent
    Event Data

    The event handler receives an argument of type DeviceAsyncEventArgs containing data related to this event. The following DeviceAsyncEventArgs properties provide information specific to this event.

    PropertyDescription
    Gets the number of images camera will capture.  
    Gets the minutes of battery power remaining.  
    Gets the percentage of battery power remaining.  
    Get the event that has taken place.  
    Gets the name of the device that generated the event.  
    Gets the current flash setting.  
    Gets the current power supply in use.  
    Gets the current resolution.  
    Gets the number of seconds before first capture.  
    Gets the hundredths of a second between captures.  
    Example
    This example shows how to detect when paper is jammed.
    ''' <summary>
    ''' Detects the paper jamm.
    ''' </summary>
    Public Sub DetectPaperJam(ByVal device As Device)
        ' disable device UI
        device.ShowUI = False
        ' disable device when images are acquired
        device.DisableAfterAcquire = True
                
        ' open the device
        device.Open()
                
        ' set device settings
        device.PixelType = PixelType.RGB
        device.UnitOfMeasure = UnitOfMeasure.Inches
        device.Resolution = New Resolution(300.0F, 300.0F)
                
        Try
            ' get events supported by device
            Dim supportedDeviceEvents As DeviceEventId() = device.GetSupportedAsyncEvents()
            ' for each supported event
            For i As Integer = 0 To supportedDeviceEvents.Length - 1
                ' if device can report when paper is jammed
                If supportedDeviceEvents(i) = DeviceEventId.PaperJam Then
                    ' specify that device must report when paper is jammed
                    device.AsyncEvents = New DeviceEventId() {DeviceEventId.PaperJam}
                
                    ' subscribe to the device event
                    AddHandler device.AsyncEvent, New EventHandler(Of DeviceAsyncEventArgs)(AddressOf device_DeviceEvent)
                
                    Exit For
                End If
            Next
        Catch ex As Exception
            Console.WriteLine(ex.ToString())
        End Try
                
        ' subscribe to the Device.ImageAcquired, Device.ScanCompleted, ... events
        '...
                
        ' acquire images from device
        device.Acquire()
    End Sub
                
    ''' <summary>
    ''' Occurred the device event.
    ''' </summary>
    Private Sub device_DeviceEvent(ByVal sender As Object, ByVal e As DeviceAsyncEventArgs)
        Console.WriteLine("Paper is jammed.")
    End Sub
    /// <summary>
    /// Detects the paper jamm.
    /// </summary>
    public void DetectPaperJam(Device device)
    {
        // disable device UI
        device.ShowUI = false;
        // disable device when images are acquired
        device.DisableAfterAcquire = true;
                
        // open the device
        device.Open();
                
        // set device settings
        device.PixelType = PixelType.RGB;
        device.UnitOfMeasure = UnitOfMeasure.Inches;
        device.Resolution = new Resolution(300f, 300f);
                
        try
        {
            // get events supported by device
            DeviceEventId[] supportedDeviceEvents = device.GetSupportedAsyncEvents();
            // for each supported event
            for (int i = 0; i < supportedDeviceEvents.Length; i++)
            {
                // if device can report when paper is jammed
                if (supportedDeviceEvents[i] == DeviceEventId.PaperJam)
                {
                    // specify that device must report when paper is jammed
                    device.AsyncEvents = new DeviceEventId[] { DeviceEventId.PaperJam };
                
                    // subscribe to the device event
                    device.AsyncEvent += new EventHandler<DeviceAsyncEventArgs>(device_DeviceEvent);
                
                    break;
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
                
        // subscribe to the Device.ImageAcquired, Device.ScanCompleted, ... events
        //...
                
        // acquire images from device
        device.Acquire();
    }
                
    /// <summary>
    /// Occurred the device event.
    /// </summary>
    private void device_DeviceEvent(object sender, DeviceAsyncEventArgs e)
    {
        Console.WriteLine("Paper is jammed.");
    }
    Requirements

    Target Platforms: Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also