OpenDevice() 공개 메소드

public OpenDevice ( ) : void
리턴 void
예제 #1
2
        static void Main()
        {
            _device = HidDevices.Enumerate(VendorId, ProductId).FirstOrDefault();

            if (_device != null)
            {
                _device.OpenDevice();

                _device.Inserted += DeviceAttachedHandler;
                _device.Removed += DeviceRemovedHandler;

                _device.MonitorDeviceEvents = true;

                _device.ReadReport(OnReport);

                Console.WriteLine("Reader found, press any key to exit.");
                Console.ReadKey();

                _device.CloseDevice();
            }
            else
            {
                Console.WriteLine("Could not find reader.");
                Console.ReadKey();
            }
        }
        public bool OpenDevice()
        {
            var devices = HidDevices.Enumerate(VendorId);

            if (devices != null && devices.Any())
            {
                Device = devices.First();

                if (Device != null)
                {
                    Device.OpenDevice();

                    Device.Inserted += () =>
                    {
                        DeviceAttached();
                        Device.ReadReport(OnReportReceived);
                    };
                    Device.Removed += DeviceRemoved;
                    Device.MonitorDeviceEvents = true;

                    return true;
                }
            }

            return false;
        }
예제 #3
0
 private void Devices_SelectedIndexChanged(object sender, EventArgs e)
 {
     if ((_selectedDevice != null)) _selectedDevice.CloseDevice();
     _selectedDevice = _deviceList[Devices.SelectedIndex];
     _selectedDevice.OpenDevice();
     _selectedDevice.MonitorDeviceEvents = true;
     _selectedDevice.Inserted += Device_Inserted;
     _selectedDevice.Removed += Device_Removed;
 }
예제 #4
0
	    public Scanner(HidDevice hidDevice)
	    {
		    _scanner = hidDevice;

	        _scanner.Inserted += ScannerInserted;
            _scanner.Removed += ScannerRemoved;

		    if (!_scanner.IsOpen) _scanner.OpenDevice();
		    _scanner.MonitorDeviceEvents = true;

		    BeginReadReport();
	    }
예제 #5
0
        public bool Connect(HidDevice device)
        {
            scale = device;
            int waitTries = 0;
            scale.OpenDevice();

            while (!scale.IsConnected && waitTries < 10)
            {
                Thread.Sleep(50);
                waitTries++;
            }
            return scale.IsConnected;
        }
        public MainWindow()
        {
            InitializeComponent();

            device = HidDevices.Enumerate(vid, pid).FirstOrDefault();
            try
            {
                device.OpenDevice();
            }
            catch
            {
                valueSlider.IsEnabled = false;
            }
        }
예제 #7
0
        public WeatherStation(HidDevice hidDevice)
        {
            _weatherStation = hidDevice;

            _weatherStation.Inserted += _weatherStation_Inserted;
            _weatherStation.Removed += _weatherStation_Removed;

            if (!_weatherStation.IsOpen)
                _weatherStation.OpenDevice();

            _weatherStation.MonitorDeviceEvents = true;

            _history = new List<HistoryData>();
        }
예제 #8
0
        public bool Connect(HidDevice device)
        {
            scale = device;
              int waitTries = 0;
              scale.OpenDevice();

              // sometimes the scale is not ready immedietly after
              // Open() so wait till its ready
              while (!scale.IsConnected && waitTries < 10)
              {
            Thread.Sleep(50);
            waitTries++;
              }
              return scale.IsConnected;
        }
예제 #9
0
        private bool Connect()
        {
            _device = HidDevices.Enumerate(VendorId, ProductId, 0xFFAB, 0x0200).FirstOrDefault();
             if (_device != null)
             {
            _device.OpenDevice();
            _device.Inserted += DeviceAttachedHandler;
            _device.Removed += DeviceRemovedHandler;

            _device.MonitorDeviceEvents = true;
            _isAttached = true;
            PrintOutputLine("rawhid device found");
             }
             else
             {
            PrintOutputLine("no rawhid found");
            _isAttached = false;
             }
             return _isAttached;
        }
예제 #10
0
        /// <summary>
        /// Attempts to connect to a PowerMate device.
        /// 
        /// After a successful connection, a DeviceAttached event will normally be sent.
        /// </summary>
        /// <returns>True if a PowerMate device is connected, False otherwise.</returns>
        public bool OpenDevice()
        {
            device = HidDevices.Enumerate(VendorId, ProductId).FirstOrDefault();

            if (device != null)
            {
                connectedToDriver = true;
                device.OpenDevice();

                device.Inserted += DeviceAttachedHandler;
                device.Removed += DeviceRemovedHandler;

                device.MonitorDeviceEvents = true;

                device.ReadReport(OnReport); 

                return true;
            }

            return false;
        }
예제 #11
0
        public OpenLauncher()
        {
            initCommands();

            // Enumerate the devices
            deviceList = HidDevices.Enumerate(0x2123, 0x1010);

            if (deviceList.Count() < 1)
            {
                throw new Exception("Could not find device");
            }

            DevicePresent = true;

            dev1 = deviceList.FirstOrDefault();
            dev1.OpenDevice();
            dev1.Inserted += DeviceAttachedHandler;
            dev1.Removed += DeviceRemovedHandler;
            dev1.MonitorDeviceEvents = true;

            //dev1.CloseDevice();
        }
