Detect if scanner is connected?

Questions, comments and suggestions concerning VintaSoftTwain.NET SDK.

Moderator: Alex

Detect if scanner is connected?

Postby rbourque » Tue Sep 09, 2008 12:22 pm

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

Re: Detect if scanner is connected?

Postby Alex » Wed Sep 10, 2008 7:27 am

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
Alex
Site Admin
 
Posts: 849
Joined: Thu Jul 10, 2008 11:21 am

Re: Detect if scanner is connected?

Postby rbourque » Wed Sep 10, 2008 11:48 am

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

Re: Detect if scanner is connected?

Postby Alex » Wed Sep 10, 2008 12:06 pm

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)
{
}
Alex
Site Admin
 
Posts: 849
Joined: Thu Jul 10, 2008 11:21 am

Re: Detect if scanner is connected?

Postby drosenhain » Wed Oct 01, 2008 5:47 am

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
---------------------------
drosenhain
 
Posts: 1
Joined: Wed Oct 01, 2008 5:38 am

Re: Detect if scanner is connected?

Postby Alex » Wed Oct 01, 2008 7:11 am

Hello Dean,

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

Best regards, Alexander
Alex
Site Admin
 
Posts: 849
Joined: Thu Jul 10, 2008 11:21 am


Return to VintaSoftTwain.NET SDK Discussions

Who is online

Users browsing this forum: No registered users and 1 guest

cron