private void USBPort_USBDeviceRemoved(object sender, UsbClass.UsbDeviceEventArgs e) { if (!UsbClass.GetUsbDevice(MyDeviceVid, MyDevicePid, ref _listOfUsbList, false)) { //My Device is removed _myUsbDeviceConnected = false; Disconnect(); } }
private UsbSerialDeviceInfo FindDeviceInfo(UsbSerialDeviceID id, UsbClass usbClass, bool allowAnonymousCdcAcmDevices) { if (AvailableDeviceInfo.ContainsKey(id)) { return(AvailableDeviceInfo[id]); } if (allowAnonymousCdcAcmDevices && usbClass == UsbClass.Comm) { return(UsbSerialDeviceInfo.CdcAcm); } return(null); }
private const uint MyDevicePid = 0X6001; //FTDI 245R PID #region USB /// <summary> /// Try to connect to the device. /// </summary> /// <returns>True if success, false otherwise</returns> private bool UsbTryMyDeviceConnection() { uint? mi = null; const bool bGetSerialPort = true; if (UsbClass.GetUsbDevice(MyDeviceVid, MyDevicePid, ref _listOfUsbList, bGetSerialPort, mi)) { Connect(); return(true); } else { Disconnect(); return(false); } }
public EverDriveUSB() { Connection = new Connection(); //Throttle = new Throttle(Connection.IoPort); //LocoProgrammer = new LocoProgrammer(Connection.IoPort); //USB Connection _usbPort = new UsbClass(); _listOfUsbList = new List <UsbClass.DeviceProperties>(); _usbPort.UsbDeviceAttached += USBPort_USBDeviceAttached; _usbPort.UsbDeviceRemoved += USBPort_USBDeviceRemoved; //USB Connection (A class library doesnt have a window, so we will pass a fake one!) var source = new HwndSource(0, 0, 0, 0, 0, "fakeWindow", IntPtr.Zero); source.AddHook(WndProc); _usbPort.RegisterForDeviceChange(true, source.Handle); UsbTryMyDeviceConnection(); _myUsbDeviceConnected = false; }