Detect if scanner is connected?

Questions, comments and suggestions concerning VintaSoft Twain .NET SDK.

Moderator: Alex

Post Reply
rbourque
Posts: 2
Joined: Tue Sep 09, 2008 3:00 am

Detect if scanner is connected?

Post 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.
Alex
Site Admin
Posts: 2314
Joined: Thu Jul 10, 2008 2:21 pm

Re: Detect if scanner is connected?

Post 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
rbourque
Posts: 2
Joined: Tue Sep 09, 2008 3:00 am

Re: Detect if scanner is connected?

Post 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
{
}
Alex
Site Admin
Posts: 2314
Joined: Thu Jul 10, 2008 2:21 pm

Re: Detect if scanner is connected?

Post 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)
{
}
drosenhain
Posts: 1
Joined: Wed Oct 01, 2008 8:38 am

Re: Detect if scanner is connected?

Post 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
---------------------------
Alex
Site Admin
Posts: 2314
Joined: Thu Jul 10, 2008 2:21 pm

Re: Detect if scanner is connected?

Post by Alex »

Hello Dean,

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

Best regards, Alexander
Post Reply