Unfortunately, it is tricky and unlikely to check if a scanner is plugged in.
The reasons are:
- 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).
- 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.
- Most if not all webcams hide their sources when they are not connected.
- Some scanners/webcams have 2 drivers (2 sources per device).
Because of the above:
- The property SourceCount doesn't indicate how many devices are installed or connected.
- When a source is shown in the list (especially when it's a scanner), it might not be connected.
- 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".