Ejemplo n.º 1
0
        private DeviceInterface FindDevice()
        {
            Guid hidGuid = DeviceInformationSet.GetHidGuid();

            using (var deviceInformationSet = new DeviceInformationSet(hidGuid, DiGetClassFlags.Present | DiGetClassFlags.DeviceInterface))
            {
                DeviceInterface deviceInterface = deviceInformationSet.GetDeviceInterfaces(hidGuid)
                                                  .Where(d => d.IsValidUsbDevice)
                                                  .FirstOrDefault(dis => dis.Details.DevicePath.Contains(VendorId) && dis.Details.DevicePath.Contains(ProductId));
                if (deviceInterface == null)
                {
                    _log.Debug("device not found");
                }
                else
                {
                    _log.Debug("device found: " + deviceInterface.Details.DevicePath);
                }
                return(deviceInterface);
            }
        }
Ejemplo n.º 2
0
        private bool TryOpen(int blockSize)
        {
            Dispose();

            DeviceInterface deviceInterface;
            Guid            hidGuid = DeviceInformationSet.GetHidGuid();

            using (var deviceInformationSet = new DeviceInformationSet(hidGuid, DiGetClassFlags.Present | DiGetClassFlags.DeviceInterface))
            {
                deviceInterface = deviceInformationSet.GetDeviceInterfaces(hidGuid)
                                  .Where(d => d.IsValidUsbDevice)
                                  .FirstOrDefault(dis => (dis.Details.DevicePath.Contains("16c0") && dis.Details.DevicePath.Contains("0478")) ||
                                                  (dis.Details.DevicePath.Contains("03eb") && dis.Details.DevicePath.Contains("2067")));
                if (deviceInterface != null)
                {
                    _handle = deviceInterface.OpenFile(blockSize + 3);
                    return(true);
                }

                return(false);
            }
        }