コード例 #1
0
ファイル: HidMonitor.cs プロジェクト: tu-nv/mi-360
        private void SearchForDevice(object state)
        {
            var devices = HidDevices
                          .EnumeratePaths(_Filter)
                          .ToArray();

            // Get all the devices that has connected since the last check
            var newDevices = devices.Except(_SeenDevices);

            // Get all the device that has disconnected since the last check
            var removedDevices = _SeenDevices.Except(devices);

            foreach (var device in newDevices)
            {
                _Logger.Information("Detected attached HID devices matching filter {Filter}", _Filter);
                DeviceAttached?.Invoke(this, device);
            }

            foreach (var device in removedDevices)
            {
                _Logger.Information("Detected removed HID devices matching filter {Filter}", _Filter);
                DeviceRemoved?.Invoke(this, device);
            }

            _SeenDevices = devices;
        }
コード例 #2
0
        internal void AddDevice(UsbManager usbManager, UsbDevice usbDevice)
        {
            var serialDevice = GetDevice(usbManager, usbDevice, AllowAnonymousCdcAcmDevices);

            if (serialDevice != null)
            {
                lock (_attachedDevicesSyncRoot)
                {
                    AttachedDevices.Add(serialDevice);
                    DeviceAttached?.Invoke(this, new UsbSerialDeviceEventArgs(serialDevice));
                }
            }
        }
コード例 #3
0
        private void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            while (port.BytesToRead >= 4 && port.BytesToRead % 4 == 0)
            {
                byte[] packet = new byte[4];
                int    read   = port.Read(packet, 0, 4);
                InterfaceDebugger.DataReceived(packet);
                switch (packet[0])
                {
                case 0x00:
                {
                    break;
                }

                case 0x01:
                {
                    IVirtualDevice device = GetDevice(packet);
                    bool           found  = false;
                    for (int i = 0; i < Subdevices.Count; i++)
                    {
                        if (Subdevices[i].Id == packet[2])         //if the device already exists, update it
                        {
                            Subdevices[i] = device;
                            found         = true;
                        }
                    }
                    //if the device doesn't already exist, add it
                    if (!found)
                    {
                        devices.Add(device);
                    }

                    //sort the list on the device ID
                    devices = devices.OrderBy(o => o.Id).ToList();
                    DeviceAttached?.Invoke(this, new VirtualDeviceEventArgs(device));
                    break;
                }

                case 0x02:
                {
                    //device sends a report
                    if (packet[1] > devices.Count - 1)
                    {
                        break;
                    }
                    devices[packet[1]].ReceivePacket(packet);
                    break;
                }
                }
            }
        }
コード例 #4
0
        /// <summary>
        ///     Overrided Window procedure
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="msg"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <param name="handled"></param>
        /// <returns></returns>
        private IntPtr HwndSourceHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg != WM_DEVICECHANGE)
            {
                return(IntPtr.Zero);
            }

            switch ((int)wParam)
            {
            case DBT_DEVICEARRIVAL:
            {
                var info =
                    (DEV_BROADCAST_DEVICEINTERFACE)
                    Marshal.PtrToStructure(lParam, typeof(DEV_BROADCAST_DEVICEINTERFACE));

                DeviceAttached?.Invoke(this,
                                       new FireShockDetectorEventArgs(new Guid(info.dbcc_classguid), new string(info.dbcc_name)));
            }
            break;

            case DBT_DEVICEREMOVECOMPLETE:
            {
                var info =
                    (DEV_BROADCAST_DEVICEINTERFACE)
                    Marshal.PtrToStructure(lParam, typeof(DEV_BROADCAST_DEVICEINTERFACE));

                DeviceRemoved?.Invoke(this,
                                      new FireShockDetectorEventArgs(new Guid(info.dbcc_classguid), new string(info.dbcc_name)));
            }
            break;

            case DBT_DEVNODES_CHANGED:
                break;
            }

            return(IntPtr.Zero);
        }
コード例 #5
0
        private void SearchForDevice(object state)
        {
            var devices = HidDevices
                          .EnumeratePaths(_Filter)
                          .ToArray();

            // Get all the devices that has connected since the last check
            var newDevices = devices.Except(_SeenDevices);

            // Get all the device that has disconnected since the last check
            var removedDevices = _SeenDevices.Except(devices);

            foreach (var device in newDevices)
            {
                DeviceAttached?.Invoke(this, device);
            }

            foreach (var device in removedDevices)
            {
                DeviceRemoved?.Invoke(this, device);
            }

            _SeenDevices = devices;
        }
コード例 #6
0
        protected override void WndProc(ref Message msg)
        {
            if (msg.Msg == WM_DEVICECHANGE)
            {
                var info       = (DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(msg.LParam, typeof(DEV_BROADCAST_DEVICEINTERFACE));
                var devicePath = new string(info.dbcc_name);

                switch (msg.WParam.ToInt64())
                {
                case DBT_DEVICEARRIVAL:
                    DeviceAttached?.Invoke(this, devicePath);
                    break;

                case DBT_DEVICEREMOVECOMPLETE:
                    DeviceRemoved?.Invoke(this, devicePath);
                    break;

                case DBT_DEVNODES_CHANGED:
                    break;
                }
            }

            base.WndProc(ref msg);
        }
コード例 #7
0
ファイル: DeviceChangeNotifier.cs プロジェクト: etfovac/hid
 private void ReportDeviceAttached(Message message)
 {
     DeviceAttached?.Invoke(this, null);
     DeviceNotify?.Invoke(this, new EventArgs <Message>(message));
 }
コード例 #8
0
 private void onDeviceAttched(EventArgs e)
 {
     DeviceAttached?.Invoke(this, e);
 }