Exemple #1
0
        private void GPSReader_Load(object sender, EventArgs e)
        {
            try
            {
                #region 检测USB设备
                showGPS = new ShowGPSData(show_GPSData);//初始化委托

                device.TargetVendorId  = 0x46d;
                device.TargetProductId = 0xc077;

                device.TargetVendorId  = 0x413c;
                device.TargetProductId = 0x2107;

                // device.TargetVendorId = 0x091E;
                //device.TargetProductId = 0xc077;

                bool DevFound = DeviceDiscovery.FindTargetDevice(ref device);
                if (DevFound)
                {
                    MessageBox.Show("检测到USB外设!", "测试测试", MessageBoxButtons.YesNoCancel,
                                    MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                }
                #endregion
            }
            catch (Exception ex)
            {
                Log.WriteLog.Write("GPSReader_USB", "GPSReader_Load", ex.Message);
            }
        }
Exemple #2
0
 private void DeviceChangeNotifierDeviceAttached()
 {
     if (IsDeviceConnected)
     {
         Disconnect();
     }
     DeviceDiscovery.FindTargetDevice(ref _deviceInformation);
 }
Exemple #3
0
        public UsbHidDevice(string devicePath)
        {
            _deviceInformation.DevicePathName = devicePath;

            _worker         = new BackgroundWorker();
            _worker.DoWork += WorkerDoWork;
            if (DeviceDiscovery.FindTargetDevice(ref _deviceInformation))
            {
                _worker.RunWorkerAsync();
            }

            _deviceInformation.ConnectedChanged += DeviceConnectedChanged;
            DeviceChangeNotifier.DeviceAttached += DeviceChangeNotifierDeviceAttached;
            DeviceChangeNotifier.DeviceDetached += DeviceChangeNotifierDeviceDetached;
        }
Exemple #4
0
 public bool Connect()
 {
     DeviceDiscovery.FindTargetDevice(ref _deviceInformation);
     return(IsDeviceConnected);
 }