private static bool FindHIDs(DeviceInformationStructure deviceInformation, List <string> InputList, ref List <string> FoundList) { List <SingleDevice> devices = FindDevices(deviceInformation); if (devices.Count > 0) { foreach (SingleDevice sdev in devices) { SingleHID singleHID = new SingleHID(sdev); foreach (string path in InputList) { Match match = Regex.Match(path, "VID_(.{4})", RegexOptions.IgnoreCase); ushort Vid; if (match.Success) { string vid_string = match.Groups[1].Value; Vid = ushort.Parse(vid_string, System.Globalization.NumberStyles.HexNumber); } else { Vid = 0; } match = Regex.Match(path, "PID_(.{4})", RegexOptions.IgnoreCase); ushort Pid; if (match.Success) { string pid_string = match.Groups[1].Value; Pid = ushort.Parse(pid_string, System.Globalization.NumberStyles.HexNumber); } else { Pid = 0; } match = Regex.Match(path, "MI_(.{2})", RegexOptions.IgnoreCase); ushort MI; if (match.Success) { string mi_string = match.Groups[1].Value; MI = ushort.Parse(mi_string, System.Globalization.NumberStyles.HexNumber); } else { MI = 0; } bool Detected = (Vid == singleHID.Vid) && (Pid == singleHID.Pid) && (MI == singleHID.MI); if (Detected) { FoundList.Add(path); //break; // Matching device found Debug.WriteLine("findTargetDevice() -> Device with matching VID and PID found!"); } } } } return(FoundList.Count > 0); }
private static bool CheckDevice(DeviceInformationStructure dev1, SingleHID dev2) { bool Found = false; if (dev1.TargetCaption == dev2.Caption && dev1.TargetProductId == dev2.Pid && dev1.TargetVendorId == dev2.Vid && dev1.TargetMultiInterface == dev2.MI) { Found = true; } return(Found); }