Describes the device notify event
Inheritance: System.EventArgs
示例#1
0
        private void OnDeviceChange(ref Message m)
        {
            if (m.LParam.ToInt32() != 0)
            {
                EventHandler <DeviceNotifyEventArgs> temp = OnDeviceNotify;
                if (!ReferenceEquals(temp, null))
                {
                    DeviceNotifyEventArgs args;
                    DEV_BROADCAST_HDR     hdr = new DEV_BROADCAST_HDR();
                    Marshal.PtrToStructure(m.LParam, hdr);
                    switch (hdr.dbch_DeviceType)
                    {
                    case DeviceType.PORT:
                    case DeviceType.VOLUME:
                    case DeviceType.DEVICEINTERFACE:
                        args = new DeviceNotifyEventArgs(hdr, m.LParam, (EventType)m.WParam.ToInt32());
                        break;

                    default:
                        args = null;
                        break;
                    }

                    if (!ReferenceEquals(args, null))
                    {
                        temp(this, args);
                    }
                }
            }
        }
示例#2
0
 void devNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
 {
     Console.WriteLine(e.ToString());
     
     switch (e.EventType)
     {
         case EventType.CustomEvent:
             break;
         case EventType.DeviceArrival:
             if (e.DeviceType == DeviceType.DeviceInterface)
             {
                 this.Dispatcher.BeginInvoke(new AppendNotifyDelegate(UpStatusbarInfo), "Connected", e.Device);
                 _UsbKeyDataStruct.PID = e.Device.IdProduct;
                 _UsbKeyDataStruct.VID = e.Device.IdVendor;
                 _UsbKeyDataStruct.Sn = System.Text.Encoding.ASCII.GetBytes(e.Device.SerialNumber);
             }
             break;
         case EventType.DeviceQueryRemove:
             break;
         case EventType.DeviceQueryRemoveFailed:
             break;
         case EventType.DeviceRemoveComplete:
             this.Dispatcher.BeginInvoke(new AppendNotifyDelegate(UpStatusbarInfo), "Disconnected", e.Device);
             break;
         case EventType.DeviceRemovePending:
             break;
         case EventType.DeviceTypeSpecific:
             break;
         default:
             break;
     }
 }
示例#3
0
		private void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
        {
            Console.WriteLine(e.ToString()); // Dump the event info to output.
        
            Console.WriteLine();

			OnUsbDeviceAdded();
        }
        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 OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
 {
     switch (e.EventType)
     {
         case EventType.DeviceArrival:
             UsbDevice usbDevice = UsbDevice.OpenUsbDevice(usbFinder);
             if (usbDevice != null)
             {
                 batteries.Add(e.Device.SerialNumber, new Battery(usbDevice));
                 Switcher.Switch(new MainMenu());
             }
             break;
         case EventType.DeviceRemoveComplete:
             batteries.Remove(e.Device.SerialNumber);
             Switcher.Switch(new MainMenu());
             break;
     }
 }
