예제 #1
0
파일: Form1.cs 프로젝트: wpmyj/csharp
 //设备变化消息相应函数
 private void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
 {
     if (e.EventType == EventType.DeviceArrival)
     {
         ShowMsg(string.Format("发现有新USB设备连接,PID = 0x{0:X},VID = 0x{1:X}.\r\n设备的详细信息{2}", e.Device.IdProduct, e.Device.IdVendor, e.Device.ToString()));
         //看看目前新连接的USB设备是不是目标设备
         if (e.Device.IdProduct == myPID && e.Device.IdVendor == myVID)
         {
             ShowMsg("该USB设备是目标设备");
             //发现目标设备并打开该设备
             FindAndOpenUSB(myPID, myVID);
         }
         else
         {
             ShowMsg("该USB设备不是目标设备\r\n");
         }
     }
     else if (e.EventType == EventType.DeviceRemoveComplete)
     {
         ShowMsg(string.Format("发现有USB设备移除,PID = 0x{0:X}, VID = 0x{1:X}\r\n设备的详细信息{2}", e.Device.IdProduct, e.Device.IdVendor, e.Device.ToString()));
         //看看目前移除的USB设备是不是目标设备
         if (e.Device.IdProduct == myPID && e.Device.IdVendor == myVID)
         {
             ShowMsg(string.Format("移除的USB设备是目标设备\r\n"));
             CloseUSB();
         }
         else
         {
             ShowMsg(string.Format("移除的USB设备不是目标设备\r\n"));
         }
     }
 }
예제 #2
0
 private void UsbDeviceNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
 {
     this.Dispatcher.BeginInvoke((Action) delegate()
     {
         buttonRefresh_Click(null, null);
     }, null);
 }
예제 #3
0
        private void IOnUsbNotify(object sender, DeviceNotifyEventArgs e)
        {
            DeviceID id = new DeviceID(e.Device);

            // Do we give any shits about this device?
            if (!DeviceFactory.Contains(id.Vendor, id.Product))
            {
                return;
            }

            // Wazzup?
            switch (e.EventType)
            {
            case EventType.DeviceArrival: {
                IInitDevice(id, DeviceEventType.DeviceAdded);
                break;
            }

            case EventType.DeviceQueryRemove: {
                ResponseDevice device    = m_devices[id];
                bool           canRemove = device.IBeginSoftRemoval();
                /// TODO: deny this request
                break;
            }

            case EventType.DeviceRemoveComplete: {
                IDestroyDevice(id);
                break;
            }
            }
        }
예제 #4
0
        /// <summary>
        /// 设备事件触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void onDevNotify(object sender, DeviceNotifyEventArgs e)
        {
            try
            {
                switch (e.DeviceType)
                {
                case DeviceType.DeviceInterface:
                    var myDevice = (IUsbDeviceNotifyInfo)e.Object;

                    switch (e.EventType)
                    {
                    case EventType.DeviceArrival:
                        DeviceArrival(myDevice);
                        break;

                    case EventType.DeviceRemoveComplete:
                        DeviceRemove(myDevice);
                        break;
                    }

                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("设备热插拔事件触发异常" + "{0}异常信息:{1}", FileUtils.NEW_LINE_SPACE, ex));
            }
        }
 /// <summary>
 /// Called whenever a usb device is plugged in or unplugged
 /// </summary>
 void deviceNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
 {
     // Detected a device, try to see if it is the traqpaq
     if (e.EventType == EventType.DeviceArrival)  // check for device arrival
     {
         //MessageBox.Show(e.Device.IdProduct.ToString() + "\n" + e.Device.IdVendor.ToString());
         if (traqpaq == null)
         {//TODO could also check for specifics with the e.Device..... properties
             // try to connect again
             try
             {
                 traqpaq = new TraqpaqDevice();
                 statusBarItemTraqpaq.Content = "Device connected";
                 oneTimeRead();
                 autoReadTimer.Start();
             }
             catch (TraqPaqNotConnectedException) { }    // Silently fail
         }
     }
     else if (e.EventType == EventType.DeviceRemoveComplete)
     {
         //TODO use this to disconnect the device. The event handler would need to be created regardless
         //of wether or not the device is connected at first though.
         if (traqpaq.MyUSBDevice.IsOpen)
         {
             traqpaq.MyUSBDevice.Close();
             statusBarItemTraqpaq.Content = "Device not found";
             autoReadTimer.Stop();
         }
     }
 }
