/// <summary> /// Checks the devices that are present at the moment and checks if one of those /// is the device you defined by filling in the product id and vendor id. /// </summary> public void CheckDevicePresent() { try { //Mind if the specified device existed before. bool history = false; if (specified_device != null) { history = true; } specified_device = HIDDevice.FindDevice(VendorId, ProductId, CreateDevice()); // look for the device on the USB bus if (specified_device != null) // did we find it? { if (OnSpecifiedDeviceArrived != null) { this.OnSpecifiedDeviceArrived(this, new EventArgs()); } specified_device.DataReceived += new DataReceivedEventHandler(DataRecieved); specified_device.DataSent += new DataSentEventHandler(DataSend); } else { if (OnSpecifiedDeviceRemoved != null && history) { this.OnSpecifiedDeviceRemoved(this, new EventArgs()); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static SpecifiedDevice FindSpecifiedDevice(int vendor_id, int product_id) => ((SpecifiedDevice)HIDDevice.FindDevice(vendor_id, product_id, typeof(SpecifiedDevice)));