示例#6
0
        private void UsbDeviceNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
        {
            try {

                UsbSubscription subscription = m_Devices.FirstOrDefault (u => ((u.VendorId == e.Device.IdVendor) && (u.ProductId == e.Device.IdProduct)));

                if (subscription != default(UsbSubscription)) {
                    if (e.EventType == EventType.DeviceArrival) {
                        subscription.OnConnected ();
                    } else if (e.EventType == EventType.DeviceRemoveComplete) {
                        subscription.OnDisconnected ();
                    }
                }

            } catch (Exception ex) {
                throw new UsbEventNotifierException (ex.Message, ex.InnerException);
            }
        }
        void myNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
        {
            if (PollingTimerIsEnabled)
                return;
            if (e.Device.IdVendor != vid || e.Device.IdProduct != pid)
                return;

            if(e.EventType == EventType.DeviceArrival) // board added
            {
                foreach(UsbRegistry regDevice in UsbDevice.AllDevices)
                {
                    if(regDevice.Device != null)
                    {
						if (regDevice.Vid == vid || regDevice.Pid == pid) {
							bool isInBoardList = false;
							foreach (var board in Boards) {
								if (regDevice.Device.Info.SerialString == board.SerialNumber) {
									isInBoardList = true;
								}
							}
							if (!isInBoardList) {
								Debug.WriteLine ("Adding board");
								Boards.Add (new TreehopperBoard (regDevice.Device));
							}
						}

						// This code only works under WinUSB, since e.Device.SerialNumber is empty in LibUsb
//						if (regDevice.Device.Info.SerialString.Length > 0) 
//						{
//							if (regDevice.Device.Info.SerialString == e.Device.SerialNumber)
//							{
//								TreehopperBoard board = new TreehopperBoard(regDevice.Device);
//								if (PassesFilter(board))
//									Boards.Add(board);
//							}
//						}
                        
                    }
                   
                }
            } else if(e.EventType == EventType.DeviceRemoveComplete) // board removed
            {
				Debug.WriteLine ("DEVICE REMOVED!");
				TreehopperBoard boardToRemove = null;
				foreach (var board in Boards) {
					bool deviceExists = false;
//					var deviceList = UsbDevice.AllDevices.ToList ();
//					foreach (UsbRegistry regDevice in deviceList) {
//						if (board.SerialNumber == regDevice.Device.Info.SerialString) {
//							deviceExists = true;
//						}
//					}
					if (!deviceExists) {
						boardToRemove = board;
					}
				}
				if (boardToRemove != null) {
					Boards.Remove (boardToRemove);
					Debug.WriteLine ("Removed board ");

				}
				// This code only works on Windows. LibUsb doesn't get access to the serial number.
				/*
                var board = Boards.Where(x => x.SerialNumber == e.Device.SerialNumber).ToList();
                if(board.Count > 0)
                {
                    board[0].Dispose();
                    Boards.Remove(board[0]);
                }
                */

            }
        }
 /// <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();
         }
     }
 }
 void devNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
 {
     Console.WriteLine(e.ToString());
 }
        void myNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
        {
            if (PollingTimerIsEnabled)
                return;
            if (e.Device.IdVendor != TreehopperUsb.Settings.Vid || e.Device.IdProduct != TreehopperUsb.Settings.Pid)
                return;

            if(e.EventType == EventType.DeviceArrival) // board added
            {
                foreach(UsbRegistry regDevice in UsbDevice.AllDevices)
                {
                    if(regDevice.Device != null)
                    {
						if (regDevice.Vid == TreehopperUsb.Settings.Vid && regDevice.Pid == TreehopperUsb.Settings.Pid) {
							bool isInBoardList = false;
							foreach (var board in Boards) {
								if (regDevice.SymbolicName == board.Connection.DevicePath) {
									isInBoardList = true;
								}
							}
							if (!isInBoardList && regDevice.Device.Info.SerialString.Length > 0) {
								Debug.WriteLine ("Adding board");
								Boards.Add (new TreehopperUsb(new UsbConnection(regDevice)));
							} else
                            {

                            }
						}
                    }
                   
                }
            } else if(e.EventType == EventType.DeviceRemoveComplete) // board removed
            {
                string id = e.Device.SymbolicName.FullName.ToLower();

                Debug.WriteLine ("Device removed: " +id);

                var board = Boards.Where(x => x.Connection.SerialNumber == e.Device.SymbolicName.SerialNumber).ToList();
                if (board.Count > 0)
                {
                    board[0].Dispose();
                    Boards.Remove(board[0]);
                }


            }
        }
示例#11
0
        // This function will be called each time we plug/unplug a usb device.
        private void onDevNotify(object sender, DeviceNotifyEventArgs e)
        {
            // If the mini2440 is disconnected, disable buttons.
            if ((e.EventType == EventType.DeviceRemoveComplete) && (((e.Device.IdProduct == pid2440) && (e.Device.IdVendor == vid2440))
                 || ((e.Device.IdProduct == pid6410) && (e.Device.IdVendor == vid6410)) ))
            {
                l_usbFound.Text = "Disconnected";
                t_log.AppendText("\r\n" + "## Device disconnected." + "\r\n");
                b_download.Enabled = false;
                b_upload.Enabled = false;
            }

            // If the mini2440 is plugged, connect to it.
            if ((e.EventType == EventType.DeviceArrival) && (((e.Device.IdProduct == pid2440) && (e.Device.IdVendor == vid2440))
                 || ((e.Device.IdProduct == pid6410) && (e.Device.IdVendor == vid6410))))
                Invoke(new AppendNotifyDelegate(usbConnect));
        }
示例#12
0
 /// <summary>
 /// Handles device list change on Linux/Mac.
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="e">E.</param>
 private void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
 {
     OnUsbDevicesChanged();
 }
示例#13
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));
         }
     }
 }
 private void onDevNotify(object sender, DeviceNotifyEventArgs e)
 {
     Invoke(new AppendNotifyDelegate(AppendNotifyText),new object[] {e.ToString()});
 }