예제 #6
0
 private void DeviceNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
 {
     //UsbPortTree.RefreshUsbPort();
     //if (this.InvokeRequired)
     //{
     //this.BeginInvoke(new UpdateUIStatusDelegate(() =>
     //{
     //    label1.Text = "";
     //    UsbPortTree.RefreshUsbPort();
     //    foreach (var device in UsbPortTree.ConnectedAndroidDevices)
     //    {
     //        label1.Text += $"{device.Port_Path}\n{device.Port_Index}\n{device.Product}\n{device.SerialNumber}\n\n";
     //    }
     //}), null);
     //}
     //else
     //{
     //    //label1.Text = "";
     //    //UsbPortTree.RefreshUsbPort();
     //    //foreach (var device in UsbPortTree.ConnectedAndroidDevices)
     //    //{
     //    //    label1.Text += $"{device.Port_Path}\n{device.Port_Index}\n{device.Product}\n{device.SerialNumber}\n\n";
     //    //}
     //}
 }
예제 #7
0
        private void sbSave_Click(object sender, EventArgs e)
        {
            SimpleButton[] buttons = { sbRefresh, sbSave };
            ButtonEnable(false, buttons);
            //获取旧的参数,保存失败则回溯
            DTDeviceInfo dt = DeviceCommViewModel.VM.AnalysisEntities;

            bool rs = SaveDeviceComChanges(
                (DeviceName)Enum.Parse(typeof(DeviceName), cName),
                cbeCommunication.Text,
                ceUsedPm.Checked ? "1" : "0"
                );

            if (!rs)
            {
                BackDeviceComChanges(dt);
            }
            ButtonEnable(true, buttons);
            RefreshUI();
            if (!rs)
            {
                return;
            }

            DeviceNotifyEventArgs args = new DeviceNotifyEventArgs();

            args.Key   = "AnalysisDevice";
            args.Param = rs;
            onDeviceNotify(args);
        }
예제 #8
0
        private void sbSave_Click(object sender, EventArgs e)
        {
            SimpleButton[] buttons = { sbRefresh, sbSave };
            ButtonEnable(false, buttons);
            //获取旧的参数,保存失败则回溯
            DTDeviceInfo dt = DeviceCommViewModel.VM.PlatEntities;
            PlatParam    pp = new PlatParam();

            pp.platNum           = tePlatNumber.Text.ToString();
            pp.unloadInvalidData = ceUnloadData.Checked;
            string param = JsonNewtonsoft.ToJSON(pp);

            bool rs = SaveDeviceComChanges(
                DeviceCommViewModel.DeviceName.Plat,
                cbeCommunication.Text, null, param);

            if (!rs)
            {
                BackDeviceComChanges(dt);
            }
            ButtonEnable(true, buttons);
            RefreshUI();
            if (!rs)
            {
                return;
            }

            DeviceNotifyEventArgs args = new DeviceNotifyEventArgs();

            args.Key   = "PlatDevice";
            args.Param = param;
            onDeviceNotify(args);
        }
