예제 #1
0
 private void ConnectUsbDevice()
 {
     _usbDevice = UsbDevice.OpenUsbDevice(_myUsbFinder);
     if (_usbDevice != null)
     {
         IsAvailable = true;
         if (ArduinoUsbDeviceChangeNotifier != null)
         {
             ArduinoUsbDeviceChangeNotifier.Invoke(true, null);
         }
     }
     else
     {
         IsAvailable = false;
     }
 }
예제 #2
0
        private void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
        {
            if (e.Device.IdVendor == _vendorId && e.Device.IdProduct == _productId)
            {
                if (e.EventType == EventType.DeviceArrival)
                {
                    ConnectUsbDevice();
                }

                else if (e.EventType == EventType.DeviceRemoveComplete)
                {
                    _usbDevice  = null;
                    IsAvailable = false;
                    if (ArduinoUsbDeviceChangeNotifier != null)
                    {
                        ArduinoUsbDeviceChangeNotifier.Invoke(false, null);
                    }
                }
            }
        }