Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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;
                }
            }
        }