예제 #9
0
        //called at init, and each time a system event occurs
        private void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
        {
            switch (e.EventType)
            {
            case EventType.DeviceArrival:
                C.Logger.Debug("LibUSB device arrival");
                if (e.Device == null || e.Device.IdVendor != VID || !PIDs.Contains(e.Device.IdProduct))
                {
                    C.Logger.Debug("Not taking this device, PID/VID not a smartscope");
                    return;
                }

                UsbDeviceFinder usbFinder = new UsbDeviceFinder(e.Device.IdVendor, e.Device.IdProduct, e.Device.SerialNumber);
                UsbDevice       usbDevice = UsbDevice.OpenUsbDevice(usbFinder);
                if (usbDevice != null)
                {
                    DeviceFound(usbDevice);
                }
                break;

            case EventType.DeviceRemoveComplete:
                C.Logger.Debug(String.Format("LibUSB device removal [VID:{0},PID:{1}]", e.Device.IdVendor, e.Device.IdProduct));
                if (e.Device != null && e.Device.IdVendor == VID && PIDs.Contains(e.Device.IdProduct))
                {
                    RemoveDevice(e.Device.SerialNumber);
                }
                break;

            default:
                C.Logger.Debug("LibUSB unhandled device event [" + Enum.GetName(typeof(EventType), e.EventType) + "]");
                break;
            }
        }
예제 #10
0
        private void sbSave_Click(object sender, EventArgs e)
        {
            SimpleButton[] buttons = { sbRefresh, sbSave };
            ButtonEnable(false, buttons);
            //获取旧的参数,保存失败则回溯
            DTDeviceInfo dt = DeviceCommViewModel.VM.GPSEntities;

            bool rs = SaveDeviceComChanges(
                DeviceCommViewModel.DeviceName.GPS,
                cbeCommunication.Text,
                ceUsed.Checked ? "1" : "0");

            if (!rs)
            {
                BackDeviceComChanges(dt);
            }
            ButtonEnable(true, buttons);
            RefreshUI();
            if (!rs)
            {
                return;
            }

            DeviceNotifyEventArgs args = new DeviceNotifyEventArgs();

            args.Key   = "GPSDevice";
            args.Param = rs;
            onDeviceNotify(args);
            //if (rs) XtraMessageBox.Show("保存成功");
            //else XtraMessageBox.Show("保存失败");
        }
예제 #11
0
        private void devNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
        {
            EventType eventType = e.EventType;
            //e.DeviceType;
            IUsbDeviceNotifyInfo device = e.Device;
            IVolumeNotifyInfo    volume = e.Volume;

            if ((int)eventType == 32768 && volume != null)
            {
                this.USBDrive = volume.Letter;
                this.Callback(this, new CmdCiteEventArgs(DEV_ACTIONS.IS_USB));
            }
            if ((int)eventType == 32768)
            {
                if (device.ClassGuid.Equals(Guid.Parse("a5dcbf10-6530-11d2-901f-00c04fb951ed")))
                {
                    this.MountDevice();
                }
                if (!string.IsNullOrEmpty(volume.Letter))
                {
                    this.USBDrive = volume.Letter;
                }
            }
            if ((int)eventType == 32772)
            {
                this.IsConnected = false;
                this.Callback(this, new CmdCiteEventArgs(DEV_ACTIONS.DISCONNECTED));
            }
        }
예제 #12
0
        void MultiPointObject_DeviceArrivalEvent(object sender, DeviceNotifyEventArgs e)
        {
            DeviceInfo            mouseObject   = e.DeviceInfo;
            MultipointMouseDevice mpMouseDevice = mouseObject.DeviceVisual;
            Bitmap cursorBitmap = GetCursorImage(MultipointSdk.Instance.MouseDeviceList.Count);

            mpMouseDevice.CursorImage = ConvertBitmapToBitmapImage(cursorBitmap);
        }
예제 #13
0
 /// <summary>
 /// notify to parent
 /// </summary>
 protected bool onDeviceNotify(DeviceNotifyEventArgs e)
 {
     e.Result = true;
     if (DeviceNotify != null)
     {
         DeviceNotify(this, e);
     }
     return(e.Result);
 }
        private static void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
        {
            if (e.EventType.ToString() == "DeviceArrival")
            {
                Console.WriteLine("\n Device Connected");

                GenerateUDIDs();
            }
        }
