public bool IsConnected() { if (_device == null) { var devices = HidDevice.Enumerate() .Select(de => new HidDevice(de)); var connected = devices .Where(d => d.Attributes != null) .FirstOrDefault(d => d.Attributes.VendorId == _vendorId && d.Attributes.ProductId == _productId); if (connected != null) _device = connected; } return _device != null; }
private void monitor_Removed() { if (_device != null) { var devices = HidDevice.Enumerate() .Select(de => new HidDevice(de)); var connected = devices .Where(d => d.Attributes != null) .FirstOrDefault(d => d.Attributes.VendorId == _vendorId && d.Attributes.ProductId == _productId); if (connected == null) { _device.Dispose(); _device = null; } } }