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(); } } }
// Uses the Equals method to determine if dev is already in the list public byte DeviceIndex(USBDevice dev) { byte x = 0; // Index of tmp foreach (USBDevice tmp in Items) { if (dev.Equals(tmp)) { return(x); } x++; } return(0xFF); // Device wasn't found }
public void Remove(IntPtr hDev) { 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)) { Items.Remove(tmp); tmp.Dispose(); } } }
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); } } } }
public override bool Equals(object right) { if (right == null) { return(false); } if (object.ReferenceEquals(this, right)) { return(true); } if (this.GetType() != right.GetType()) { return(false); } USBDevice dev = right as USBDevice; // The device paths of 2 different devices are unique in Windows return(this._path.Equals(dev._path)); }
// Uses the Equals method to determine if dev is already in the list public byte DeviceIndex(USBDevice dev) { byte x = 0; // Index of tmp foreach (USBDevice tmp in Items) { if (dev.Equals(tmp)) return x; x++; } return 0xFF; // Device wasn't found }