예제 #15
0
        private static void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
        {
            bool connected = false;

            // A Device system-level event has occured
            connected = tool.GetUSBConnectState();
            if (connected != MainWindow.GetInstance().IsConnected)
            {
                MainWindow.GetInstance().IsConnected = connected;
            }
        }
예제 #16
0
파일: Form1.cs 프로젝트: zoobab/CH554
        private void OnDevNotify(object sender, DeviceNotifyEventArgs e)
        {
            object[] o = new object[] { e.EventType.ToString(), DateTime.Now.ToString(), e.DeviceType.ToString(), e.Object.ToString() };
            string   s = String.Format("{0} - Time: {1}  -  {2}\r\n{3}", o);

            if (e.DeviceType == DeviceType.DEVICEINTERFACE && e.EventType == EventType.DEVICEARRIVAL)
            {
                s += "\r\n" + e.Device.SymbolicName.FullName;
            }
            tNotify.Text += s;
        }
예제 #17
0
        private static void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
        {
            // A Device system-level event has occured

            Console.SetCursorPosition(0, Console.CursorTop);

            Console.WriteLine(e.ToString()); // Dump the event info to output.

            Console.WriteLine();
            Console.Write("[Press any key to exit]");
        }
 private void UsbDeviceNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
 {
     try
     {
         Debug.WriteLine(string.Format("UsbEvent --> {0}, {1}", e.EventType, e.DeviceType));
         _deviceUpdatetimer.Start();
     }
     catch (Exception ex)
     {
         Debug.WriteLine("UsbDeviceNotifier_OnDeviceNotify Exception: " + ex.Message);
     }
 }
예제 #19
0
 void HandleUsbDeviceNotifierOnDeviceNotify(object sender, DeviceNotifyEventArgs e)
 {
     if (e.Device.IdVendor == GARMIN_VID)
     {
         var       device_finder   = new UsbDeviceFinder(e.Device.IdVendor, e.Device.IdProduct);
         var       device_registry = UsbDevice.AllDevices.Find(device_finder);
         UsbDevice device;
         if (device_registry.Open(out device))
         {
             DeviceAdded(new GarminUnit(device));
         }
     }
 }
예제 #20
0
파일: Form1.cs 프로젝트: longzai2651/USB
 private void UsbDeviceNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
 {
     if (e.EventType == EventType.DeviceArrival)
     {
         Console.WriteLine("usb DeviceArrival");
         new Thread(() => { Thread.Sleep(500); InitUSB(); }).Start();
     }
     else if (e.EventType == EventType.DeviceRemoveComplete)
     {
         Console.WriteLine("usb Remove");
         CloseUSB();
     }
 }
예제 #21
0
 public void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
 {
     // A Device system-level event has occured
     if (e.EventType == EventType.DeviceArrival)
     {
         USB_State      = "连接";
         USB_StateColor = new SolidColorBrush(Colors.Blue);
     }
     else if (e.EventType == EventType.DeviceRemoveComplete)
     {
         USB_State      = "断开";
         USB_StateColor = new SolidColorBrush(Colors.Red);
     }
 }
예제 #22
0
 /// <summary>
 /// 设备发生变动事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
 {
     if (inUsingDevce != null &&
         inUsingDevce.UsbRegistryInfo.SymbolicName.Equals(e.Device.Name) &&
         e.EventType == EventType.DeviceRemoveComplete)
     {
         // 当前设备已移除
         disconnected();
     }
     if (inUsingDevce == null && e.EventType == EventType.DeviceArrival)
     {
         UpdateDeviceList();
     }
 }
