Beispiel #1
0
        /// <returns>the serial number</returns>
        internal static unsafe string getSerialNumber(IntPtr device_handle)
        {
            LibusbDeviceDescriptor descriptor = getDeviceDescriptor(device_handle);

            byte[] buffer = new byte[100];
            int    length;

            fixed(byte *p = buffer)
            {
                length = LibUsb.throwIfError(UsbDevice.libusbGetStringDescriptorASCII(device_handle, descriptor.iSerialNumber, p, buffer.Length), "Error getting serial number string from device (pid=" + descriptor.idProduct.ToString("x") + ", vid=" + descriptor.idVendor.ToString("x") + ").");
            }

            String serial_number = "";

            for (int i = 0; i < length; i++)
            {
                serial_number += (char)buffer[i];
            }
            return(serial_number);
        }
Beispiel #2
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);
        }
Beispiel #3
0
 /// <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.");
 }
Beispiel #4
0
 /// <summary>
 /// Gets the serial number.
 /// </summary>
 public String getSerialNumber()
 {
     return(LibUsb.getSerialNumber(deviceHandle));
 }
Beispiel #5
0
 protected ushort getProductID()
 {
     return(LibUsb.getDeviceDescriptor(deviceHandle).idProduct);
 }
Beispiel #6
0
 internal static void handleEvents()
 {
     LibUsb.throwIfError(libusb_handle_events(context));
 }
Beispiel #7
0
 public static void check()
 {
     LibUsb.handleEvents();
 }