Occurs when the asynchronous device event is occurs.
Visual Basic |
---|
Public Event DeviceAsyncEvent( _ ByVal deviceEvent As Long, _ ByVal deviceName As String, _ ByVal batteryMinutes As Double, _ ByVal batteryPercentage As Integer, _ ByVal powerSupply As Long, _ ByVal resolutionX As Single, _ ByVal resolutionY As Single, _ ByVal flashUsed As Long, _ ByVal automaticCapture As Double, _ ByVal timeBeforeFirstCapture As Double, _ ByVal timeBetweenCaptures As Double _ ) |
Private VSTwain1 As New VintaSoftTwain() ''' <summary> ''' Scans images asynchronously. ''' </summary> Private Sub ScanImages() VSTwain1.Device_Open() If VSTwain1.DeviceManager_ShowDefaultDeviceSelectionDialog() Then VSTwain1.Device_ShowUI = True Try ' get events supported by device Dim supportedDeviceEvents As Array = VSTwain1.Device_GetSupportedAsyncEvents() If (Not IsNothing(supportedDeviceEvents)) Then ' for each supported event For i As Integer = 0 To supportedDeviceEvents.Length - 1 ' if device can report when paper is jammed If supportedDeviceEvents(i) = 13 Then ' specify that device must report when paper is jammed VSTwain1.Device_AsyncEvents = New Int32() {13} ' subscribe to the device event AddHandler VSTwain1.DeviceAsyncEvent, AddressOf VSTwain1_AsyncEvent Exit For End If Next End If Catch ex As Exception Console.WriteLine(ex.ToString()) End Try ' subscribe to the device events AddHandler VSTwain1.DeviceImageAcquired, AddressOf VSTwain1_ImageAcquired AddHandler VSTwain1.DeviceScanCompleted, AddressOf VSTwain1_ScanCompleted AddHandler VSTwain1.DeviceScanFailed, AddressOf VSTwain1_ScanFailed AddHandler VSTwain1.DeviceScanCanceled, AddressOf VSTwain1_ScanCanceled ' acquire images asynchronously VSTwain1.Device_AcquireImage() End If End Sub Private Sub VSTwain1_AsyncEvent(deviceEvent As Integer, _ deviceName As String, _ batteryMinutes As Double, _ batteryPercentage As Short, _ powerSupply As Integer, _ resolutionX As Single, _ resolutionY As Single, _ flashUsed As Integer, _ automaticCapture As Double, _ timeBeforeFirstCapture As Double, _ timeBetweenCaptures As Double) Console.WriteLine("Paper is jammed.") End Sub Private Sub VSTwain1_ImageAcquired() ' get index of acquired image Dim imageIndex As Integer = VSTwain1.AcquiredImages_Count - 1 ' save acquired image to TIFF file If Not VSTwain1.AcquiredImages_Save(0, "c:\test.tiff") Then Console.WriteLine(VSTwain1.errorString) End If End Sub Private Sub VSTwain1_ScanCompleted() Console.WriteLine("Scan is completed.") End Sub Private Sub VSTwain1_ScanFailed(errorString As String) Console.WriteLine(String.Format("Scan is failed: {0}.", errorString)) End Sub Private Sub VSTwain1_ScanCanceled() Console.WriteLine("Scan is canceled.") End Sub