/// <summary> /// gets a list of devices by vendor and product ID /// </summary> /// <returns></returns> protected static unsafe List <DeviceListItem> getDeviceList(UInt16 vendorId, UInt16[] productIdArray) { var list = new List <DeviceListItem>(); IntPtr *device_list; int count = LibUsb.throwIfError(UsbDevice.libusbGetDeviceList(LibUsb.context, out device_list), "Error from libusb_get_device_list."); int i; for (i = 0; i < count; i++) { IntPtr device = device_list[i]; foreach (UInt16 productId in productIdArray) { if (LibUsb.deviceMatchesVendorProduct(device, vendorId, productId)) { IntPtr device_handle; LibUsb.throwIfError(UsbDevice.libusbOpen(device, out device_handle), "Error connecting to device to get serial number (" + (i + 1) + " of " + count + ", " + device.ToString("x8") + ")."); string serialNumber = LibUsb.getSerialNumber(device_handle); list.Add(new DeviceListItem(device, "#" + serialNumber, serialNumber, productId)); UsbDevice.libusbClose(device_handle); } } } // Free device list without unreferencing. // Unreference/free the individual devices in the // DeviceListItem destructor. UsbDevice.libusbFreeDeviceList(device_list, 0); return(list); }
public static void check() { LibUsb.handleEvents(); }
internal static void handleEvents() { LibUsb.throwIfError(libusb_handle_events(context)); }
protected ushort getProductID() { return(LibUsb.getDeviceDescriptor(deviceHandle).idProduct); }
/// <summary> /// Create a usb device from a deviceListItem /// </summary> /// <param name="handles"></param> protected UsbDevice(DeviceListItem deviceListItem) { LibUsb.throwIfError(libusbOpen(deviceListItem.devicePointer, out privateDeviceHandle), "Error connecting to device."); }
/// <summary> /// Gets the serial number. /// </summary> public String getSerialNumber() { return(LibUsb.getSerialNumber(deviceHandle)); }