0

I'm developing a scanning application and I'd like to enable the Scan button only when my/any scanner is available.

I tried achieve this with GdPicture but without any success (btw. it's really poor library, don't use it). I also tried to get some kind of similar event using Atalasoft's TWAIN and lower-level TWAIN library (which I found thanks to that post). None worked.

I also have an idea to detect new devices connected to the computer and than rescan for TWAIN devices but maybe anyone of you know better solution. Any ideas?

Community
  • 1
  • 1
SOReader
  • 5,697
  • 5
  • 31
  • 53

1 Answers1

0

You may need to write a wrapper yourself for a scanner. If the above mentioned libraries have no API to tell the scanner's status, you can try to connect to the scanner, if you get connected it means the scanner is up. I think they provide connection API for a scanner.

Kamran Amini
  • 1,062
  • 8
  • 14
  • Hmm, you can't do it like this. If the scanner is not connected to your pc you can't open a connection to it. What I need is some kind of an event when a new device has been connected. – SOReader Jun 05 '12 at 07:57
  • 1
    Sure, but I don't think you can find a framework which does it for you. All I feel is that you have to implement it yourself. Behind an event oriented system there are some kind of monitoring or interrupt. – Kamran Amini Jun 05 '12 at 08:11
  • @SOReader The connection notification was what I tried to implement in my scanning application. But it turned out to be a difficult work...but personally, it is not a must feature for my scanning application. I was able to detect if there are any scanner drivers available (though the scanner itself might not be physically connected). If not, then I will grey out the Scan Button. This idea actually works fine. BTW, I am using [Dynamsoft's NET TWAIN](http://www.dynamsoft.com/Products/.Net-TWAIN-Scanner.aspx)...works great. – Logan Jun 06 '12 at 04:05
  • @SOReader, I don't think there is direct API available to achieve your requirements. However, you can try the following workaround: 1. Detect whether a TWAIN driver is available on the machine. 2. Once a driver is detected, you can try to open the source. 3. If you fail to open the selected source (open source returns false), you can grey out the Scan button. Logan, I'm working for Dynamsoft. Let me know if you have any questions. – Windy Jun 06 '12 at 05:15
  • @Windy: Sure but then you'll have to do it periodically (polling) :( – SOReader Jun 06 '12 at 09:04
  • @SOReader: True. Instead of greying out the button, have you considered adding a message behind the Scan button (for instance, "The scanner is not available.")? – Windy Jun 06 '12 at 09:45
  • 1
    Btw. for some scanners (its drivers, to be precise) TryOpen solution won't work because if you try to open a connection a window will pop up asking to pick another device. I couldn't find a way to stop it. – SOReader Jun 06 '12 at 09:46
  • Have you tired to use the native dll of your vendor ?! Usually the applications come with scanners can detect the status of the device but they are not using the wrappers and middle interfaces. Maybe you should try to use native dlls of the vendor. But you will be limited to a few vendors whom you can use their native files. – Kamran Amini Jun 06 '12 at 11:43
  • @Kamran: no, I haven't because I can't do it. The application should work with any TWAIN scanner and I can't really manually support all the possible vendors :( – SOReader Jun 06 '12 at 13:28
  • @Windy SOReader is right. For most scanner drivers I have tested with so for, OpenSource() method always returns a pop up windows showing that the device is not ready/available. Perhaps there is no way to detect the availability of each device :) – Logan Jun 08 '12 at 03:55