I just tried to add a for loop to make it scan from both scanners several times :
Code:Dim DeviceManager1 = CreateObject("WIA.DeviceManager") 'wia device manager For k = 1 To 3 Dim j As String = 1 For i = 1 To DeviceManager1.DeviceInfos.Count 'loop through all devices [...] Next i Next k DeviceManager1 = Nothing
That showed that the first occurence of the loop works (scans once from each scanner) but that's it, the scanners never scan the second time and start blinking, so basically exactly the same problem.
I also tried to include the Devicemanager declaration in the new loop :
but it did not change anything.Code:For k = 1 To 3 Dim DeviceManager1 = CreateObject("WIA.DeviceManager") 'wia device manager Dim j As String = 1 For i = 1 To DeviceManager1.DeviceInfos.Count 'loop through all devices [...] Next i DeviceManager1 = Nothing Next k
The next thing I did wat to log the events within the loop so that I can know where exactly things stop :
Code:Dim DeviceManager1 = CreateObject("WIA.DeviceManager") 'wia device manager Dim j As String = 1 For i = 1 To DeviceManager1.DeviceInfos.Count 'loop through all devices If DeviceManager1.DeviceInfos(i).Type = 1 Then 'Select only scanners, not webcams etc... 'startpoint to calculate how long it is to scan Dim ScanStart = DateAndTime.Second(Now) + (DateAndTime.Minute(Now) * 60) + (DateAndTime.Hour(Now) * 3600) 'Directory + file Dim targetdir = Me.ProjectFolderBox.Text & "\scans\Scanner" & j & "\S" & j & "_" & Me.FilePrefix.Text & Me.CurrFileIndex & "." & Me.FileExt.SelectedItem Form2.CurrentActionLabel.Text = "Scanning from scanner #" & j Dim Scanner As WIA.Device = DeviceManager1.DeviceInfos(i).connect If IsNothing(Scanner) Then Log(Me.logfilename, Now & " | Scanner #" & j & " not found") Else Try Dim Img As WIA.ImageFile 'log Log(Me.logfilename, Now & " | Scanner #" & j & " | Img initialized") With Scanner.Items(1) .Properties("6146").Value = colorcode '4 is Black-white,gray is 2, color 1 (Color Intent) .Properties("6147").Value = dpi 'dots per inch/horizontal .Properties("6148").Value = dpi 'dots per inch/vertical .Properties("6149").Value = 0 'x point where to start scan .Properties("6150").Value = 0 'y-point where to start scan 'Following is A4 paper size. (Not 100% accurate because real A4 Ht errors) .Properties("6151").Value = horizextent 'horizontal exent DPI x inches wide .Properties("6152").Value = vertextent 'vertical extent DPI x inches tall ' .Properties("4104").Value = 8 'bits per pixel End With 'log Log(Me.logfilename, Now & " | Scanner #" & j & " | properties initialized") 'transfer image Img = Scanner.Items(1).Transfer(fileformat) 'scans the image. 'log Log(Me.logfilename, Now & " | Scanner #" & j & " |Transfer done") 'kill previous file if exists to avoid errors If System.IO.File.Exists(targetdir) = True Then Kill(targetdir) 'log Log(Me.logfilename, Now & " | Scanner #" & j & " | deleted existing " & targetdir) End If Img.SaveFile(targetdir) 'log Log(Me.logfilename, Now & " | Scanner #" & j & " | saved " & targetdir) 'last scan Form2.LastFileLabel.Text = "\Scanner" & j & "\S" & j & "_" & Me.FilePrefix.Text & Me.CurrFileIndex & "." & Me.FileExt.SelectedItem Form2.LastScanLabel.Text = Now Catch ex As Exception MsgBox(ex.Message) Finally Scanner = Nothing End Try End If 'End time for the scan Dim ScanEnd = DateAndTime.Second(Now) + (DateAndTime.Minute(Now) * 60) + (DateAndTime.Hour(Now) * 3600) 'log Log(Me.logfilename, Now & " | Scanner #" & j & " | Scanned " & targetdir & " | duration: " & (ScanEnd - ScanStart)) j = j + 1 End If Next i
and here is the logfile generated :
Scan starts 29/11/2012 9:24:31 AM | Interval :Start scanning with 5 min | Res:100 DPI |
29/11/2012 9:24:31 AM | Scanner #1 | Img initialized
29/11/2012 9:24:31 AM | Scanner #1 | properties initialized
29/11/2012 9:24:49 AM | Scanner #1 |Transfer done
29/11/2012 9:24:49 AM | Scanner #1 | saved C:\__2\scans\Scanner1\S1_img_1.TIF
29/11/2012 9:24:49 AM | Scanner #1 | Scanned C:\__2\scans\Scanner1\S1_img_1.TIF | duration: 18
29/11/2012 9:24:49 AM | Scanner #2 | Img initialized
29/11/2012 9:24:49 AM | Scanner #2 | properties initialized
29/11/2012 9:25:08 AM | Scanner #2 |Transfer done
29/11/2012 9:25:08 AM | Scanner #2 | saved C:\__2\scans\Scanner2\S2_img_1.TIF
29/11/2012 9:25:08 AM | Scanner #2 | Scanned C:\__2\scans\Scanner2\S2_img_1.TIF | duration: 19
29/11/2012 9:25:08 AM | Scanner #1 | Img initialized
29/11/2012 9:25:08 AM | Scanner #1 | properties initialized
it appears that things go wrong at this line :
Code:Img = Scanner.Items(1).Transfer(fileformat) 'scans the image.
It looks like WIA is happy to switch from scanner 1 to 2 but refuses to come back to scanner 1 for the next round. also, I should precise, when the second scan is supposed to occur, scanner #2 blinks (and not 1 which surprises me).
Is it possible that scanner#2 is selected as "default scanner" or something like that and if so, is there a way to revert that ?
thanks for your help




Reply With Quote