예제 #23
0
파일: MainForm.cs 프로젝트: mo10/PigeonUI
 private void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
 {
     if (inUsingDevice != null &&
         inUsingDevice.UsbRegistryInfo.IsAlive == false &&
         e.EventType == EventType.DeviceRemoveComplete)
     {
         // Current device removed.
         DeviceDisconnect();
     }
     if (inUsingDevice == null && e.EventType == EventType.DeviceArrival)
     {
         // Try to open device
         OpenDevice();
     }
 }
예제 #24
0
 void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
 {
     // A Device system-level event has occured
     if (e.Device.IdProduct == BlinkStick.ProductId && e.Device.IdVendor == BlinkStick.VendorId)
     {
         log.Debug(e.ToString()); // Dump the event info to output.
         if (e.EventType == EventType.DeviceRemoveComplete)
         {
             turnOffBlinkStick("Removed");
         }
         else if (e.EventType == EventType.DeviceArrival)
         {
             turnOnBlinkStick("Arrival");
         }
     }
 }
예제 #25
0
        private void Send(DeviceNotifyEventArgs device)
        {
            List <string> data = new List <string>();

            data.Add(device.Device.Name);
            data.Add(device.DeviceType.ToString());
            data.Add(device.EventType.ToString());
            data.Add(device.Port.Name);
            data.Add(device.Volume.Letter);

            RemoteClient.SendMessage(new global::DataObject
            {
                CommandType = "Device",
                CommandName = "notify",
                CommandData = data
            });
        }
예제 #26
0
        private void OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
        {
            if (e.Device.IdVendor != _vid || e.Device.IdProduct != _pid)
            {
                return; //Ignore this one!
            }
            switch (e.EventType)
            {
            case EventType.DeviceArrival:
                LibMain.OnConnectedChanged(true);     // Notify we found device
                break;

            case EventType.DeviceRemoveComplete:
                CloseDevice();
                LibMain.OnConnectedChanged(false);     // Notify we lost the device
                break;
            }
        }
예제 #27
0
 private void UsbDeviceNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
 {
     if (e.Device == null)
     {
         return;
     }
     if (e.Device.SerialNumber == last_device_name)
     {
         if (e.EventType == EventType.DeviceRemoveComplete)
         {
             this.ClosePort();
         }
         if (e.EventType == EventType.DeviceArrival)
         {
             this.reopenPort();
         }
     }
 }
예제 #28
0
 private void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
 {
     // A Device system-level event has occured
     if (e.EventType == EventType.DeviceArrival)
     {
         richTextBoxReceive.AppendText("Device arrival\n");
         USBDeviceDeinit();
     }
     else if (e.EventType == EventType.DeviceRemoveComplete)
     {
         richTextBoxReceive.AppendText("Device remove complete\n");
     }
     else
     {
         richTextBoxReceive.AppendText("Deveice Event: " + e.EventType.ToString() + "\n");
     }
     richTextBoxReceive.AppendText(e.ToString() + "\n");
 }
예제 #29
0
        /// <summary>
        /// Matches the device info during connect/disconnect and fires events accordingly, or passes on the event if it's not handled
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UsbDeviceNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
        {
            if (e.EventType == EventType.DeviceArrival)
            {
                if (e.Device.IdVendor == MyUsbFinder.Vid && e.Device.IdProduct == MyUsbFinder.Pid)
                {
                    MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);

                    if (IsConnected)
                    {
                        if (OnConnect != null)
                        {
                            OnConnect(this, e);
                        }
                    }

                    return;
                }
            }
            else if (e.EventType == EventType.DeviceRemoveComplete)
            {
                if (MyUsbDevice != null)
                {
                    if (MyUsbDevice.UsbRegistryInfo.Vid == e.Device.IdVendor &&
                        MyUsbDevice.UsbRegistryInfo.Pid == e.Device.IdProduct)// &&
                    //MyUsbDevice.UsbRegistryInfo.SymbolicName.ToLowerInvariant().Contains(e.Device.SymbolicName.FullName.ToLowerInvariant()))
                    {
                        ForceClose();

                        if (OnDisconnect != null)
                        {
                            OnDisconnect(this, e);
                        }

                        return;
                    }
                }
            }

            if (OnOtherDeviceNotifyEvent != null)
            {
                OnOtherDeviceNotifyEvent(this, e);
            }
        }