예제 #12
0
        /// <summary>
        ///     After a successful connection, a DeviceAttached event will normally be sent.
        /// </summary>
        /// <returns>True if a device is connected, False otherwise.</returns>
        public bool Connect()
        {
            //TODO: introduce a way to handle multiple devices throughout driver
            Devices = HidDevices.Enumerate(VendorId, ProductId);
            _device = Devices.FirstOrDefault();

            if (_device != null)
            {
                _connectedToDriver = true;
                _device.OpenDevice();

                _device.Inserted += DeviceAttachedHandler;
                _device.Removed += DeviceRemovedHandler;

                _device.MonitorDeviceEvents = true;

                _device.ReadReport(OnReport);

                return true;
            }

            return false;
        }
예제 #13
0
        public int proveraPumpi()
        {
            System.Windows.Threading.DispatcherTimer T = new System.Windows.Threading.DispatcherTimer();
            T.Tick += new EventHandler(dispatcherTimer_Tick);
            T.Interval = new TimeSpan(0, 0, 0, 0, 100);
            T.Start();

                //_deviceList = HidDevices.Enumerate().ToArray() ;
                //duzina = _deviceList.GetLength(0);
                //if (_deviceList[duzina].Equals(HidDevices.Enumerate(0x1234)))
                //{
            try
            {
                _selectedDevice = HidDevices.Enumerate(0x1234, 0x0021).First();
                _selectedDevice.OpenDevice();
                _selectedDevice.MonitorDeviceEvents = true;
                _selectedDevice.Inserted += Device_Inserted;
                _selectedDevice.Removed += Device_Removed;

                gaga = _selectedDevice.CreateReport();

                //var device = _selectedDevice;

                //device.OpenDevice();
                //device.MonitorDeviceEvents = true;

                // device.ReadReport(ReadProcess);
                _selectedDevice.ReadReport(ReadProcess);

                return 1;
            }
            catch { return 0; };
        }
예제 #14
0
 bool RenewTransport()
 {
     var newDevice = EnumerateHIDDevices(new[]
     {
         this._VendorProductIds
     }, _AcceptedUsageSpecifications)
     .FirstOrDefault(hid => hid.DevicePath == _DevicePath);
     if(newDevice == null)
         return false;
     _Device = newDevice;
     if(!_Device.IsOpen)
         _Device.OpenDevice();
     Init();
     return true;
 }
예제 #15
-1
        static void Main()
        {
            foreach (var productId in ProductIds)
            {
                _device = HidDevices.Enumerate(VendorId, productId).FirstOrDefault();

                if (_device == null) continue;

                _currentProductId = productId;

                _device.OpenDevice();

                _device.Inserted += DeviceAttachedHandler;
                _device.Removed += DeviceRemovedHandler;

                _device.MonitorDeviceEvents = true;

                _device.ReadReport(OnReport);
                break;
            }

            if (_device != null)
            {
                Console.WriteLine("Gamepad found, press any key to exit.");
                Console.ReadKey();
                _device.CloseDevice();
            }
            else
            {
                Console.WriteLine("Could not find a gamepad.");
                Console.ReadKey();
            }
        }
예제 #16
-1
 protected HIDTransportBase(HidDevice device, UsageSpecification[] acceptedUsageSpecifications)
 {
     if(!device.IsOpen)
         device.OpenDevice();
     _Device = device;
     _DevicePath = device.DevicePath;
     _VendorProductIds = new VendorProductIds(device.Attributes.VendorId, device.Attributes.ProductId);
     _AcceptedUsageSpecifications = acceptedUsageSpecifications;
     ReadTimeout = TimeSpan.FromMilliseconds(DEFAULT_TIMEOUT);
 }
예제 #17
-1
        /// <summary>
        /// Create a new Win7 forwaderer.
        /// </summary>
        /// <param name="dArgs"></param>
        public Win7Forwarder(Dictionary<String, String> dArgs)
        {
            // If the HID device is not loaded.
            if (pDevice == null)
            {
                // Access the HID device driver.
                pDevice = HidDevices.Enumerate(0xdddd, 0x0001).FirstOrDefault();
                if (pDevice == null)
                    throw new InvalidOperationException("Touchscreen HID driver was not found. Personal/non-commercial projects can use the compatible UniSoftHID driver.");

                // Open the HID device.
                try
                {
                    pDevice.OpenDevice(DeviceMode.Overlapped, DeviceMode.NonOverlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                }
                catch (Exception e)
                {
                    pDevice = null;
                    throw e;
                }
            }

            // Increment device count.
            iDeviceReferences++;

            // Pick a screen to inject onto.
            String sScreenIndex = null;
            if (!dArgs.TryGetValue("screen", out sScreenIndex))
                sScreenIndex = "0";

            if (!int.TryParse(sScreenIndex, out iScreenIndex))
                throw new ArgumentException("Cannot accept non-numeric screen index.");

            if (iScreenIndex < 0 || iScreenIndex >= lScreens.Count)
                throw new ArgumentException("Screen index out of range.");
        }