示例#15
0
        //void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        //{
        //    MessageBox.Show("Complete");
        //}

        //void bw_DoWork(object sender, DoWorkEventArgs e)
        //{
        //    Populate handler = logBookPage.populateTracks;
        //    logBookPage.Dispatcher.BeginInvoke(handler);
        //}

        /// <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.Device.IdProduct == Constants.PID && e.Device.IdVendor == Constants.VID)
            {
                if (e.EventType == EventType.DeviceArrival)  // check for device arrival
                {
                    if (traqpaq == null)
                    {
                        // try to connect again
                        try
                        {
                            traqpaq = new TraqpaqDevice();
                            statusBarItemTraqpaq.Content = "Device connected: " + traqpaq.reqSerialNumber();
                            // populate tracks
                            //TODO fix populate tracks
                            logBookPage.populateTracks();                            
                        }
                        catch (TraqPaqNotConnectedException) { return; }    // Silently fail and exit method

                        //BackgroundWorker bw = new BackgroundWorker();
                        //bw.DoWork += bw_DoWork;
                        //bw.RunWorkerAsync(); 
                    }
                }
                else    // device removal
                {
                    traqpaq.disconnectDevice();
                    traqpaq = null;
                    // update status bar
                    statusBarItemTraqpaq.Content = "Traqpaq disconnected";
                }
            }
        }
示例#16
0
        private void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
        {
            if (e.Device.IdVendor == _vendorId && e.Device.IdProduct == _productId)
            {
                if (e.EventType == EventType.DeviceArrival)
                {
                    ConnectUsbDevice();
                }

                else if (e.EventType == EventType.DeviceRemoveComplete)
                {
                    _usbDevice = null;

                    IsAvailable = false;

                    if (ArduinoUsbDeviceChangeNotifier != null)

                        ArduinoUsbDeviceChangeNotifier.Invoke(false, null);
                }
            }
        }
示例#17
0
 void trinket_OnOtherDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
 {
     //notifyIcon.ShowBalloonTip(1000, "Trinket Fake USB Serial", "USB Device Notification: " + Enum.GetName(typeof(LibUsbDotNet.DeviceNotify.EventType), e.EventType), ToolTipIcon.Info);
 }
示例#18
0
 private void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
 {
     // Dump the event info to output.
     textBox1.Invoke(new EventHandler(delegate { textBox1.AppendText("\n#############\n"); }));
     textBox1.Invoke(new EventHandler(delegate { textBox1.AppendText(e.ToString()); }));
     label1.Text = e.Device.SerialNumber + " " + e.EventType.ToString();
     label2.Text = e.Device.IdProduct.ToString() + e.Device.IdVendor.ToString();
     textBox1.Invoke(new EventHandler(delegate { textBox1.AppendText("\n#############\n"); }));
 }
示例#19
0
文件: main.cs 项目: jakubl/jphonewin
	private void USBNotifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
	{
		// Only interested in Apple devices.
		if (e.Device.IdVendor != 0x05AC) return;

		if (!bDriveMounted)
		{
			PopulateDeviceList();
			TryAutomount();
		}

		// If a drive is mounted and we get an event, check to see if the mounted device was
		// unexpectedly unplugged.
		else
		{
			if (!iPhoneUSBDevice.UsbRegistryInfo.IsAlive)
			{
				Global.Log("Unmounting unexpectedly.\n");
				UnmountDevice(true);
				PopulateDeviceList();
			}
		}
	}
示例#20
0
 void notifier_OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
 {
     if (e.Device.IdVendor == Driver.VID && e.Device.IdProduct == Driver.PID)
     {
         switch (e.EventType)
         {
             case EventType.DeviceArrival:
                 if (ConnectAutomatically)
                     Open();
                 break;
             case EventType.DeviceRemoveComplete:
                 Close();
                 break;
         }
     }
 }
        /// <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);
        }
示例#22
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;
            }
        }