예제 #30
0
        private async void UsbDeviceNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
        {
            if (e.EventType == EventType.DeviceArrival && e.Device != null)
            {
                string locationInfo = String.Empty;
                int    count        = 0;
                while (String.IsNullOrEmpty(locationInfo) && count <= 10)
                {
                    await Task.Delay(500);

                    locationInfo = findArrivaledDevice(e.Device.SerialNumber);
                    count++;
                }
                if (locationInfo != string.Empty)
                {
                    lbl_deviceInfo.Text += "Serial Number: " + e.Device.SerialNumber + "\r\n" + "USB Port: " + locationInfo + "\r\n\r\n";
                }
            }
        }
예제 #31
0
 void MultiPointObject_DeviceArrivalEvent(object sender, DeviceNotifyEventArgs e)
 {
     DeviceInfo mouseObject = e.DeviceInfo;
     MultipointMouseDevice mpMouseDevice = mouseObject.DeviceVisual;
     Bitmap cursorBitmap = GetCursorImage(MultipointSdk.Instance.MouseDeviceList.Count);
     mpMouseDevice.CursorImage = ConvertBitmapToBitmapImage(cursorBitmap);
 }
예제 #32
0
        void Mouse_Conectado(object sender, DeviceNotifyEventArgs e)
        {
            BasicMouse newMouse = null;
            KidBox kb = null;
            Barra fb = null;

            bool reconnected = false;

            foreach (object key in devicesLost.Keys)
            {
                string deviceName = (string)key;

                if (deviceName.Equals(e.DeviceInfo.DeviceName))
                {
                    kb = (KidBox)devicesLost[deviceName];
                    newMouse = new BasicMouse(e.DeviceInfo);
                    newMouse.AlumnoMouse = kb.alumnoMouse;
                    newMouse.Foto_Identificacion = kb.FotoMouse;

                    GameContext.Instance.GamingMouses.Add(newMouse);
                    fb = (Barra)feedbackbarsLost[deviceName];
                    fb.KidID = e.DeviceInfo.ID;

                    fb.Mouse_Barra = newMouse;

                    devicesLost.Remove(key);
                    feedbackbarsLost.Remove(key);

                    reconnected = true;

                    break;
                }
            }

            fb.Mouse_Barra = newMouse;

            barContainer.barras.Add(fb);
            barContainer.RefrescarBarras();

            kb.ConnectBox(newMouse);
        }
예제 #33
0
        void Mouse_Desconectado(object sender, DeviceNotifyEventArgs e)
        {
            foreach (BasicMouse m in GameContext.Instance.GamingMouses)
            {
                if (m.deviceInfo.DeviceName == e.DeviceInfo.DeviceName)
                {
                    //We remove the mouse
                    GameContext.Instance.GamingMouses.Remove(m);

                    KidBox disconectedKidBox = null;

                    foreach (KidBox kb in this.kidBoxList)
                    {
                        if (kb.MouseControl != null && kb.MouseControl == m)
                        {
                            disconectedKidBox = kb;
                            disconectedKidBox.DisconnectBox();
                            break;
                        }
                    }

                    devicesLost.Add(m.deviceInfo.DeviceName, disconectedKidBox);

                    //we remove the feedbackbar
                    foreach (Barra b in barContainer.barras)
                    {
                        if (m.deviceInfo.ID == b.KidID)
                        {
                            feedbackbarsLost.Add(m.deviceInfo.DeviceName, b);

                            barContainer.barras.Remove(b);
                            barContainer.RefrescarBarras();

                            break;
                        }
                    }

                    break;
                }
            }
        }