Beispiel #1
0
        private static IEnumerable <Tuple <string, DeviceHeritage> > GetKeyboardBasicData()
        {
            var interfaceGuid = new Guid(GuidInterfaceKeyboard);

            using (var deviceInfoSet = new DeviceInfoSet(interfaceGuid, Wrapper.GetDeviceInfoSetFlags.Present | Wrapper.GetDeviceInfoSetFlags.DeviceInterface))
            {
                foreach (var interfaceData in EnumerateDeviceInterfaces(deviceInfoSet, interfaceGuid))
                {
                    var deviceFileInstancePath = GetDeviceFileInstancePath(deviceInfoSet, interfaceData.Item2);

                    var deviceData = GetDeviceInfoData(deviceInfoSet, interfaceData.Item1);

                    var deviceInstancePath = deviceData.Item1
                        ? GetPropertyString(deviceInfoSet, deviceData.Item2, Wrapper.DevPropKey.DEVPKEY_Device_InstanceId)
                        : string.Empty;

                    var parentInstancePath = deviceData.Item1
                        ? GetPropertyString(deviceInfoSet, deviceData.Item2, Wrapper.DevPropKey.DEVPKEY_Device_Parent)
                        : string.Empty;

                    var grandParentInstancePath = deviceData.Item1
                        ? GetGrandParent(parentInstancePath)
                        : string.Empty;

                    var deviceHeritage = new DeviceHeritage
                    {
                        DeviceId            = deviceInstancePath,
                        ParentDeviceId      = parentInstancePath,
                        GrandParentDeviceId = grandParentInstancePath
                    };

                    yield return(new Tuple <string, DeviceHeritage>(deviceFileInstancePath, deviceHeritage));
                }
            }
        }
Beispiel #2
0
        private static string TryParseSerialNumber(DeviceHeritage deviceHeritage)
        {
            var result       = string.Empty;
            var regexPattern = new Regex(@".*vid_[a-fA-F0-9]{4}&pid_[a-fA-F0-9]{4}.{0,6}\\(\w{4,})", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant, TimeSpan.FromSeconds(1));

            foreach (var id in deviceHeritage)
            {
                var regexMatch = regexPattern.Match(id);
                if (!regexMatch.Success)
                {
                    continue;
                }

                result = regexMatch.Groups[1].Value; // first regex contains whole id so we pick the second one.
                break;
            }
            return(result);
        }