示例#23
0
        private void AppendNotifyText(DeviceNotifyEventArgs e)
        {
            try
            {
                string eventText = DateTime.Now.ToString("HH:mm:ss.fff - ") + Enum.GetName(typeof(EventType), e.EventType);

                string s;

                try
                {
                    s = e.Device.Name;
                    if (string.IsNullOrEmpty(s) == false && string.IsNullOrEmpty(s.Trim()) == false)
                        eventText += " - " + s;
                }
                catch { }

                TreeNode tvEvent = treeEvents.Nodes.Insert(0, eventText);

                try
                {
                    s = "VID: 0x" + e.Device.IdVendor.ToString("X4") + ", PID: 0x" + e.Device.IdProduct.ToString("X4");
                    if (string.IsNullOrEmpty(s) == false && string.IsNullOrEmpty(s.Trim()) == false)
                        tvEvent.Nodes.Add(s);
                }
                catch { }

                try
                {
                    s = e.Device.SerialNumber;
                    if (string.IsNullOrEmpty(s) == false && string.IsNullOrEmpty(s.Trim()) == false)
                        tvEvent.Nodes.Add("Serial Number: " + s);
                }
                catch { }

                try
                {
                    s = e.Device.ClassGuid.ToString();
                    if (string.IsNullOrEmpty(s) == false && string.IsNullOrEmpty(s.Trim()) == false)
                        tvEvent.Nodes.Add("Class GUID: " + s.ToUpperInvariant());
                }
                catch { }

                try
                {
                    s = Enum.GetName(typeof(DeviceType), e.DeviceType);
                    if (string.IsNullOrEmpty(s) == false && string.IsNullOrEmpty(s.Trim()) == false)
                        tvEvent.Nodes.Add("Device Type: " + s);
                }
                catch { }

                try
                {
                    s = e.Port.Name;
                    if (string.IsNullOrEmpty(s) == false && string.IsNullOrEmpty(s.Trim()) == false)
                        tvEvent.Nodes.Add("Port: " + s);
                }
                catch { }
            }
            catch (Exception ex)
            {
                //ErrorReportWindow.Show(ex, "Error During USB Panel Notification Event");

                string eventText = DateTime.Now.ToString("HH:mm:ss.fff - ") + "USB Event Exception";

                TreeNode tvEvent = treeErrors.Nodes.Insert(0, eventText);
                treeErrors.Nodes.Add(ex.Message);
            }
        }
示例#24
0
        public void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
        {
            // A Device system-level event has occured

            //Console.SetCursorPosition(0, Console.CursorTop);
            //MessageBox.Show(e.Device.IdVendor.ToString());
            if (e.EventType == EventType.DeviceArrival && e.Device.IdVendor == 0x16C0 && e.Device.IdProduct == 0x05DD)
            {
                try
                {
                    MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
                    if (MyUsbDevice == null)
                    {
                        //throw new Exception("Device Not Found.");
                        connected = false;
                    }
                    else
                    {

                        Device_l.Text = "Device: Connected";
                        connected = true;

                        Scan_b.Enabled = true;

                        wholeUsbDevice = MyUsbDevice as IUsbDevice;
                        if (!ReferenceEquals(wholeUsbDevice, null))
                        {
                            // This is a "whole" USB device. Before it can be used,
                            // the desired configuration and interface must be selected.

                            // Select config #1
                            wholeUsbDevice.SetConfiguration(1);

                            // Claim interface #0.
                            wholeUsbDevice.ClaimInterface(0);
                        }
                        //MessageBox.Show(ReadEndpointID.Ep04.ToString());
                        reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01);
                        writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep01);
                        mode = 4;
                        backgroundWorker1.RunWorkerAsync();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
                }
            }
            if (e.EventType == EventType.DeviceRemoveComplete && e.Device.IdVendor == 0x16C0 && e.Device.IdProduct == 0x05DD)
            {
                timer1.Enabled = false;
                connected = false;
                if (MyUsbDevice != null)
                {
                    if (MyUsbDevice.IsOpen)
                    {
                        // If this is a "whole" usb device (libusb-win32, linux libusb-1.0)
                        // it exposes an IUsbDevice interface. If not (WinUSB) the
                        // 'wholeUsbDevice' variable will be null indicating this is
                        // an interface of a device; it does not require or support
                        // configuration and interface selection.
                        IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
                        if (!ReferenceEquals(wholeUsbDevice, null))
                        {
                            // Release interface #0.
                            wholeUsbDevice.ReleaseInterface(0);
                        }

                        MyUsbDevice.Close();
                    }
                    MyUsbDevice = null;

                    // Free usb resources
                    UsbDevice.Exit();
                    Device_l.Text = "Device: Not Connected";
                    Scan_b.Enabled = false;
                    DumpRAM_b.Enabled = false;
                    DumpROM_b.Enabled = false;
                    WriteRAM_b.Enabled = false;
                    Banks_l.Text = "Banks: ";
                    MBC_l.Text = "MBC: ";
                    RAM_l.Text = "RAM Size: ";
                    Size_l.Text = "Size:";
                    Title_l.Text = "Title:";

                }
            }
               // 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)
 {
     if(e.Device.IdProduct == 1500 && e.Device.IdVendor == 5824)
     {
         if(e.EventType == EventType.DeviceRemoveComplete)
         {
             if (_isPlaying) TogglePlay();
             Log("Disconnecting device.");
             ExitDevice();
         }
         else if(e.EventType == EventType.DeviceArrival)
         {
             Log("Connecting device.");
             EnterDevice();
         }
     }
     //Log(e.ToString());
 }