Is there any way for the TWAIN API to detect if the scanner hardware is plugged-in?

Unfortunately, it is tricky and unlikely to check if a scanner is plugged in.

The reasons are:

  1. Our product gets the scanner sources from TWAIN Data Source Manager (or DSM, this is a common module of TWAIN, made available by the TWAIN Working Group) and gets the webcam sources from built-in UVC support (Windows).
  2. Most scanners have their sources shown in DSM whether it's connected or not. Only some of them hide the sources when they are not connected.
  3. Most if not all webcams hide their sources when they are not connected.
  4. Some scanners/webcams have 2 drivers (2 sources per device).

Because of the above:

  1. The property SourceCount doesn't indicate how many devices are installed or connected.
  2. When a source is shown in the list (especially when it's a scanner), it might not be connected.
  3. When you try to use a scanner that is not connected, the driver of the scanner might throw up a warning or error. Different devices have different behaviors.

Therefore, it's not a good idea to check whether a source is valid (meaning the device is connected and powered on) in code. Instead, you can put a friendly note that says "please make sure the device is hooked up and its driver installed".

Is this page helpful?

Leave a Reply

Your email address will not be published.