コード例 #1
0
        /// <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);
        }
コード例 #2
0
 /// <summary>
 /// Gets the serial number.
 /// </summary>
 public String getSerialNumber()
 {
     return(LibUsb.getSerialNumber(deviceHandle));
 }