Exemple #1
0
        public void Remove(IntPtr hDev, USBEventArgs e)
        {
            if (_alreadyDisposed)
            {
                throw new ObjectDisposedException("");
            }

            // Can't use foreach here, as we're modifying Items within the loop
            for (byte i = 0; i < Count; i++)
            {
                USBDevice tmp = (USBDevice)Items[i];
                if (hDev.Equals(tmp._hDevice))
                {
                    e.Device       = null;
                    e.FriendlyName = tmp.FriendlyName;
                    e.Manufacturer = tmp.Manufacturer;
                    e.Product      = tmp.Product;
                    e.VendorID     = tmp.VendorID;
                    e.ProductID    = tmp.ProductID;
                    e.SerialNum    = tmp.SerialNumber;

                    Items.Remove(tmp);
                    tmp.Dispose();
                }
            }
        }
Exemple #2
0
        private void PnP_Event_Handler(IntPtr pnpEvent, IntPtr hRemovedDevice)
        {
            if (AppCallBack != null)
            {
                AppCallBack(pnpEvent, hRemovedDevice);
            }
            else
            {
                USBEventArgs e = new USBEventArgs();

                if (pnpEvent.Equals(CyConst.DBT_DEVICEREMOVECOMPLETE))
                {
                    Remove(hRemovedDevice, e); // Sets the contents of e

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

                if (pnpEvent.Equals(CyConst.DBT_DEVICEARRIVAL))
                {
                    USBDevice newDev = Add();  // Find and add the new device to the list

                    if (DeviceAttached != null)
                    {
                        if (newDev != null)
                        {
                            e.Device       = newDev;
                            e.FriendlyName = newDev.FriendlyName;
                            e.Manufacturer = newDev.Manufacturer;
                            e.Product      = newDev.Product;
                            e.VendorID     = newDev.VendorID;
                            e.ProductID    = newDev.ProductID;
                            e.SerialNum    = newDev.SerialNumber;
                        }

                        DeviceAttached(this, e);
                    }
                }
            }
        }
Exemple #3
0
        private void PnP_Event_Handler(IntPtr pnpEvent, IntPtr hRemovedDevice)
        {
            if (AppCallBack != null)
                AppCallBack(pnpEvent, hRemovedDevice);
            else
            {
                USBEventArgs e = new USBEventArgs();

                if (pnpEvent.Equals(CyConst.DBT_DEVICEREMOVECOMPLETE))
                {
                    Remove(hRemovedDevice, e); // Sets the contents of e

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

                if (pnpEvent.Equals(CyConst.DBT_DEVICEARRIVAL))
                {
                    USBDevice newDev = Add();  // Find and add the new device to the list

                    if (DeviceAttached != null)
                    {
                        if (newDev != null)
                        {
                            e.Device = newDev;
                            e.FriendlyName = newDev.FriendlyName;
                            e.Manufacturer = newDev.Manufacturer;
                            e.Product = newDev.Product;
                            e.VendorID = newDev.VendorID;
                            e.ProductID = newDev.ProductID;
                            e.SerialNum = newDev.SerialNumber;
                        }

                        DeviceAttached(this, e);
                    }
                }
            }
        }
Exemple #4
0
        public void Remove(IntPtr hDev, USBEventArgs e)
        {
            if (_alreadyDisposed) throw new ObjectDisposedException("");

            // Can't use foreach here, as we're modifying Items within the loop
            for (byte i = 0; i < Count; i++)
            {
                USBDevice tmp = (USBDevice)Items[i];
                if (hDev.Equals(tmp._hDevice))
                {
                    e.Device = null;
                    e.FriendlyName = tmp.FriendlyName;
                    e.Manufacturer = tmp.Manufacturer;
                    e.Product = tmp.Product;
                    e.VendorID = tmp.VendorID;
                    e.ProductID = tmp.ProductID;
                    e.SerialNum = tmp.SerialNumber;

                    Items.Remove(tmp);
                    tmp.Dispose();
                }
            }
        }