Created
August 29, 2024 09:45
-
-
Save unseensenpai/e1f73fc611ed35d6663c228dccf1b679 to your computer and use it in GitHub Desktop.
WIA Device No Finder (TWAIN SOURCE)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace WIAHelper; | |
| public class WIAHelper | |
| { | |
| readonly DeviceManager _deviceManager; | |
| public WIAHelper() | |
| { | |
| _deviceManager = new DeviceManager(); | |
| } | |
| private int FindDeviceNo(string deviceName, string devicePropertyName, WiaDeviceType? wiaDeviceType = null) | |
| { | |
| int deviceNo = 0; | |
| int deviceCount = _deviceManager.DeviceInfos.Count; | |
| for (int i = 1; i <= deviceCount; i++) // WIA Indexes Starts with 1 | |
| { | |
| object index = i; | |
| DeviceInfo deviceInfo = _deviceManager.DeviceInfos.get_Item(ref index); | |
| foreach (Property item in deviceInfo.Properties) | |
| { | |
| object propertyItemValue = item.get_Value(); | |
| if (item.Name.ToString().Contains(devicePropertyName, StringComparison.OrdinalIgnoreCase) && (wiaDeviceType == null || deviceInfo.Type == wiaDeviceType)) | |
| { | |
| object propertyNameValue = item.get_Value(); | |
| if (propertyNameValue is not null) | |
| { | |
| string propertyName = propertyNameValue.ToString(); | |
| if (propertyName.Contains(deviceName, StringComparison.OrdinalIgnoreCase)) | |
| { | |
| deviceNo = i; | |
| return deviceNo; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| return deviceNo; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: