Page 1 of 1

Detect if scanner is connected?

Posted: Tue Sep 09, 2008 3:22 pm
by rbourque
Is there an easy way to detect if the scanner is connected or not?
I'd like the application I wrote to disable scanning features if the user disconnected the scanner.

Re: Detect if scanner is connected?

Posted: Wed Sep 10, 2008 10:27 am
by Alex
Hello,

TWAIN standard does not allow to detect if device is on-line or not. You should try to open the device if you want to check device status.

Which scanner do you use? Some scanners send messages to application about their state (the power supply has been changed, the user has added a device, device has become unavailable and so on).

Best regards, Alexander

Re: Detect if scanner is connected?

Posted: Wed Sep 10, 2008 2:48 pm
by rbourque
My software is for remote invoice approval and is used by 120 users. Only 3 of which use an HP ScanJet 5590 to scan in the images.

So if I did the following in a try/catch block it would work?

bool bScannerConnected = false;
try {
Vintasoft.Twain.VSTwain td_Scanner = new Vintasoft.Twain.VSTwain();
td_Scanner.StartDevice();
td_Scanner.OpenDataSource();
bScannerConneced = true;
}
catch
{
}

Re: Detect if scanner is connected?

Posted: Wed Sep 10, 2008 3:06 pm
by Alex
Yes, but you should specify correct exception type as follows:

Code: Select all

bScannerConneced = false;
Vintasoft.Twain.VSTwain td_Scanner = new Vintasoft.Twain.VSTwain();
try {
  td_Scanner.StartDevice();
  td_Scanner.OpenDataSource();
  bScannerConneced = true;
}
catch (TwainException)
{
}

Re: Detect if scanner is connected?

Posted: Wed Oct 01, 2008 8:47 am
by drosenhain
When I call OpenDataSource without having a scanner attached I get a dialog box (text below). This happens BEFORE the TwainException is caught and is fairly obviously being generated by the Canon scanner's TWAIN driver (not VintaSoftTwain). Setting ShowUI = false before doing the OpenDataSource doesn't help.

Any suggestions for overcoming this behaviour?

Regards
Dean Rosenhain

---------------------------
ScanGear CS
---------------------------
Cannot communicate with scanner.

Cable may be disconnected or scanner may be turned off.

Check status.

Scanner driver will be closed.
---------------------------
OK
---------------------------

Re: Detect if scanner is connected?

Posted: Wed Oct 01, 2008 10:11 am
by Alex
Hello Dean,

Unfortunately this dialog cannot be prevented because it's a custom dialog from the * of scanner.

Best regards, Alexander