Libusb

For issues with communication ports, protocols, etc.
Dinosaur
Posts: 1071
Joined: Jul 24, 2005 1:13
Location: Searcy AR USA
Contact:

Libusb

Postby Dinosaur » Jun 01, 2018 19:35

Hi All

After two days of experimenting I can't get beyond an error on Libusb_open.
I have simplified as much as possible and it all hinges on "dev" returned by libusb_get_device_descriptor(dev,@desc)
The number returned in dev is a rather large number , but different each time. (29346192)
The large number puzzles me as, if it is an address, then the content prints as 0.
Worth noting that if I print all the other usb devices it finds, the numbers are in the same range.
Playing around with dev either returns an error of -4 (LIBUSB_ERROR_NO_DEVICE) or the program hangs with a segment violation.
Running it as Root from the terminal produces the same result.

By changing the Vendor & Product to your device, this program will run in Linux if someone can test it for me.

Couldn't include the .bi file as it exceeded the char count for this post, but it is in the previous thread.
One thing I simply can't get my head around is the multiple Ptr statements , like "libusb_device Ptr Ptr dev" and that probably contributes
to my lack of understanding the problem.

Code: Select all

#include once "libusb-1.0.bi"
    Dim shared as libusb_device_descriptor desc
    Dim shared as libusb_device Ptr Ptr dev
    Dim shared as libusb_device_handle Ptr Ptr dev_handle
    Dim shared as libusb_device Ptr Ptr devs
    Dim shared as Long i = 0, j = 0, r = 0
    Dim shared as UByte path(8)
    Dim shared as ssize_t cnt

Sub print_devs(devs As libusb_device Ptr Ptr)
   dev = devs[0]
   '--------Look for one of two -----------------
   While dev <> NULL
        r = libusb_get_device_descriptor(dev, @desc)     
        Print r,dev
        If r < 0 Then
            Print "failed to get device descriptor"
            Return
        EndIf
        If Hex(desc.idVendor,4) = "0A07" And Hex(desc.idProduct,4) = "0046" Then
            Print "Found one ;";dev
            Print Hex(desc.idVendor,4);":";Hex(desc.idProduct,4)
            Print "bcdDevice  ;"; desc.bcdDevice
            Print "Serial Nbr ;"; desc.iSerialNumber
            r = libusb_open(@dev, dev_handle)
            Print "dev_handle ;"; dev_handle
            Print "Error Detail ;";r
            Print *(libusb_error_name(r))
            Print
        EndIf
        i += 1
        dev = devs[i]
   Wend
   '---------------------------------------------
End Sub


    r = libusb_init(NULL)
    If r < 0 Then
        End r
    EndIf
    cnt = libusb_get_device_list(NULL, @devs)
    If cnt < 0 Then
        End cnt
    EndIf
    print_devs(devs)
    libusb_free_device_list(devs, 1)
   
    libusb_exit(NULL)
    ? "OK"
    Sleep


However I can open the devices (individually with only one plugged in) with:

Code: Select all

Sub usbInitialize
    With usbOntrak
        .Found = libusb_init(0)
        If .Found = 0 Then
                .usbFlag = 1
            Else
                Print "libusb_Init     =; Failed"
                Exit Sub
        EndIf
        If .Found = 0 Then
            .HandlePtr = libusb_open_device_with_vid_pid(0, &H0a07, &H0046)     
            If .HandlePtr < 1 Then
                Print "Open Handle Ptr =; Failed"                               
            EndIf
            If .HandlePtr > 0 Then
                .usbFlag += 1
                .CValue = libusb_kernel_driver_active(.HandlePtr,0)             ''check if kernel has attached a driver
                If .CValue > 0 Then                                             ''if so
                    .Detach = libusb_detach_kernel_driver(.HandlePtr, 0)        ''detach it
                Endif
                .Claim = libusb_claim_interface(.HandlePtr, 0)                  ''now we can claim the interface
                If .Claim = 0 Then
                        .usbFlag += 1                                           ''This allows usbThread to proceed
                    Else
                        Print "Claiming I/F Failed   "
                EndIf
            Endif
            Buffer = Allocate(64)
            .RetValue = libusb_get_string_descriptor_ascii(.HandlePtr,3,Buffer,64)
            If .RetValue > 0 Then
                Dim i as Ushort
                For i = 0 to .RetValue
                    .SerialNbr(1) += Chr(Buffer[i])
                Next
            EndIf
            Print .SerialNbr(1)
            .Handle(1) = .HandlePtr
        EndIf
    End With
End Sub
But the downside of that is that it never finds the second unit which has the same Vendor details but different serial number.
I have tried to find other ways to open the port to no avail, so getting Libusb_open to work is crucial.

Hopefully someone here has experience with this and sees the problem.
Much appreciated.

Regards
badidea
Posts: 751
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Libusb

Postby badidea » Jun 01, 2018 20:42

Post should have been part of this Topic? viewtopic.php?f=18&t=20820&start=45
If not, I can do some tests, but I can't find the correct 'libusb-1.0.bi'
Dinosaur
Posts: 1071
Joined: Jul 24, 2005 1:13
Location: Searcy AR USA
Contact:

Re: Libusb

Postby Dinosaur » Jun 01, 2018 20:58

Hi All
badidea, thanks for the response, tried to paste the file in here but the response is
Your message contains 78386 characters.
The maximum number of allowed characters is 60000.

Yet on page 4 of the previous post , 5th post down the .bi file is there from grindstone. ??

Regards
Dinosaur
Posts: 1071
Joined: Jul 24, 2005 1:13
Location: Searcy AR USA
Contact:

Re: Libusb

Postby Dinosaur » Jun 01, 2018 21:13

Hi All

.bi file with lots of large comment blocks removed.

Code: Select all

#Ifndef LIBUSB_H
   #define LIBUSB_H
      
   #Inclib "usb-1.0"
         
   #Include Once "crt/stdint.bi"
   #Include Once "crt/sys/types.bi"
    #If Defined(__FB_LINUX__ ) Or Defined(__FB_CYGWIN__)
      Type timeval
         tv_sec As Long
         tv_usec As Long
      End Type
   #EndIf

   #Include Once "crt/limits.bi"
   
   #If Defined(__FB_WIN32__) Or Defined(__FB_CYGWIN__)   
      #Include Once "windows.bi"
      #If Defined(interface)
         #Undef interface
      #EndIf
      #If Not Defined(__FB_CYGWIN__)
         #Include Once "win/winsock.bi"
      #EndIf
   #EndIf
      
   #If Defined(__FB_LINUX__)
      #Include Once "crt/sys/socket.bi"
   #EndIf
   
Dim As ULong libusb_device = 0

#define LIBUSB_API_VERSION &h01000105

/'' The following is kept for compatibility, but will be deprecated in the future ''/
#define LIBUSBX_API_VERSION LIBUSB_API_VERSION

#If Defined(__FB_WIN32__)
   #Define LIBUSB_CALL WINAPI
   Extern "Windows-MS"
#Else
   #Define LIBUSB_CALL
   Extern "C"
#EndIf

Function libusb_cpu_to_le16(x As Const uint16_t) As uint16_t

   Union _tmp
      As uint8_t b8(1)
      As uint16_t b16
   End Union
   Dim _tmp As _tmp
   
   _tmp.b8(1) = Cast(uint8_t, (x Shr 8))
   _tmp.b8(0) = Cast(uint8_t, (x And &hff))
   Return _tmp.b16
End Function

#define libusb_le16_to_cpu libusb_cpu_to_le16

Enum libusb_class_code
   LIBUSB_CLASS_PER_INTERFACE = 0

   /''* Audio class ''/
   LIBUSB_CLASS_AUDIO = 1

   /''* Communications class ''/
   LIBUSB_CLASS_COMM = 2

   /''* Human Interface Device class ''/
   LIBUSB_CLASS_HID = 3

   /''* Physical ''/
   LIBUSB_CLASS_PHYSICAL = 5

   /''* Printer class ''/
   LIBUSB_CLASS_PRINTER = 7

   /''* Image class ''/
   LIBUSB_CLASS_PTP = 6, /'' legacy name from libusb-0.1 usb.h ''/
   LIBUSB_CLASS_IMAGE = 6

   /''* Mass storage class ''/
   LIBUSB_CLASS_MASS_STORAGE = 8

   /''* Hub class ''/
   LIBUSB_CLASS_HUB = 9

   /''* Data class ''/
   LIBUSB_CLASS_DATA = 10

   /''* Smart Card ''/
   LIBUSB_CLASS_SMART_CARD = &h0b

   /''* Content Security ''/
   LIBUSB_CLASS_CONTENT_SECURITY = &h0d

   /''* Video ''/
   LIBUSB_CLASS_VIDEO = &h0e,

   /''* Personal Healthcare ''/
   LIBUSB_CLASS_PERSONAL_HEALTHCARE = &h0f

   /''* Diagnostic Device ''/
   LIBUSB_CLASS_DIAGNOSTIC_DEVICE = &hdc

   /''* Wireless class ''/
   LIBUSB_CLASS_WIRELESS = &he0

   /''* Application class ''/
   LIBUSB_CLASS_APPLICATION = &hfe

   /''* Class is vendor-specific ''/
   LIBUSB_CLASS_VENDOR_SPEC = &hff
End Enum

/''* \ingroup libusb_desc
 * Descriptor types as defined by the USB specification. ''/
Enum libusb_descriptor_type
   /''* Device descriptor. See libusb_device_descriptor. ''/
   LIBUSB_DT_DEVICE = &h01

   /''* Configuration descriptor. See libusb_config_descriptor. ''/
   LIBUSB_DT_CONFIG = &h02

   /''* String descriptor ''/
   LIBUSB_DT_STRING = &h03

   /''* Interface descriptor. See libusb_interface_descriptor. ''/
   LIBUSB_DT_INTERFACE = &h04

   /''* Endpoint descriptor. See libusb_endpoint_descriptor. ''/
   LIBUSB_DT_ENDPOINT = &h05

   /''* BOS descriptor ''/
   LIBUSB_DT_BOS = &h0f

   /''* Device Capability descriptor ''/
   LIBUSB_DT_DEVICE_CAPABILITY = &h10

   /''* HID descriptor ''/
   LIBUSB_DT_HID = &h21

   /''* HID report descriptor ''/
   LIBUSB_DT_REPORT = &h22

   /''* Physical descriptor ''/
   LIBUSB_DT_PHYSICAL = &h23

   /''* Hub descriptor ''/
   LIBUSB_DT_HUB = &h29

   /''* SuperSpeed Hub descriptor ''/
   LIBUSB_DT_SUPERSPEED_HUB = &h2a

   /''* SuperSpeed Endpoint Companion descriptor ''/
   LIBUSB_DT_SS_ENDPOINT_COMPANION = &h30
End Enum

/'' Descriptor sizes per descriptor type ''/
#define LIBUSB_DT_DEVICE_SIZE         18
#define LIBUSB_DT_CONFIG_SIZE         9
#define LIBUSB_DT_INTERFACE_SIZE      9
#define LIBUSB_DT_ENDPOINT_SIZE         7
#define LIBUSB_DT_ENDPOINT_AUDIO_SIZE      9   /'' Audio extension ''/
#define LIBUSB_DT_HUB_NONVAR_SIZE      7
#define LIBUSB_DT_SS_ENDPOINT_COMPANION_SIZE   6
#define LIBUSB_DT_BOS_SIZE         5
#define LIBUSB_DT_DEVICE_CAPABILITY_SIZE   3

/'' BOS descriptor sizes ''/
#define LIBUSB_BT_USB_2_0_EXTENSION_SIZE   7
#define LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE   10
#define LIBUSB_BT_CONTAINER_ID_SIZE      20

/'' We unwrap the BOS => define its max size ''/
#define LIBUSB_DT_BOS_MAX_SIZE   ((LIBUSB_DT_BOS_SIZE) + _
                                      (LIBUSB_BT_USB_2_0_EXTENSION_SIZE) + _
                                      (LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE) + _
                                      (LIBUSB_BT_CONTAINER_ID_SIZE))

#define LIBUSB_ENDPOINT_ADDRESS_MASK   &h0f    /'' in bEndpointAddress ''/
#define LIBUSB_ENDPOINT_DIR_MASK      &h80

Enum libusb_endpoint_direction
   /''* In: device-to-host ''/
   LIBUSB_ENDPOINT_IN = &h80

   /''* Out: host-to-device ''/
   LIBUSB_ENDPOINT_OUT = &h00
End Enum

#define LIBUSB_TRANSFER_TYPE_MASK         &h03    /'' in bmAttributes ''/

Enum libusb_transfer_type
   /''* Control endpoint ''/
   LIBUSB_TRANSFER_TYPE_CONTROL = 0

   /''* Isochronous endpoint ''/
   LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1

   /''* Bulk endpoint ''/
   LIBUSB_TRANSFER_TYPE_BULK = 2

   /''* Interrupt endpoint ''/
   LIBUSB_TRANSFER_TYPE_INTERRUPT = 3

   /''* Stream endpoint ''/
   LIBUSB_TRANSFER_TYPE_BULK_STREAM = 4
End Enum

/''* \ingroup libusb_misc
 * Standard requests, as defined in table 9-5 of the USB 3.0 specifications ''/
Enum libusb_standard_request
   /''* Request status of the specific recipient ''/
   LIBUSB_REQUEST_GET_STATUS = &h00

   /''* Clear or disable a specific feature ''/
   LIBUSB_REQUEST_CLEAR_FEATURE = &h01

   /'' &h02 is reserved ''/

   /''* Set or enable a specific feature ''/
   LIBUSB_REQUEST_SET_FEATURE = &h03

   /'' &h04 is reserved ''/

   /''* Set device address for all future accesses ''/
   LIBUSB_REQUEST_SET_ADDRESS = &h05

   /''* Get the specified descriptor ''/
   LIBUSB_REQUEST_GET_DESCRIPTOR = &h06

   /''* Used to update existing descriptors or add new descriptors ''/
   LIBUSB_REQUEST_SET_DESCRIPTOR = &h07

   /''* Get the current device configuration value ''/
   LIBUSB_REQUEST_GET_CONFIGURATION = &h08

   /''* Set device configuration ''/
   LIBUSB_REQUEST_SET_CONFIGURATION = &h09

   /''* Return the selected alternate setting for the specified interface ''/
   LIBUSB_REQUEST_GET_INTERFACE = &h0A

   /''* Select an alternate interface for the specified interface ''/
   LIBUSB_REQUEST_SET_INTERFACE = &h0B

   '' Set then report an endpoint''s synchronization frame ''/
   LIBUSB_REQUEST_SYNCH_FRAME = &h0C

   /''* Sets both the U1 and U2 Exit Latency ''/
   LIBUSB_REQUEST_SET_SEL = &h30

   /''* Delay from the time a host transmits a packet to the time it is
     * received by the device. ''/
   LIBUSB_SET_ISOCH_DELAY = &h31
End Enum

Enum libusb_request_type
   /''* Standard ''/
   LIBUSB_REQUEST_TYPE_STANDARD = (&h00 Shl 5)

   /''* Class ''/
   LIBUSB_REQUEST_TYPE_CLASS = (&h01 Shl 5)

   /''* Vendor ''/
   LIBUSB_REQUEST_TYPE_VENDOR = (&h02 Shl 5)

   /''* Reserved ''/
   LIBUSB_REQUEST_TYPE_RESERVED = (&h03 Shl 5)
End Enum

Enum libusb_request_recipient
   /''* Device ''/
   LIBUSB_RECIPIENT_DEVICE = &h00

   /''* Interface ''/
   LIBUSB_RECIPIENT_INTERFACE = &h01

   /''* Endpoint ''/
   LIBUSB_RECIPIENT_ENDPOINT = &h02

   /''* Other ''/
   LIBUSB_RECIPIENT_OTHER = &h03
End Enum

#define LIBUSB_ISO_SYNC_TYPE_MASK      &h0C

Enum libusb_iso_sync_type
   /''* No synchronization ''/
   LIBUSB_ISO_SYNC_TYPE_NONE = 0

   /''* Asynchronous ''/
   LIBUSB_ISO_SYNC_TYPE_ASYNC = 1

   /''* Adaptive ''/
   LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2

   /''* Synchronous ''/
   LIBUSB_ISO_SYNC_TYPE_SYNC = 3
End Enum

#define LIBUSB_ISO_USAGE_TYPE_MASK &h30

Enum libusb_iso_usage_type
   /''* Data endpoint ''/
   LIBUSB_ISO_USAGE_TYPE_DATA = 0

   /''* Feedback endpoint ''/
   LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1

   /''* Implicit feedback Data endpoint ''/
   LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2
End Enum

Type libusb_device_descriptor
   /''* Size of this descriptor (in bytes) ''/
   As uint8_t  bLength

   As uint8_t  bDescriptorType

   As uint16_t bcdUSB

   /''* USB-IF class code for the device. See \ref libusb_class_code. ''/
   As uint8_t  bDeviceClass

   /''* USB-IF subclass code for the device, qualified by the bDeviceClass
    * value ''/
   As uint8_t  bDeviceSubClass

   /''* USB-IF protocol code for the device, qualified by the bDeviceClass and
    * bDeviceSubClass values ''/
   As uint8_t  bDeviceProtocol

   /''* Maximum packet size for endpoint 0 ''/
   As uint8_t  bMaxPacketSize0

   /''* USB-IF vendor ID ''/
   As uint16_t idVendor

   /''* USB-IF product ID ''/
   As uint16_t idProduct

   /''* Device release number in binary-coded decimal ''/
   As uint16_t bcdDevice

   /''* Index of string descriptor describing manufacturer ''/
   As uint8_t  iManufacturer

   /''* Index of string descriptor describing product ''/
   As uint8_t  iProduct

   /''* Index of string descriptor containing device serial number ''/
   As uint8_t  iSerialNumber

   /''* Number of possible configurations ''/
   As uint8_t  bNumConfigurations
End Type

Type libusb_endpoint_descriptor
   /''* Size of this descriptor (in bytes) ''/
   As uint8_t  bLength

   As uint8_t  bDescriptorType

   As uint8_t  bEndpointAddress

   As uint8_t  bmAttributes

   /''* Maximum packet size this endpoint is capable of sending/receiving. ''/
   As uint16_t wMaxPacketSize

   /''* Interval for polling endpoint for data transfers. ''/
   As uint8_t  bInterval

   /''* For audio devices only: the rate at which synchronization feedback
    * is provided. ''/
   As uint8_t  bRefresh

   /''* For audio devices only: the address if the synch endpoint ''/
   As uint8_t  bSynchAddress

   /''* Extra descriptors. If libusb encounters unknown endpoint descriptors,
    * it will store them here, should you wish to parse them. ''/
   As  UByte Ptr extra

   /''* Length of the extra descriptors, in bytes. ''/
   As Long extra_length
End Type

Type libusb_interface_descriptor
   /''* Size of this descriptor (in bytes) ''/
   As uint8_t  bLength

   As uint8_t  bDescriptorType

   /''* Number of this interface ''/
   As uint8_t  bInterfaceNumber

   /''* Value used to select this alternate setting for this interface ''/
   As uint8_t  bAlternateSetting

   /''* Number of endpoints used by this interface (excluding the control
    * endpoint). ''/
   As uint8_t  bNumEndpoints

   /''* USB-IF class code for this interface. See \ref libusb_class_code. ''/
   As uint8_t  bInterfaceClass

   /''* USB-IF subclass code for this interface, qualified by the
    * bInterfaceClass value ''/
   As uint8_t  bInterfaceSubClass

   /''* USB-IF protocol code for this interface, qualified by the
    * bInterfaceClass and bInterfaceSubClass values ''/
   As uint8_t  bInterfaceProtocol

   /''* Index of string descriptor describing this interface ''/
   As uint8_t  iInterface

   As  libusb_endpoint_descriptor Ptr endpoint

   As  UByte Ptr extra

   /''* Length of the extra descriptors, in bytes. ''/
   As Long extra_length
End Type

Type libusb_interface
   As Const libusb_interface_descriptor Ptr altsetting
   
   As Long num_altsetting
End Type

Type libusb_config_descriptor
   /''* Size of this descriptor (in bytes) ''/
   As uint8_t  bLength

   As uint8_t  bDescriptorType

   /''* Total length of data returned for this configuration ''/
   As uint16_t wTotalLength

   /''* Number of interfaces supported by this configuration ''/
   As uint8_t  bNumInterfaces

   /''* Identifier value for this configuration ''/
   As uint8_t  bConfigurationValue

   /''* Index of string descriptor describing this configuration ''/
   As uint8_t  iConfiguration

   /''* Configuration characteristics ''/
   As uint8_t  bmAttributes

   As uint8_t  MaxPower

   As Const libusb_interface Ptr interface
   As  UByte Ptr extra

   /''* Length of the extra descriptors, in bytes. ''/
   As Long extra_length
End Type

Type libusb_ss_endpoint_companion_descriptor
   As uint8_t  bLength

   As uint8_t  bDescriptorType

   As uint8_t  bMaxBurst

   As uint8_t  bmAttributes

   As uint16_t wBytesPerInterval
End Type

#If Defined(__STDC_VERSION__)
   #If (__STDC_VERSION__ >= 199901)
      #Define __STDC_VERSION_DEF__
   #EndIf
#EndIf

Type libusb_bos_dev_capability_descriptor
   /''* Size of this descriptor (in bytes) ''/
   As uint8_t bLength
   As uint8_t bDescriptorType
   /''* Device Capability type ''/
   As uint8_t bDevCapabilityType
   /''* Device Capability data (bLength - 3 bytes) ''/
   #If Defined(__STDC_VERSION_DEF__)
      As uint8_t dev_capability_data(Any) /'' valid C99 code ''/
   #Else
      As uint8_t dev_capability_data(0) /'' non-standard, but usually working code ''/
   #EndIf
End Type

Type libusb_bos_descriptor
   /''* Size of this descriptor (in bytes) ''/
   As uint8_t  bLength

   As uint8_t  bDescriptorType

   /''* Length of this descriptor and all of its sub descriptors ''/
   As uint16_t wTotalLength

   /''* The number of separate device capability descriptors in
    * the BOS ''/
   As uint8_t  bNumDeviceCaps

   /''* bNumDeviceCap Device Capability Descriptors ''/
   #If Defined(__STDC_VERSION_DEF__)
      As libusb_bos_dev_capability_descriptor Ptr dev_capability(Any) /'' valid C99 code ''/
   #Else
      As libusb_bos_dev_capability_descriptor Ptr dev_capability(0) /'' non-standard, but usually working code ''/
   #EndIf
End Type

Type libusb_usb_2_0_extension_descriptor
   /''* Size of this descriptor (in bytes) ''/
   As uint8_t  bLength

   As uint8_t  bDescriptorType

   As uint8_t  bDevCapabilityType

   As uint32_t  bmAttributes
End Type

Type libusb_ss_usb_device_capability_descriptor
   /''* Size of this descriptor (in bytes) ''/
   As uint8_t  bLength

   As uint8_t  bDescriptorType

   As uint8_t  bDevCapabilityType

   As uint8_t  bmAttributes

   As uint16_t wSpeedSupported

   As uint8_t  bFunctionalitySupport

   /''* U1 Device Exit Latency. ''/
   As uint8_t  bU1DevExitLat

   /''* U2 Device Exit Latency. ''/
   As uint16_t bU2DevExitLat
End Type

Type  libusb_container_id_descriptor
   /''* Size of this descriptor (in bytes) ''/
   As uint8_t  bLength

   As uint8_t  bDescriptorType

   As uint8_t  bDevCapabilityType

   /''* Reserved field ''/
   As uint8_t bReserved

   /''* 128 bit UUID ''/
   As uint8_t  ContainerID(16)
End Type

Type libusb_control_setup
   As uint8_t  bmRequestType

   As uint8_t  bRequest

   /''* Value. Varies according to request ''/
   As uint16_t wValue

   /''* Index. Varies according to request, typically used to pass an index
    * or offset ''/
   As uint16_t wIndex

   /''* Number of bytes to transfer ''/
   As uint16_t wLength
End Type
Dim Shared libusb_control_setup As libusb_control_setup

#define LIBUSB_CONTROL_SETUP_SIZE (SizeOf(libusb_control_setup))

/'' libusb ''/
Type libusb_context As libusb_context
Type libusb_device As libusb_device
Type libusb_device_handle As libusb_device_handle

/''* \ingroup libusb_lib
 * Structure providing the version of the libusb runtime
 ''/
Type libusb_version
   /''* Library major version. ''/
   As  uint16_t major

   /''* Library minor version. ''/
   ''As Const uint16_t minor
   As  uint16_t minor

   /''* Library micro version. ''/
   ''As Const uint16_t micro
   As  uint16_t micro

   /''* Library nano version. ''/
   ''As Const uint16_t nano
   As  uint16_t nano

   /''* Library release candidate suffix string, e.g. "-rc4". ''/
   ''As Const UByte Ptr rc
   As  UByte Ptr rc

   /''* For ABI compatibility only. ''/
   As  UByte Ptr describe
End Type

Type libusb_context As libusb_context

Type libusb_device As libusb_device


Type libusb_device_handle As libusb_device_handle

Enum libusb_speed
   ''* The OS doesn''t report or know the device speed. ''/
   LIBUSB_SPEED_UNKNOWN = 0

   /''* The device is operating at low speed (1.5MBit/s). ''/
   LIBUSB_SPEED_LOW = 1

   /''* The device is operating at full speed (12MBit/s). ''/
   LIBUSB_SPEED_FULL = 2

   /''* The device is operating at high speed (480MBit/s). ''/
   LIBUSB_SPEED_HIGH = 3

   /''* The device is operating at super speed (5000MBit/s). ''/
   LIBUSB_SPEED_SUPER = 4
End Enum

Enum libusb_supported_speed
   /''* Low speed operation supported (1.5MBit/s). ''/
   LIBUSB_LOW_SPEED_OPERATION   = 1

   /''* Full speed operation supported (12MBit/s). ''/
   LIBUSB_FULL_SPEED_OPERATION  = 2

   /''* High speed operation supported (480MBit/s). ''/
   LIBUSB_HIGH_SPEED_OPERATION  = 4

   /''* Superspeed operation supported (5000MBit/s). ''/
   LIBUSB_SUPER_SPEED_OPERATION = 8
End Enum

Enum libusb_usb_2_0_extension_attributes
   /''* Supports Link Power Management (LPM) ''/
   LIBUSB_BM_LPM_SUPPORT = 2
End Enum

Enum libusb_ss_usb_device_capability_attributes
   /''* Supports Latency Tolerance Messages (LTM) ''/
   LIBUSB_BM_LTM_SUPPORT = 2
End Enum

/''* \ingroup libusb_dev
 * USB capability types
 ''/
Enum libusb_bos_type
   /''* Wireless USB device capability ''/
   LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY   = 1

   /''* USB 2.0 extensions ''/
   LIBUSB_BT_USB_2_0_EXTENSION         = 2

   /''* SuperSpeed USB device capability ''/
   LIBUSB_BT_SS_USB_DEVICE_CAPABILITY      = 3

   /''* Container ID type ''/
   LIBUSB_BT_CONTAINER_ID            = 4
End Enum

Enum libusb_error
   /''* Success (no error) ''/
   LIBUSB_SUCCESS = 0

   /''* Input/output error ''/
   LIBUSB_ERROR_IO = -1

   /''* Invalid parameter ''/
   LIBUSB_ERROR_INVALID_PARAM = -2

   /''* Access denied (insufficient permissions) ''/
   LIBUSB_ERROR_ACCESS = -3

   /''* No such device (it may have been disconnected) ''/
   LIBUSB_ERROR_NO_DEVICE = -4

   /''* Entity not found ''/
   LIBUSB_ERROR_NOT_FOUND = -5

   /''* Resource busy ''/
   LIBUSB_ERROR_BUSY = -6

   /''* Operation timed out ''/
   LIBUSB_ERROR_TIMEOUT = -7

   /''* Overflow ''/
   LIBUSB_ERROR_OVERFLOW = -8

   /''* Pipe error ''/
   LIBUSB_ERROR_PIPE = -9

   /''* System call interrupted (perhaps due to signal) ''/
   LIBUSB_ERROR_INTERRUPTED = -10

   /''* Insufficient memory ''/
   LIBUSB_ERROR_NO_MEM = -11

   /''* Operation not supported or unimplemented on this platform ''/
   LIBUSB_ERROR_NOT_SUPPORTED = -12

   /'' NB: Remember to update LIBUSB_ERROR_COUNT below as well as the
      message strings in strerror.c when adding new error codes here. ''/

   /''* Other error ''/
   LIBUSB_ERROR_OTHER = -99
End Enum

/'' Total number of error codes in enum libusb_error ''/
#define LIBUSB_ERROR_COUNT 14

/''* \ingroup libusb_asyncio
 * Transfer status codes ''/
Enum libusb_transfer_status
   /''* Transfer completed without error. Note that this does not indicate
    * that the entire amount of requested data was transferred. ''/
   LIBUSB_TRANSFER_COMPLETED

   /''* Transfer failed ''/
   LIBUSB_TRANSFER_ERROR

   /''* Transfer timed out ''/
   LIBUSB_TRANSFER_TIMED_OUT

   /''* Transfer was cancelled ''/
   LIBUSB_TRANSFER_CANCELLED

   /''* For bulk/interrupt endpoints: halt condition detected (endpoint
    * stalled). For control endpoints: control request not supported. ''/
   LIBUSB_TRANSFER_STALL

   /''* Device was disconnected ''/
   LIBUSB_TRANSFER_NO_DEVICE

   /''* Device sent more data than requested ''/
   LIBUSB_TRANSFER_OVERFLOW

   /'' NB! Remember to update libusb_error_name()
      when adding new status codes here. ''/
End Enum

/''* \ingroup libusb_asyncio
 * libusb_transfer.flags values ''/
Enum libusb_transfer_flags
   /''* Report short frames as errors ''/
   LIBUSB_TRANSFER_SHORT_NOT_OK = 1 Shl 0

   LIBUSB_TRANSFER_FREE_BUFFER = 1 Shl 1

   LIBUSB_TRANSFER_FREE_TRANSFER = 1 Shl 2

   LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 Shl 3,
End Enum

/''* \ingroup libusb_asyncio
 * Isochronous packet descriptor. ''/
Type libusb_iso_packet_descriptor
   /''* Length of data to request in this packet ''/
   As ULong length

   /''* Amount of data that was actually transferred ''/
   As ULong actual_length

   /''* Status code for this packet ''/
   As libusb_transfer_status status
End Type

Type fw_libusb_transfer As libusb_transfer

Type libusb_transfer_cb_fn As Sub(transfer As fw_libusb_transfer Ptr)

Type libusb_transfer
   /''* Handle of the device that this transfer will be submitted to ''/
   As libusb_device_handle Ptr dev_handle

   /''* A bitwise OR combination of \ref libusb_transfer_flags. ''/
   As uint8_t flags

   /''* Address of the endpoint where this transfer will be sent. ''/
   As UByte endpoint

   /''* Type of the endpoint from \ref libusb_transfer_type ''/
   As UByte Type

   /''* Timeout for this transfer in millseconds. A value of 0 indicates no
    * timeout. ''/
   As ULong timeout

   As libusb_transfer_status status

   /''* Length of the data buffer ''/
   As Long length

   As Long actual_length

   As libusb_transfer_cb_fn callback

   /''* User context data to pass to the callback function. ''/
   As Any Ptr user_data

   /''* Data buffer ''/
   As UByte Ptr buffer

   /''* Number of isochronous packets. Only used for I/O with isochronous
    * endpoints. ''/
   As Long num_iso_packets

   /''* Isochronous packet descriptors, for isochronous transfers only. ''/
   #If Defined(__STDC_VERSION_DEF__)
      As libusb_iso_packet_descriptor iso_packet_desc(Any) /'' valid C99 code ''/
   #Else
      As libusb_iso_packet_descriptor iso_packet_desc(0) /'' non-standard, but usually working code ''/
   #EndIf
End Type

Enum libusb_capability
   /''* The libusb_has_capability() API is available. ''/
   LIBUSB_CAP_HAS_CAPABILITY = &h0000
   /''* Hotplug support is available on this platform. ''/
   LIBUSB_CAP_HAS_HOTPLUG = &h0001
   /''* The library can access HID devices without requiring user intervention.
    * Note that before being able to actually access an HID device, you may
    * still have to call additional libusb functions such as
    * \ref libusb_detach_kernel_driver(). ''/
   LIBUSB_CAP_HAS_HID_ACCESS = &h0100
   /''* The library supports detaching of the default USB driver, using
    * \ref libusb_detach_kernel_driver(), if one is set by the OS kernel ''/
   LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = &h0101
End Enum

Enum libusb_log_level
   LIBUSB_LOG_LEVEL_NONE = 0
   LIBUSB_LOG_LEVEL_ERROR
   LIBUSB_LOG_LEVEL_WARNING
   LIBUSB_LOG_LEVEL_INFO
   LIBUSB_LOG_LEVEL_DEBUG
End Enum

Declare Function libusb_init(ctx As libusb_context Ptr Ptr) As Long
Declare Sub libusb_exit(ctx As libusb_context Ptr)
Declare Sub libusb_set_debug(ctx As libusb_context Ptr, level As Long)
Declare Function libusb_get_version() As Const libusb_version Ptr
Declare Function libusb_has_capability(capability As uint32_t) As Long
Declare Function libusb_error_name(errcode As Long) As Const ZString Ptr
Declare Function libusb_setlocale(locale As  UByte Ptr) As Long
Declare Function libusb_strerror(errcode As Long) As Const ZString Ptr

Declare Function libusb_get_device_list(ctx As libusb_context Ptr, list As libusb_device Ptr Ptr Ptr) As ssize_t
Declare Sub libusb_free_device_list(list As libusb_device Ptr Ptr, unref_devices As Long)
Declare Function libusb_ref_device(dev As libusb_device Ptr) As libusb_device Ptr
Declare Sub libusb_unref_device(dev As libusb_device Ptr)

Declare Function libusb_get_configuration( _
                        dev As libusb_device_handle Ptr, _
                        config As Long Ptr) As Long
Declare Function libusb_get_device_descriptor( _
                        dev As libusb_device Ptr, _
                        desc As libusb_device_descriptor Ptr) As Long
Declare Function libusb_get_active_config_descriptor( _
                        dev As libusb_device Ptr, _
                        config As libusb_config_descriptor Ptr Ptr) As Long
Declare Function libusb_get_config_descriptor( _
                        dev As libusb_device Ptr, _
                        config_index As uint8_t, _
                        config As libusb_config_descriptor Ptr Ptr) As Long
Declare Function libusb_get_config_descriptor_by_value( _
                        dev As libusb_device Ptr, _
                        bConfigurationValue As uint8_t, _
                        config As libusb_config_descriptor Ptr Ptr) As Long
Declare Sub libusb_free_config_descriptor(config As libusb_config_descriptor Ptr)
Declare Function libusb_get_ss_endpoint_companion_descriptor( _
                        ctx As libusb_context Ptr, _
                        endpoint As Const libusb_endpoint_descriptor Ptr, _
                        ep_comp As libusb_ss_endpoint_companion_descriptor Ptr Ptr) As Long
Declare Sub libusb_free_ss_endpoint_companion_descriptor( _
                        ep_comp As libusb_ss_endpoint_companion_descriptor Ptr)
                       
Declare Function libusb_get_bos_descriptor( _
                        dev_handle As libusb_device_handle Ptr, _
                        bos As libusb_bos_descriptor Ptr Ptr) As Long
Declare Sub libusb_free_bos_descriptor(bos As libusb_bos_descriptor Ptr)
Declare Function libusb_get_usb_2_0_extension_descriptor( _
                        ctx As libusb_context Ptr, _
                        dev_cap As libusb_bos_dev_capability_descriptor Ptr, _
                        usb_2_0_extension As libusb_usb_2_0_extension_descriptor Ptr Ptr) As Long
Declare Sub libusb_free_usb_2_0_extension_descriptor(usb_2_0_extension As libusb_usb_2_0_extension_descriptor Ptr)
Declare Function libusb_get_ss_usb_device_capability_descriptor( _
                        ctx As libusb_context Ptr, _
                        dev_cap As libusb_bos_dev_capability_descriptor Ptr, _
                        ss_usb_device_cap As libusb_ss_usb_device_capability_descriptor Ptr Ptr) As Long
Declare Sub libusb_free_ss_usb_device_capability_descriptor(ss_usb_device_cap As libusb_ss_usb_device_capability_descriptor Ptr)
Declare Function libusb_get_container_id_descriptor( _
                        ctx As libusb_context Ptr, _
                        dev_cap As libusb_bos_dev_capability_descriptor Ptr, _
                        container_id As libusb_container_id_descriptor Ptr Ptr) As Long
Declare Sub libusb_free_container_id_descriptor( _
                        container_id As libusb_container_id_descriptor Ptr)
Declare Function libusb_get_bus_number(dev As libusb_device Ptr) As uint8_t
Declare Function libusb_get_port_number(dev As libusb_device Ptr) As uint8_t
Declare Function libusb_get_port_numbers( _
                        dev As libusb_device Ptr, _
                        port_numbers As uint8_t Ptr, _
                        port_numbers_len As Long) As Long
''LIBUSB_DEPRECATED_FOR(libusb_get_port_numbers)
Declare Function libusb_get_port_path( _
                        ctx As libusb_context Ptr, _
                        dev As libusb_device Ptr, _
                        path As ZString Ptr, _
                        path_length As uint8_t) As Long
Declare Function libusb_get_parent(dev As libusb_device Ptr) As libusb_device Ptr
Declare Function libusb_get_device_address(dev As libusb_device Ptr) As uint8_t
Declare Function libusb_get_device_speed(dev As libusb_device Ptr) As Long
Declare Function libusb_get_max_packet_size( _
                        dev As libusb_device Ptr, _
                        endpoint As UByte) As Long
Declare Function libusb_get_max_iso_packet_size(dev As libusb_device Ptr, endpoint As UByte) As Long

Declare Function libusb_open(dev As libusb_device Ptr, dev_handle As libusb_device_handle Ptr Ptr) As Long
Declare Sub libusb_close(dev_handle As libusb_device_handle Ptr)
Declare Function libusb_get_device(dev_handle As libusb_device_handle Ptr) As libusb_device Ptr

Declare Function libusb_set_configuration( _
                        dev_handle As libusb_device_handle Ptr, _
                        configuration As Long) As Long
Declare Function libusb_claim_interface( _
                        dev_handle As libusb_device_handle Ptr, _
                        interface_number As Long) As Long
Declare Function libusb_release_interface( _
                        dev_handle As libusb_device_handle Ptr, _
                        interface_number As Long) As Long

Declare Function libusb_open_device_with_vid_pid( _
                        ctx As libusb_context Ptr, _
                        vendor_id As uint16_t, _
                        product_id As uint16_t) As libusb_device_handle Ptr

Declare Function libusb_set_interface_alt_setting( _
                        dev_handle As libusb_device_handle Ptr, _
                        interface_number As Long, _
                        alternate_setting As Long) As Long
Declare Function libusb_clear_halt( _
                        dev_handle As libusb_device_handle Ptr, _
                        endpoint As UByte) As Long
Declare Function libusb_reset_device(dev_handle As libusb_device_handle Ptr)As Long

Declare Function libusb_alloc_streams( _
                        dev_handle As libusb_device_handle Ptr, _
                        num_streams As uint32_t, _
                        endpoints As UByte Ptr, _
                        num_endpoints As Long) As Long
Declare Function libusb_free_streams( _
                        dev_handle As libusb_device_handle Ptr, _
                        endpoints As UByte Ptr, _
                        num_endpoints As Long) As Long

Declare Function libusb_dev_mem_alloc( _
                        dev_handle As libusb_device_handle Ptr, _
                        length As size_t) As UByte Ptr
Declare Function libusb_dev_mem_free( _
                        dev_handle As libusb_device_handle Ptr, _
                        buffer As UByte Ptr, _
                        length As size_t) As Long

Declare Function libusb_kernel_driver_active( _
                        dev_handle As libusb_device_handle Ptr, _
                        interface_number As Long) As Long
Declare Function libusb_detach_kernel_driver( _
                        dev_handle As libusb_device_handle Ptr, _
                        interface_number As Long) As Long
Declare Function libusb_attach_kernel_driver( _
                        dev_handle As libusb_device_handle Ptr, _
                        interface_number As Long) As Long
Declare Function libusb_set_auto_detach_kernel_driver( _
                        dev_handle As libusb_device_handle Ptr, _
                        enable As Long) As Long

Function libusb_control_transfer_get_data(transfer As libusb_transfer Ptr) As ZString Ptr
   Return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE
End Function

Function libusb_control_transfer_get_setup(transfer As libusb_transfer Ptr) As libusb_control_setup Ptr
   Return Cast(libusb_control_setup Ptr, transfer->buffer)
End Function
 
Sub libusb_fill_control_setup( _
           buffer As UByte Ptr, _
           bmRequestType As uint8_t, _
           bRequest As uint8_t, _
           wValue As uint16_t, _
           wIndex As uint16_t, _
           wLength As uint16_t)
   Dim As libusb_control_setup Ptr setup
   setup = Cast(libusb_control_setup Ptr, buffer)
   setup->bmRequestType = bmRequestType
   setup->bRequest = bRequest
   setup->wValue = libusb_cpu_to_le16(wValue)
   setup->wIndex = libusb_cpu_to_le16(wIndex)
   setup->wLength = libusb_cpu_to_le16(wLength)       
End Sub
             
Declare Function libusb_alloc_transfer(iso_packets As Long) As libusb_transfer Ptr
Declare Function libusb_submit_transfer(transfer As libusb_transfer Ptr) As Long
Declare Function libusb_cancel_transfer(transfer As libusb_transfer Ptr) As Long
Declare Sub libusb_free_transfer(transfer As libusb_transfer Ptr)
Declare Sub libusb_transfer_set_stream_id( _
                   transfer As libusb_transfer Ptr, _
                   stream_id As uint32_t)
Declare Function libusb_transfer_get_stream_id(transfer As libusb_transfer Ptr) As uint32_t

Sub libusb_fill_control_transfer( _
           transfer As libusb_transfer Ptr, _
           dev_handle As libusb_device_handle Ptr, _
           buffer As UByte Ptr, _
           callback As libusb_transfer_cb_fn, _
           user_data As Any Ptr, _
           timeout As ULong)
           
  Dim As libusb_control_setup Ptr setup
  setup = Cast(libusb_control_setup Ptr, buffer)
   transfer->dev_handle = dev_handle
   transfer->endpoint = 0
   transfer->Type = LIBUSB_TRANSFER_TYPE_CONTROL
   transfer->timeout = timeout
   transfer->buffer = buffer
   If setup Then
      transfer->length = Cast(Long, LIBUSB_CONTROL_SETUP_SIZE + libusb_le16_to_cpu(setup->wLength))
   EndIf
   transfer->user_data = user_data
   transfer->callback = callback   
End Sub

Sub libusb_fill_bulk_transfer( _
           transfer As libusb_transfer Ptr, _
           dev_handle As libusb_device_handle Ptr, _
           endpoint As UByte, _
           buffer As UByte Ptr, _
           length As Long, _
           callback As libusb_transfer_cb_fn, _
           user_data As Any Ptr, _
           timeout As ULong)

   transfer->dev_handle = dev_handle
   transfer->endpoint = endpoint
   transfer->Type = LIBUSB_TRANSFER_TYPE_BULK
   transfer->timeout = timeout
   transfer->buffer = buffer
   transfer->length = length
   transfer->user_data = user_data
   transfer->callback = callback
End Sub

Sub libusb_fill_bulk_stream_transfer( _
           transfer As libusb_transfer Ptr, _
           dev_handle As libusb_device_handle Ptr, _
           endpoint As UByte, _
           stream_id As uint32_t, _
           buffer As UByte Ptr, _
           length As Long, _
           callback As libusb_transfer_cb_fn, _
           user_data As Any Ptr, _
           timeout As ULong)

   libusb_fill_bulk_transfer(transfer, dev_handle, endpoint, buffer, _
         length, callback, user_data, timeout)
   transfer->Type = LIBUSB_TRANSFER_TYPE_BULK_STREAM
   libusb_transfer_set_stream_id(transfer, stream_id)
End Sub

Sub libusb_fill_interrupt_transfer( _
           transfer As libusb_transfer Ptr, _
           dev_handle As libusb_device_handle Ptr, _
           endpoint As UByte, _
           buffer As UByte Ptr, _
           length As Long, _
           callback As libusb_transfer_cb_fn, _
           user_data As Any Ptr, _
           timeout As ULong)

   transfer->dev_handle = dev_handle
   transfer->endpoint = endpoint
   transfer->Type = LIBUSB_TRANSFER_TYPE_INTERRUPT
   transfer->timeout = timeout
   transfer->buffer = buffer
   transfer->length = length
   transfer->user_data = user_data
   transfer->callback = callback
End Sub

Sub libusb_fill_iso_transfer( _
           transfer As libusb_transfer Ptr, _
           dev_handle As libusb_device_handle Ptr, _
           endpoint As UByte, _
           buffer As UByte Ptr, _
           length As Long, _
           num_iso_packets As Long, _
           callback As libusb_transfer_cb_fn, _
           user_data As Any Ptr, _
           timeout As ULong)
 
   transfer->dev_handle = dev_handle
   transfer->endpoint = endpoint
   transfer->Type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS
   transfer->timeout = timeout
   transfer->buffer = buffer
   transfer->length = length
   transfer->num_iso_packets = num_iso_packets
   transfer->user_data = user_data
   transfer->callback = callback
End Sub

Sub libusb_set_iso_packet_lengths( _
           transfer As libusb_transfer Ptr, _
           length As ULong)
   Dim As Long i
   For i = 0 To transfer->num_iso_packets
      transfer->iso_packet_desc(i).length = length
   Next
      
End Sub

Function libusb_get_iso_packet_buffer( _
                transfer As libusb_transfer Ptr, _
                packet As ULong) As UByte Ptr

   Dim As Long i
   Dim As size_t offset = 0
   Dim As Long _packet

   /'' oops..slight bug in the API. packet is an unsigned int, but we use
    * signed integers almost everywhere else. range-check and convert to
    * signed to avoid compiler warnings. FIXME for libusb-2. ''/
   If (packet > INT_MAX) Then
      Return NULL
   EndIf
   _packet = Cast(Long, packet)

   If _packet >= transfer->num_iso_packets Then
      Return NULL
   EndIf

   For i = 0 To _packet
      offset += transfer->iso_packet_desc(i).length
   Next

   Return transfer->buffer + offset
End Function

Function libusb_get_iso_packet_buffer_simple( _
                transfer As libusb_transfer Ptr, _
                packet As Long) As UByte Ptr
 
   Dim As Long _packet

   /'' oops..slight bug in the API. packet is an unsigned int, but we use
    * signed integers almost everywhere else. range-check and convert to
    * signed to avoid compiler warnings. FIXME for libusb-2. ''/
   If (packet > INT_MAX) Then
      Return NULL
   EndIf
   _packet = Cast(Long, packet)

   If _packet >= transfer->num_iso_packets Then
      Return NULL
   EndIf

   Return transfer->buffer + (Cast(Long, transfer->iso_packet_desc(0).length) * _packet)
End Function

/'' sync I/O ''/

Declare Function libusb_control_transfer( _
                        dev_handle As libusb_device_handle Ptr, _
                        request_type As uint8_t, _
                        bRequest As uint8_t, _
                        wValue As uint16_t, _
                        wIndex As uint16_t, _
                        _Data As UByte Ptr, _
                        wLength As uint16_t, _
                        timeout As ULong) As Long

Declare Function libusb_bulk_transfer( _
                        dev_handle As libusb_device_handle Ptr, _
                        endpoint As UByte, _
                        _Data As UByte Ptr, _
                        length As Long, _
                        actual_length As Long Ptr, _
                        timeout As ULong) As Long

Declare Function libusb_interrupt_transfer( _
                        dev_handle As libusb_device_handle Ptr, _
                        endpoint As UByte, _
                        _Data As UByte Ptr, _
                        length As Long, _
                        actual_length As Long Ptr, _
                        timeout As ULong) As Long

Function libusb_get_descriptor( _
                dev_handle As libusb_device_handle Ptr, _
                desc_type As uint8_t, _
                desc_index As uint8_t, _
                _Data As UByte Ptr, _
                length As Long) As Long

   Return libusb_control_transfer(dev_handle, _
                                  LIBUSB_ENDPOINT_IN, _
                                  LIBUSB_REQUEST_GET_DESCRIPTOR, _
                                  Cast(uint16_t, ((desc_type Shl 8) Or desc_index)), _
                                  0, _
                                  _Data, _
                                  Cast(uint16_t, length), _
                                  1000)
End Function

Function libusb_get_string_descriptor( _
                dev_handle As libusb_device_handle Ptr, _
                desc_index As uint8_t, _
                langid As uint16_t, _
                _Data As UByte Ptr, _
                length As Long) As Long

   Return libusb_control_transfer(dev_handle, _
                                  LIBUSB_ENDPOINT_IN, _
                                   LIBUSB_REQUEST_GET_DESCRIPTOR, _
                                   Cast(uint16_t,((LIBUSB_DT_STRING Shl 8) Or desc_index)), _
                                   langid, _
                                   _Data, _
                                   Cast(uint16_t, length), _
                                   1000)
End Function

Declare Function libusb_get_string_descriptor_ascii( _
                        dev_handle As libusb_device_handle Ptr, _
                        desc_index As uint8_t, _
                        _Data As UByte Ptr, _
                        length As Long) As Long

/'' polling and timeouts ''/

Declare Function libusb_try_lock_events(ctx As libusb_context Ptr) As Long
Declare Sub libusb_lock_events(ctx As libusb_context Ptr)
Declare Sub libusb_unlock_events(ctx As libusb_context Ptr)
Declare Function libusb_event_handling_ok(ctx As libusb_context Ptr) As Long
Declare Function libusb_event_handler_active(ctx As libusb_context Ptr) As Long
Declare Sub libusb_interrupt_event_handler(ctx As libusb_context Ptr)
Declare Sub libusb_lock_event_waiters(ctx As libusb_context Ptr)
Declare Sub libusb_unlock_event_waiters(ctx As libusb_context Ptr)
Declare Function libusb_wait_for_event(ctx As libusb_context Ptr, tv As timeval Ptr) As Long

Declare Function libusb_handle_events_timeout(ctx As libusb_context Ptr, tv As timeval Ptr) As Long
Declare Function libusb_handle_events_timeout_completed( _
                        ctx As libusb_context Ptr, _
                        tv As timeval Ptr, _
                        completed As Long Ptr) As Long
Declare Function libusb_handle_events(ctx As libusb_context Ptr) As Long
Declare Function libusb_handle_events_completed(ctx As libusb_context Ptr, completed As Long Ptr) As Long
Declare Function libusb_handle_events_locked(ctx As libusb_context Ptr, tv As timeval Ptr) As Long
Declare Function libusb_pollfds_handle_timeouts(ctx As libusb_context Ptr) As Long
Declare Function libusb_get_next_timeout(ctx As libusb_context Ptr, tv As timeval Ptr) As Long

/''* \ingroup libusb_poll
 * File descriptor for polling
 ''/
Type libusb_pollfd
   /''* Numeric file descriptor ''/
   As Long fd

   As Short events
End Type

Type libusb_pollfd_added_cb As Sub(fd As Long, events As Short, user_data As Any Ptr)

Type libusb_pollfd_removed_cb As Sub(fd As Long, user_data As Any Ptr)

Declare Function libusb_get_pollfds(ctx As libusb_context Ptr) As Const libusb_pollfd Ptr Ptr
Declare Sub libusb_free_pollfds(pollfds As Const libusb_pollfd Ptr Ptr)
Declare Sub libusb_set_pollfd_notifiers( _
                   ctx As libusb_context Ptr, _
                   added_cb As libusb_pollfd_added_cb, _
                   removed_cb As libusb_pollfd_removed_cb, _
                   user_data As Any Ptr)

Type libusb_hotplug_callback_handle As Long

/''* \ingroup libusb_hotplug
 *
 * Since version 1.0.16, \ref LIBUSB_API_VERSION >= &h01000102
 *
 * Flags for hotplug events ''/

Enum lusb_hpf
   /''* Default value when not using any flags. ''/
   LIBUSB_HOTPLUG_NO_FLAGS = 0

   /''* Arm the callback and fire it for all matching currently attached devices. ''/
   LIBUSB_HOTPLUG_ENUMERATE = 1 Shl 0
End Enum

Type libusb_hotplug_flag As lusb_hpf
   
/''* \ingroup libusb_hotplug
 *
 * Since version 1.0.16, \ref LIBUSB_API_VERSION >= &h01000102
 *
 * Hotplug events ''/
Enum lusb_hpe
   /''* A device has been plugged in and is ready to use ''/
   LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = &h01

   /''* A device has left and is no longer available.
    * It is the user''s responsibility to call libusb_close on any handle associated with a disconnected device.
    * It is safe to call libusb_get_device_descriptor on a device that has left ''/
   LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT    = &h02
End Enum

Type libusb_hotplug_event As lusb_hpe
   
/''* \ingroup libusb_hotplug
 * Wildcard matching for hotplug events ''/
#define LIBUSB_HOTPLUG_MATCH_ANY -1

Type libusb_hotplug_callback_fn As Function( _
            ctx As libusb_context Ptr, _
                  device As libusb_device Ptr, _
                 event As libusb_hotplug_event, _
                 user_data As Any Ptr) As Long
                
Declare Function libusb_hotplug_register_callback( _
                        ctx As libusb_context Ptr, _
                              events As libusb_hotplug_event, _
                             flags As libusb_hotplug_flag, _
                             vendor_id As Long, _
                             product_id As Long, _
                             dev_class As Long, _
                              cb_fn As libusb_hotplug_callback_fn, _
                             user_data As Any Ptr, _
                              callback_handle As libusb_hotplug_callback_handle Ptr) As Long

Declare Sub libusb_hotplug_deregister_callback( _
                   ctx As libusb_context Ptr, _
                         callback_handle As libusb_hotplug_callback_handle)

End Extern
#EndIf
badidea
Posts: 751
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Libusb

Postby badidea » Jun 01, 2018 22:02

With this modified code:

Code: Select all

#include once "usb.bi"

Dim shared as libusb_device_descriptor desc
Dim shared as libusb_device Ptr Ptr dev
Dim shared as libusb_device_handle Ptr Ptr dev_handle
Dim shared as libusb_device Ptr Ptr devs
Dim shared as Long i = 0, j = 0, r = 0
Dim shared as UByte path(8)
Dim shared as ssize_t cnt

Sub print_devs(devs As libusb_device Ptr Ptr)
   dev = devs[0]
   '--------Look for one of two -----------------
   While dev <> NULL
        r = libusb_get_device_descriptor(dev, @desc)     
        Print r,dev
        If r < 0 Then
            Print "failed to get device descriptor"
            Return
        EndIf
        Print "Hex(desc.idVendor,4): "; Hex(desc.idVendor,4)
        Print "Hex(desc.idProduct,4): "; Hex(desc.idProduct,4)
        Print "bcdDevice  ;"; hex(desc.bcdDevice \ 256) ; "." ; hex(desc.bcdDevice mod 256)
       
        '~ If Hex(desc.idVendor,4) = "0A07" And Hex(desc.idProduct,4) = "0046" Then
        '~ 'If Hex(desc.idVendor,4) = "8087" And Hex(desc.idProduct,4) = "0a2a" Then
            '~ Print "Found one ;";dev
            '~ Print Hex(desc.idVendor,4);":";Hex(desc.idProduct,4)
            '~ Print "bcdDevice  ;"; desc.bcdDevice
            '~ Print "Serial Nbr ;"; desc.iSerialNumber
            '~ r = libusb_open(@dev, dev_handle)
            '~ Print "dev_handle ;"; dev_handle
            '~ Print "Error Detail ;";r
            '~ Print *(libusb_error_name(r))
            '~ Print
        '~ EndIf
        i += 1
        dev = devs[i]
   Wend
   '---------------------------------------------
End Sub

    r = libusb_init(NULL)
    If r < 0 Then
        End r
    EndIf
    cnt = libusb_get_device_list(NULL, @devs)
    If cnt < 0 Then
        End cnt
    EndIf
    print_devs(devs)
    libusb_free_device_list(devs, 1)
   
    libusb_exit(NULL)
    ? "OK"
    Sleep

I get some working output:

Code: Select all

 0            15224096
Hex(desc.idVendor,4): 0A5C
Hex(desc.idProduct,4): 5804
bcdDevice  ;1.1
 0            15311088
Hex(desc.idVendor,4): 1BCF
Hex(desc.idProduct,4): 2B8D
bcdDevice  ;46.16
 0            15258720
Hex(desc.idVendor,4): 8087
Hex(desc.idProduct,4): 0A2A
bcdDevice  ;0.1
 0            15242304
Hex(desc.idVendor,4): 8087
Hex(desc.idProduct,4): 8001
bcdDevice  ;0.3
 0            15264640
Hex(desc.idVendor,4): 1D6B
Hex(desc.idProduct,4): 0002
bcdDevice  ;4.4
 0            15299648
Hex(desc.idVendor,4): 1D6B
Hex(desc.idProduct,4): 0003
bcdDevice  ;4.4
 0            15258912
Hex(desc.idVendor,4): 1D6B
Hex(desc.idProduct,4): 0002
bcdDevice  ;4.4
OK

My lsusb -v output:

Code: Select all

Bus 001 Device 005: ID 0a5c:5804 Broadcom Corp. BCM5880 Secure Applications Processor with fingerprint swipe sensor
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x0a5c Broadcom Corp.
  idProduct          0x5804 BCM5880 Secure Applications Processor with fingerprint swipe sensor
  bcdDevice            1.01
  iManufacturer           1
  iProduct                2
  iSerial                 3
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          269
    bNumInterfaces          4
    bConfigurationValue     0
    iConfiguration          0
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       254 Application Specific Interface
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              4
      ** UNRECOGNIZED:  10 25 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x85  EP 5 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval              32
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass        11 Chip/SmartCard
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              5
      ChipCard Interface Descriptor:
        bLength                54
        bDescriptorType        33
        bcdCCID              1.00
        nMaxSlotIndex           0
        bVoltageSupport         7  5.0V 3.0V 1.8V
        dwProtocols             3  T=0 T=1
        dwDefaultClock       4000
        dwMaxiumumClock      4000
        bNumClockSupported      0
        dwDataRate           9600 bps
        dwMaxDataRate      250000 bps
        bNumDataRatesSupp.      0
        dwMaxIFSD             247
        dwSyncProtocols  00000000
        dwMechanical     00000000
        dwFeatures       000102BA
          Auto configuration based on ATR
          Auto voltage selection
          Auto clock change
          Auto baud rate change
          Auto PPS made by CCID
          NAD value other than 0x00 accepted
          TPDU level exchange
        dwMaxCCIDMsgLen       271
        bClassGetResponse      00
        bClassEnvelope         00
        wlcdLayout           none
        bPINSupport             0
        bMaxCCIDBusySlots       1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x86  EP 6 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval              32
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass        11 Chip/SmartCard
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              6
      ChipCard Interface Descriptor:
        bLength                54
        bDescriptorType        33
        bcdCCID              1.01  (Warning: Only accurate for version 1.0)
        nMaxSlotIndex           0
        bVoltageSupport         1  5.0V
        dwProtocols             3  T=0 T=1
        dwDefaultClock       3580
        dwMaxiumumClock      3580
        bNumClockSupported      1
        dwDataRate           9600 bps
        dwMaxDataRate        9600 bps
        bNumDataRatesSupp.      1
        dwMaxIFSD             254
        dwSyncProtocols  00000000
        dwMechanical     00000000
        dwFeatures       000204BA
          Auto configuration based on ATR
          Auto voltage selection
          Auto clock change
          Auto baud rate change
          Auto PPS made by CCID
          Auto IFSD exchange
          Short APDU level exchange
        dwMaxCCIDMsgLen       512
        bClassGetResponse      00
        bClassEnvelope         00
        wlcdLayout           none
        bPINSupport             0
        bMaxCCIDBusySlots       1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x87  EP 7 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval              32
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        3
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              8
      ** UNRECOGNIZED:  10 26 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x84  EP 4 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x04  EP 4 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x88  EP 8 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval              32

Bus 001 Device 004: ID 1bcf:2b8d Sunplus Innovation Technology Inc.
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          239 Miscellaneous Device
  bDeviceSubClass         2 ?
  bDeviceProtocol         1 Interface Association
  bMaxPacketSize0        64
  idVendor           0x1bcf Sunplus Innovation Technology Inc.
  idProduct          0x2b8d
  bcdDevice           46.16
  iManufacturer           1
  iProduct                2
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          737
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              500mA
    Interface Association:
      bLength                 8
      bDescriptorType        11
      bFirstInterface         0
      bInterfaceCount         2
      bFunctionClass         14 Video
      bFunctionSubClass       3 Video Interface Collection
      bFunctionProtocol       0
      iFunction               4
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      1 Video Control
      bInterfaceProtocol      0
      iInterface              4
      VideoControl Interface Descriptor:
        bLength                13
        bDescriptorType        36
        bDescriptorSubtype      1 (HEADER)
        bcdUVC               1.00
        wTotalLength          109
        dwClockFrequency       48.000000MHz
        bInCollection           1
        baInterfaceNr( 0)       1
      VideoControl Interface Descriptor:
        bLength                18
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID             1
        wTerminalType      0x0201 Camera Sensor
        bAssocTerminal          0
        iTerminal               0
        wObjectiveFocalLengthMin      0
        wObjectiveFocalLengthMax      0
        wOcularFocalLength            0
        bControlSize                  3
        bmControls           0x0000000e
          Auto-Exposure Mode
          Auto-Exposure Priority
          Exposure Time (Absolute)
      VideoControl Interface Descriptor:
        bLength                11
        bDescriptorType        36
        bDescriptorSubtype      5 (PROCESSING_UNIT)
      Warning: Descriptor too short
        bUnitID                 2
        bSourceID               1
        wMaxMultiplier      16384
        bControlSize            2
        bmControls     0x0000157f
          Brightness
          Contrast
          Hue
          Saturation
          Sharpness
          Gamma
          White Balance Temperature
          Backlight Compensation
          Power Line Frequency
          White Balance Temperature, Auto
        iProcessing             0
        bmVideoStandards     0x1d
          None
          PAL - 625/50
          SECAM - 625/50
          NTSC - 625/50
      VideoControl Interface Descriptor:
        bLength                29
        bDescriptorType        36
        bDescriptorSubtype      6 (EXTENSION_UNIT)
        bUnitID                 3
        guidExtensionCode         {c385b80f-c268-4745-90f7-8f47579d95fc}
        bNumControl             0
        bNrPins                 1
        baSourceID( 0)          2
        bControlSize            4
        bmControls( 0)       0x1f
        bmControls( 1)       0x00
        bmControls( 2)       0x00
        bmControls( 3)       0x00
        iExtension              0
      VideoControl Interface Descriptor:
        bLength                29
        bDescriptorType        36
        bDescriptorSubtype      6 (EXTENSION_UNIT)
        bUnitID                 4
        guidExtensionCode         {82066163-7050-ab49-b8cc-b3855e8d221d}
        bNumControl             0
        bNrPins                 1
        baSourceID( 0)          3
        bControlSize            4
        bmControls( 0)       0xff
        bmControls( 1)       0xff
        bmControls( 2)       0x71
        bmControls( 3)       0x00
        iExtension              0
      VideoControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (OUTPUT_TERMINAL)
        bTerminalID             5
        wTerminalType      0x0101 USB Streaming
        bAssocTerminal          0
        bSourceID               4
        iTerminal               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x87  EP 7 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval               8
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      VideoStreaming Interface Descriptor:
        bLength                            15
        bDescriptorType                    36
        bDescriptorSubtype                  1 (INPUT_HEADER)
        bNumFormats                         2
        wTotalLength                      365
        bEndPointAddress                  129
        bmInfo                              0
        bTerminalLink                       5
        bStillCaptureMethod                 1
        bTriggerSupport                     1
        bTriggerUsage                       0
        bControlSize                        1
        bmaControls( 0)                    27
        bmaControls( 1)                    27
      VideoStreaming Interface Descriptor:
        bLength                            27
        bDescriptorType                    36
        bDescriptorSubtype                  4 (FORMAT_UNCOMPRESSED)
        bFormatIndex                        1
        bNumFrameDescriptors                7
        guidFormat                            {59555932-0000-1000-8000-00aa00389b71}
        bBitsPerPixel                      16
        bDefaultFrameIndex                  1
        bAspectRatioX                       0
        bAspectRatioY                       0
        bmInterlaceFlags                 0x00
          Interlaced stream or variable: No
          Fields per frame: 2 fields
          Field 1 first: No
          Field pattern: Field 1 only
          bCopyProtect                      0
      VideoStreaming Interface Descriptor:
        bLength                            30
        bDescriptorType                    36
        bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
        bFrameIndex                         1
        bmCapabilities                   0x01
          Still image supported
        wWidth                            640
        wHeight                           480
        dwMinBitRate                147456000
        dwMaxBitRate                147456000
        dwMaxVideoFrameBufferSize      614400
        dwDefaultFrameInterval         333333
        bFrameIntervalType                  1
        dwFrameInterval( 0)            333333
      VideoStreaming Interface Descriptor:
        bLength                            30
        bDescriptorType                    36
        bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
        bFrameIndex                         2
        bmCapabilities                   0x01
          Still image supported
        wWidth                            160
        wHeight                           120
        dwMinBitRate                  9216000
        dwMaxBitRate                  9216000
        dwMaxVideoFrameBufferSize       38400
        dwDefaultFrameInterval         333333
        bFrameIntervalType                  1
        dwFrameInterval( 0)            333333
      VideoStreaming Interface Descriptor:
        bLength                            30
        bDescriptorType                    36
        bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
        bFrameIndex                         3
        bmCapabilities                   0x01
          Still image supported
        wWidth                            320
        wHeight                           180
        dwMinBitRate                 27648000
        dwMaxBitRate                 27648000
        dwMaxVideoFrameBufferSize      115200
        dwDefaultFrameInterval         333333
        bFrameIntervalType                  1
        dwFrameInterval( 0)            333333
      VideoStreaming Interface Descriptor:
        bLength                            30
        bDescriptorType                    36
        bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
        bFrameIndex                         4
        bmCapabilities                   0x01
          Still image supported
        wWidth                            320
        wHeight                           240
        dwMinBitRate                 36864000
        dwMaxBitRate                 36864000
        dwMaxVideoFrameBufferSize      153600
        dwDefaultFrameInterval         333333
        bFrameIntervalType                  1
        dwFrameInterval( 0)            333333
      VideoStreaming Interface Descriptor:
        bLength                            30
        bDescriptorType                    36
        bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
        bFrameIndex                         5
        bmCapabilities                   0x01
          Still image supported
        wWidth                            424
        wHeight                           240
        dwMinBitRate                 48844800
        dwMaxBitRate                 48844800
        dwMaxVideoFrameBufferSize      203520
        dwDefaultFrameInterval         333333
        bFrameIntervalType                  1
        dwFrameInterval( 0)            333333
      VideoStreaming Interface Descriptor:
        bLength                            30
        bDescriptorType                    36
        bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
        bFrameIndex                         6
        bmCapabilities                   0x01
          Still image supported
        wWidth                            640
        wHeight                           360
        dwMinBitRate                110592000
        dwMaxBitRate                110592000
        dwMaxVideoFrameBufferSize      460800
        dwDefaultFrameInterval         333333
        bFrameIntervalType                  1
        dwFrameInterval( 0)            333333
      VideoStreaming Interface Descriptor:
        bLength                            30
        bDescriptorType                    36
        bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
        bFrameIndex                         7
        bmCapabilities                   0x01
          Still image supported
        wWidth                            640
        wHeight                           480
        dwMinBitRate                147456000
        dwMaxBitRate                147456000
        dwMaxVideoFrameBufferSize      614400
        dwDefaultFrameInterval         333333
        bFrameIntervalType                  1
        dwFrameInterval( 0)            333333
      VideoStreaming Interface Descriptor:
        bLength                             6
        bDescriptorType                    36
        bDescriptorSubtype                 13 (COLORFORMAT)
        bColorPrimaries                     1 (BT.709,sRGB)
        bTransferCharacteristics            1 (BT.709)
        bMatrixCoefficients                 4 (SMPTE 170M (BT.601))
      VideoStreaming Interface Descriptor:
        bLength                            11
        bDescriptorType                    36
        bDescriptorSubtype                  6 (FORMAT_MJPEG)
        bFormatIndex                        2
        bNumFrameDescriptors                3
        bFlags                              1
          Fixed-size samples: Yes
        bDefaultFrameIndex                  1
        bAspectRatioX                       0
        bAspectRatioY                       0
        bmInterlaceFlags                 0x00
          Interlaced stream or variable: No
          Fields per frame: 1 fields
          Field 1 first: No
          Field pattern: Field 1 only
          bCopyProtect                      0
      VideoStreaming Interface Descriptor:
        bLength                            30
        bDescriptorType                    36
        bDescriptorSubtype                  7 (FRAME_MJPEG)
        bFrameIndex                         8
        bmCapabilities                   0x01
          Still image supported
        wWidth                            848
        wHeight                           480
        dwMinBitRate                195379200
        dwMaxBitRate                195379200
        dwMaxVideoFrameBufferSize      814080
        dwDefaultFrameInterval         333333
        bFrameIntervalType                  1
        dwFrameInterval( 0)            333333
      VideoStreaming Interface Descriptor:
        bLength                            30
        bDescriptorType                    36
        bDescriptorSubtype                  7 (FRAME_MJPEG)
        bFrameIndex                         9
        bmCapabilities                   0x01
          Still image supported
        wWidth                            960
        wHeight                           540
        dwMinBitRate                248832000
        dwMaxBitRate                248832000
        dwMaxVideoFrameBufferSize     1036800
        dwDefaultFrameInterval         333333
        bFrameIntervalType                  1
        dwFrameInterval( 0)            333333
      VideoStreaming Interface Descriptor:
        bLength                            30
        bDescriptorType                    36
        bDescriptorSubtype                  7 (FRAME_MJPEG)
        bFrameIndex                        10
        bmCapabilities                   0x01
          Still image supported
        wWidth                           1280
        wHeight                           720
        dwMinBitRate                442368000
        dwMaxBitRate                442368000
        dwMaxVideoFrameBufferSize     1843200
        dwDefaultFrameInterval         333333
        bFrameIntervalType                  1
        dwFrameInterval( 0)            333333
      VideoStreaming Interface Descriptor:
        bLength                             6
        bDescriptorType                    36
        bDescriptorSubtype                 13 (COLORFORMAT)
        bColorPrimaries                     1 (BT.709,sRGB)
        bTransferCharacteristics            1 (BT.709)
        bMatrixCoefficients                 4 (SMPTE 170M (BT.601))
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x00c0  1x 192 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       2
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0180  1x 384 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       3
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       4
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0280  1x 640 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       5
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0320  1x 800 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       6
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x03b0  1x 944 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       7
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0a80  2x 640 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       8
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0b20  2x 800 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       9
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0be0  2x 992 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting      10
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x13c0  3x 960 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting      11
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x13fc  3x 1020 bytes
        bInterval               1
        ** UNRECOGNIZED:  28 ff 42 49 53 54 00 01 06 02 78 00 00 00 00 00 01 04 e8 03 02 05 e8 03 03 06 e8 03 04 07 e8 03 05 08 e8 03 06 09 e8 03

Bus 001 Device 003: ID 8087:0a2a Intel Corp.
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.01
  bDeviceClass          224 Wireless
  bDeviceSubClass         1 Radio Frequency
  bDeviceProtocol         1 Bluetooth
  bMaxPacketSize0        64
  idVendor           0x8087 Intel Corp.
  idProduct          0x0a2a
  bcdDevice            0.01
  iManufacturer           0
  iProduct                0
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          177
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       224 Wireless
      bInterfaceSubClass      1 Radio Frequency
      bInterfaceProtocol      1 Bluetooth
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       224 Wireless
      bInterfaceSubClass      1 Radio Frequency
      bInterfaceProtocol      1 Bluetooth
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0000  1x 0 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0000  1x 0 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           2
      bInterfaceClass       224 Wireless
      bInterfaceSubClass      1 Radio Frequency
      bInterfaceProtocol      1 Bluetooth
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0009  1x 9 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0009  1x 9 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       2
      bNumEndpoints           2
      bInterfaceClass       224 Wireless
      bInterfaceSubClass      1 Radio Frequency
      bInterfaceProtocol      1 Bluetooth
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0011  1x 17 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0011  1x 17 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       3
      bNumEndpoints           2
      bInterfaceClass       224 Wireless
      bInterfaceSubClass      1 Radio Frequency
      bInterfaceProtocol      1 Bluetooth
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0019  1x 25 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0019  1x 25 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       4
      bNumEndpoints           2
      bInterfaceClass       224 Wireless
      bInterfaceSubClass      1 Radio Frequency
      bInterfaceProtocol      1 Bluetooth
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0021  1x 33 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0021  1x 33 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       5
      bNumEndpoints           2
      bInterfaceClass       224 Wireless
      bInterfaceSubClass      1 Radio Frequency
      bInterfaceProtocol      1 Bluetooth
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0031  1x 49 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            1
          Transfer Type            Isochronous
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0031  1x 49 bytes
        bInterval               1

Bus 001 Device 002: ID 8087:8001 Intel Corp.
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            9 Hub
  bDeviceSubClass         0 Unused
  bDeviceProtocol         1 Single TT
  bMaxPacketSize0        64
  idVendor           0x8087 Intel Corp.
  idProduct          0x8001
  bcdDevice            0.03
  iManufacturer           0
  iProduct                0
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           25
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower                0mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         9 Hub
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      0 Full speed (or root) hub
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0002  1x 2 bytes
        bInterval              12

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            9 Hub
  bDeviceSubClass         0 Unused
  bDeviceProtocol         0 Full speed (or root) hub
  bMaxPacketSize0        64
  idVendor           0x1d6b Linux Foundation
  idProduct          0x0002 2.0 root hub
  bcdDevice            4.04
  iManufacturer           3
  iProduct                2
  iSerial                 1
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           25
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower                0mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         9 Hub
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      0 Full speed (or root) hub
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0004  1x 4 bytes
        bInterval              12

Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               3.00
  bDeviceClass            9 Hub
  bDeviceSubClass         0 Unused
  bDeviceProtocol         3
  bMaxPacketSize0         9
  idVendor           0x1d6b Linux Foundation
  idProduct          0x0003 3.0 root hub
  bcdDevice            4.04
  iManufacturer           3
  iProduct                2
  iSerial                 1
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           31
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower                0mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         9 Hub
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      0 Full speed (or root) hub
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0004  1x 4 bytes
        bInterval              12
        bMaxBurst               0

Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            9 Hub
  bDeviceSubClass         0 Unused
  bDeviceProtocol         1 Single TT
  bMaxPacketSize0        64
  idVendor           0x1d6b Linux Foundation
  idProduct          0x0002 2.0 root hub
  bcdDevice            4.04
  iManufacturer           3
  iProduct                2
  iSerial                 1
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           25
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower                0mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         9 Hub
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      0 Full speed (or root) hub
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0004  1x 4 bytes
        bInterval              12
Last edited by badidea on Jun 01, 2018 22:33, edited 2 times in total.
Dinosaur
Posts: 1071
Joined: Jul 24, 2005 1:13
Location: Searcy AR USA
Contact:

Re: Libusb

Postby Dinosaur » Jun 01, 2018 22:18

Hi All

badidea, I noticed you commented out the area where I "Open" the device.
Also using usb.bi , is that simply renaming the libusb-1.0.bi ?
Did you get a successful libusb_open ?

That is where my main concern is.

Regards
badidea
Posts: 751
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Libusb

Postby badidea » Jun 01, 2018 22:43

Dinosaur wrote:Also using usb.bi , is that simply renaming the libusb-1.0.bi ?

Yes.
Dinosaur wrote:Did you get a successful libusb_open ?

Code: Select all

Found one ;138749064
1BCF:2B8D
bcdDevice  ;17942
Serial Nbr ;0
dev_handle ;0
Error Detail ;-4
LIBUSB_ERROR_NO_DEVICE

Not yet. I'll try some more things...
badidea
Posts: 751
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Libusb

Postby badidea » Jun 01, 2018 23:20

I think you have to much ptr's. I converted the code here: http://libusb.sourceforge.net/api-1.0/group__dev.html

Code: Select all

#include once "usb.bi"

dim as integer err_ = 0

err_ = libusb_init(NULL)
If err_ < 0 Then
   End err_
EndIf

' discover devices
dim as libusb_device ptr ptr ppList
dim as libusb_device ptr pFound = NULL
dim as ssize_t cnt = libusb_get_device_list(NULL, @ppList)
dim as ssize_t i = 0
if (cnt < 0) then
    end cnt
end if

print "ok"

for i = 0 to cnt-1
    dim as libusb_device ptr pDevice = ppList[i]
    'if (is_interesting(pDevice)) then
        pFound = pDevice
        print pFound
        exit for
    'end if
next

print "ok"

if (pFound <> NULL) then
    dim as libusb_device_handle ptr pHandle
    err_ = libusb_open(pFound, @pHandle)
    if (err_ <> 0) then
      print err_, *libusb_error_name(err_)
        end
    end if
    print "libusb_open success, now what?"
end if
libusb_free_device_list(ppList, 1)
print "end"

As normal user I get:

Code: Select all

-3            LIBUSB_ERROR_ACCESS

As superuser I get:

Code: Select all

libusb_open success, now what?

When dealing with pointers, I (mostly) use pVar (or varPtr) and for pointers to pointers ppVar (where var would be a normal variable). This way the variable name tells me what it is. So e.g. pVar = ppVar[i] is good, and so is pVar = *ppVar, or ppVar = @pVar.
Last edited by badidea on Jun 01, 2018 23:36, edited 1 time in total.
Dinosaur
Posts: 1071
Joined: Jul 24, 2005 1:13
Location: Searcy AR USA
Contact:

Re: Libusb

Postby Dinosaur » Jun 01, 2018 23:36

Hi All

badidea, thanks for that.
I replicated what you did, and now will try to convert it to use my Vendor detail.

Must be late in Holland.

PS: Originally from East Amsterdam many years ago.

Regards
badidea
Posts: 751
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Libusb

Postby badidea » Jun 01, 2018 23:39

Dinosaur wrote:Must be late in Holland.

Yes, 01:37 now, time to go to bed :-)
Dinosaur wrote:PS: Originally from East Amsterdam many years ago.

I lived in Utrecht for 10 years, now ~100 km more south.
Dinosaur
Posts: 1071
Joined: Jul 24, 2005 1:13
Location: Searcy AR USA
Contact:

Re: Libusb

Postby Dinosaur » Jun 02, 2018 1:49

Hi All

Thanks to your help I have minimised the code below and it allows me to open the two devices.

Code: Select all

#include once "libusb-1.0.bi"

dim shared as libusb_device_descriptor desc
dim shared as libusb_device_handle ptr pHandle
dim shared as libusb_device ptr pDevice
dim shared as libusb_device ptr ptr ppList
dim shared as ssize_t cnt = 0, i = 0
dim shared as integer err_ = 0
dim shared as Long r

err_ = libusb_init(NULL)
If err_ < 0 Then
   End err_
EndIf

cnt = libusb_get_device_list(NULL, @ppList)
if (cnt < 0) then
    end cnt
end if
print "Discovered ";cnt ;" devices"

for i = 0 to cnt-1
    pDevice = ppList[i]
    r = libusb_get_device_descriptor(pDevice, @desc)     
    If Hex(desc.idVendor,4) = "0A07" And Hex(desc.idProduct,4) = "0046" Then
        Print Hex(desc.idVendor,4);":";Hex(desc.idProduct,4)
        Print "Found one ;";pdevice
        Print "bcdDevice  ;"; desc.bcdDevice
        Print "Serial Nbr ;"; desc.iSerialNumber
        r = libusb_open(pDevice, @pHandle)
        Print "dev_handle ;"; pHandle
        Print "Error Detail ;";r
        Print *(libusb_error_name(r))
        Print
    end if
next

    print "ok"
    libusb_free_device_list(ppList, 1)
    libusb_exit(NULL)
    print "end"
I will now develop it into a mini application and post it when done.

Regards
and thanks once again.
Dinosaur
Posts: 1071
Joined: Jul 24, 2005 1:13
Location: Searcy AR USA
Contact:

Re: Libusb

Postby Dinosaur » Jun 02, 2018 18:40

Hi All

Posted below the completed test program.
Many thanks to those that have contributed.

The Libusb-1.0.bi used is posted in previous post with comment blocks removed to allow it to be posted.

Code: Select all

#include once "libusb-1.0.bi"
#Include once "usbPort.bi"
''-------------------------------------------------------------------
''This program does the following:
''  1: Initialize Libusb 
''  2: Gets List of usb devices attached
''  3: Uses idVendor/idProduct to find duplicates in list.
''  4: Opens Port and reads iSerialNumber of duplicates.
''  5: Free's the list
''  6: Uses Control Transfer to send a request
''  7: Uses Control Transfer to Read response
''  8: Deallocates Buffer, and closes Interface's and Libusb
''  FreeBASIC Compiler - Version 1.05.0 (01-31-2016), built for linux-x86_64 (64bit)
''  By setting .PrintFlag to 1 detail is printed to Terminal.
''  Fill in your own .Vendor / .Product at lines 163-165
''  This has only been tested on Linux Mint 18.3
''-------------------------------------------------------------------
Sub usbInitialize
    With usbPort
        ''----First init the Lib-----
        .Found = libusb_init(0)
        If .Found = 0 Then
                .usbFlag = 1
            Else
                If .PrintFlag > 0 Then Print "libusb_Init     = Failed"
                Exit Sub
        EndIf
        If .Found = 0 Then
            For cnt = 1 to 4
                .Handle(cnt) = 0
            Next
            .Hd = 0
            ''-----Get list of all usb devices (always succeeds)----------
            cnt = libusb_get_device_list(NULL, @ppList)
            ''-----Now check which devices are of the same Vendor/Product----------------
            For i = 0 to cnt-1
                pDevice = ppList[i]
                .RetValue = libusb_get_device_descriptor(pDevice, @desc)     
                If Hex(desc.idVendor,4) = .Vendor(1) And Hex(desc.idProduct,4) = .Product(1) Then
                    If .PrintFlag > 0 Then Print Hex(desc.idVendor,4);":";Hex(desc.idProduct,4)
                    If .PrintFlag > 0 Then Print "Found Dev ";.Hd + 1;" ;";pdevice
                    .RetValue = libusb_open(pDevice, @pHandle)
                    '---If an error opening------
                    If .RetValue < 0 Then
                        Print "dev_handle      ;"; pHandle
                        Print "Error Detail    ;";.RetValue
                        Print *(libusb_error_name(.RetValue))
                        Return
                    EndIf
                    .Hd += 1
                    .Handle(.Hd) = pHandle
                    pHandle = 0
                End if
            Next
            ''------Use .Handle to release from Kernel and get Serial Number----
            For i = 1 to 2
                If .Handle(i) > 0 Then
                    .usbFlag += 1
                    .RetValue = libusb_kernel_driver_active(.Handle(i),0)          ''check if kernel has attached a driver
                    If .RetValue > 0 Then                                          ''if so
                        .RetValue = libusb_detach_kernel_driver(.Handle(i), 0)     ''detach it
                        If .PrintFlag > 0 Then Print "Detach from Kernel"
                    Endif
                    .RetValue = libusb_claim_interface(.Handle(i), 0)               ''now we can claim the interface
                    If .RetValue = 0 Then
                            .usbFlag += 1                                           ''This allows usbThread to proceed
                            If .PrintFlag > 0 Then Print "Claimed I/F ";i
                        Else
                            Print "Claim I/F Fail   "
                            Return
                    EndIf
                    ReAllocate(Buffer,64)
                    ''------value 3 in call = index of descriptor for iSerialNumber--------
                    .RetValue = libusb_get_string_descriptor_ascii(.Handle(i),3,Buffer,64)
                    .Hd = i
                    ''---RetValue = number of char's in iSerialNumber string------
                    If .RetValue > 0 Then
                        Dim i as Ushort
                        If .PrintFlag > 0 Then Print "Chr's in Serial =";.RetValue
                        .SerialNbr(.Hd) = ""
                        For i = 0 to .RetValue
                            .SerialNbr(.Hd) += Chr(Buffer[i])
                        Next
                    EndIf
                    If .PrintFlag > 0 Then Print .SerialNbr(.Hd)                     
                EndIf
            Next
            If cnt > 0 Then libusb_free_device_list(ppList,1)
        EndIf
    End With
End Sub
Sub ReadOnce
    '---------------------------------------------------------
    'This Sub reads a Control Transfer from endpoint &h81
    'as a result of the request done in WriteOnce previously
    '---------------------------------------------------------
    With usbPort
        If .Handle(.Hd) > 0 Then
            .RetValue = libusb_interrupt_transfer(.Handle(.Hd), &H81, Buffer, 64, @.RxBytes, 500 )
            If .RetValue = 0 Then
                If .RxBytes = 64 Then
                    .ValString(.Hd) = ""
                    For i as Integer = 1 to .RxBytes-1             '-1 for zero terminated string
                        If (Buffer[i] > 47) And (Buffer[i] < 58) Then 'if 0-9
                            .ValString(.Hd) += Chr(Buffer[i])
                        EndIf
                        If (i > 8) and Buffer[i] = 0 Then Exit For 'dont read trailing zeroes
                    Next
                    If .PrintFlag > 0 Then Print "Value of Hd ";.Hd;" ";Val(.ValString(.Hd))
                End If
            EndIf
            If .RetValue < 0 Then
                Print "Read Control Transfer Failed"
            EndIf           
        EndIf
    End With
End Sub
Sub WriteOnce
    ''---------------------------------------------------------
    ''This Sub writes a Control Transfer request to endpoint 1
    ''---------------------------------------------------------
    With usbPort
        ReAllocate(Buffer,64)
        Buffer[0] = &H01
        Buffer[1] = 82      '' 'R'
        Buffer[2] = 68      '' 'D'
        If .Handle(.Hd) > 0 Then
            .RetValue = libusb_interrupt_transfer(.Handle(.Hd), &H01, Buffer, 8, @.TxBytes, 500 )
            If .RetValue < 0 Then
                Print "Write Control Transfer Failed"
                Print "Bytes Sent = ";.TxBytes
                Return
            EndIf
        EndIf
    End With
End Sub
Sub usbQuit
    With usbPort
        Dim i as uShort
        '----First must release i/f Then close device------------
        For i = 1 To 4
            If .Handle(i) > 0 Then
                .RetValue = libusb_release_interface(.Handle(i), 0)
                libusb_close(.Handle(i))
                If .RetValue = 0 Then
                        If .PrintFlag > 0 Then Print "I/F ";i;" Release=; Success"
                    Else
                        Print "I/F ";i;" Release=; Failed"
                EndIf
            EndIf
        Next
            If .usbFlag > 2 Then Print "Success..."
            Deallocate Buffer
            Print "Buffer Closed"
            Print "libusb Closed"
            Libusb_exit(0)
            Print "libusb exited"
    End With
End Sub

    With usbPort
        .PrintFlag = 1
        .Vendor(1) = "0A07":.Product(1) = "0046"  'Ontrak ADU70 24 bit A2D Load Cell interface
        .Vendor(2) = "0A07":.Product(2) = "0046"  '           ditto
        .Vendor(3) = "1605":.Product(3) = "8018"  'AccesIO USB-IDIO-16L.(32 bit I/O Board)
        .Vendor(4) = "1605":.Product(4) = "8077"  'AccesIO USB-AO16-4E. (16 bit I/O + 4 bit A/O)
        Buffer = Allocate(64)
        usbInitialize      ''indexes .usbFlag to 3 if succesfull
        If .usbFlag < 3 then End
        .Hd = 1
        WriteOnce           ''write request to endpoint 1
        ReadOnce            ''read response from endpoint 81
        .Hd = 2
        WriteOnce
        ReadOnce'
        usbQuit
    End With
   Sleep


And the usbPort.bi

Code: Select all

Type usbPort
    Handle(1 to 4)      As Long Ptr
    Found               As UShort
    usbFlag             As UShort
    Hd                  As UShort
    PrintFlag           As UShort
    RxBytes             As Long
    TxBytes             As Long
    RetValue            As Long
    ChrByte             As String * 1
    ValString(1 to 4)   As String * 24
    SerialNbr(1 to 4)   As String * 6
    Vendor (1 to 4)     As String * 4
    Product(1 to 4)     As String * 4
End Type
Dim Shared usbPort as usbPort
'------------------------------------
Dim Shared Buffer As UByte Ptr
Dim shared as libusb_device Ptr dev
dim shared as libusb_device_descriptor desc
dim shared as libusb_device_handle ptr pHandle
dim shared as libusb_device ptr pDevice
dim shared as libusb_device ptr ptr ppList
dim shared as ssize_t cnt = 0, i = 0


declare sub usbinitialize()
declare sub WriteOnce()
declare sub ReadOnce()
declare sub usbQuit ()


Regards
badidea
Posts: 751
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Libusb

Postby badidea » Jun 02, 2018 23:12

Form the code I understand that this test program requires an 'Ontrak' USB-device to work? (I get .usbFlag = 1)
Dinosaur
Posts: 1071
Joined: Jul 24, 2005 1:13
Location: Searcy AR USA
Contact:

Re: Libusb

Postby Dinosaur » Jun 02, 2018 23:44

Hi All

badidea you should just change the .vendor(1) and .Product(1) numbers to one of your devices and make sure you have a
permission rule in rules.d folder.

SUBSYSTEMS=="usb",ATTRS{idVendor}=="0a07",ATTRS{idProduct}=="0046",MODE="0666"
or run it as root.

I just retested with only one device plugged in and it worked fine.

Regards

EDIT: The line that call WriteOnce & ReadOnce should be commented out as they are specific.
Just tested with a Servo Motor that has inbuilt usb controller, and discovered that the rules.d statement is critical.
The WriteOnce & ReadOnce failed but that was to be expected as I don't know the commands for this motor.

I am rewriting the vendor checking section as at the moment it only checks for duplicates using .Vendor(1) / .Product(1)
but really I need a Select Case there to check all 4 Vendor possibilities.
Dinosaur
Posts: 1071
Joined: Jul 24, 2005 1:13
Location: Searcy AR USA
Contact:

Re: Libusb

Postby Dinosaur » Jun 03, 2018 16:42

Hi All

Updated code allowing upto 8 usb ports.

Code: Select all

#include once "libusb-1.0.bi"
#Include once "usbPort.bi"
''------Compiled with--------------------------------------------------------------------
''  FreeBASIC Compiler - Version 1.05.0 (01-31-2016), built for linux-x86_64 (64bit)
''
''  Note: Comments are double '' to avoid clash with Gede debugger.
''
''This program does the following:
''  1: Initialize Libusb 
''  2: Gets List of usb devices attached
''  3: Uses 0-7 idVendor/idProduct's to find matches in list.
''  4: Opens matches found and assign's .Handle(n)
''  5: Uses .Handle(n) to check if Kernel has control, then releases it.
''  6: Uses .Handle(n) to Claim Interface & load ascii string desc to get iSerialNumber.
''  7: Uses Control Transfer to send a request
''  8: Now .Handle(n) is available to Write & Read Control Transfers to devices attached.
''  9: WriteOnce & ReadOnce are dedicated to Ontrak ADU70 Load Cell's
'' 10: Deallocates Buffer, and closes Interface's and Libusb
''  By setting .PrintFlag to 1 detail is printed to Terminal.(Errors are always printed)
''  Fill in your own .Vendor / .Product at lines 176-183
''  This has only been tested on Linux Mint 18.3
''---------------------------------------------------------------------------------------
Sub usbInitialize
    With usbPort
        ''----First init the Lib-----
        .Found = libusb_init(0)
        If .Found = 0 Then
                .usbFlag = 1
            Else
                If .PrintFlag > 0 Then Print "libusb_Init     = Failed"
                Exit Sub
        EndIf
        If .Found = 0 Then
            For cnt = 0 to 7
                .Handle(cnt) = 0
            Next
            cnt = 0
            ''-----Get list of all usb devices (always succeeds)----------
            cnt = libusb_get_device_list(NULL, @ppList)
            If .PrintFlag > 0 Then Print "----Reading all usb devices to assign pDevice to MyDev numbers----"
            For i = 0 to cnt-1
                pDevice = ppList[i]
                ''-----Load found device one at a time------
                .RetValue = libusb_get_device_descriptor(pDevice, @desc)
                If .PrintFlag > 0 Then Print "Load desc.;";Hex(desc.idVendor,4);":";Hex(desc.idProduct,4);" From Device";i
                ''-----Check 8 possible matches-------------
                For MyDev = 0 to 7
                    If Hex(desc.idVendor,4) = .Vendor(MyDev) And Hex(desc.idProduct,4) = .Product(MyDev) Then
                        ''----If not been selected before, assign desc to this Hd number----
                        If .Handle(MyDev) = 0 Then
                            If .PrintFlag > 0 Then Print Hex(desc.idVendor,4);":";Hex(desc.idProduct,4)
                            If .PrintFlag > 0 Then Print "Found MyDev ";MyDev;"; Device Nbr ";pdevice
                            ''----Open device(i) with .Handle(Hd)----
                            .RetValue = libusb_open(pDevice, @pHandle)
                            '---If an error opening------
                            If .RetValue < 0 Then
                                Print "dev_handle      ;"; pHandle
                                Print "Error Detail    ;";.RetValue
                                Print *(libusb_error_name(.RetValue))
                                Return
                            EndIf
                            .Handle(MyDev) = pHandle
                            pHandle = 0
                            Exit For
                        EndIf
                    End if
                Next MyDev
            Next i
            ''------Use .Handle to release from Kernel and get Serial Number----
            If .PrintFlag > 0 Then Print "----Claiming MyDev's and getting Serial Numbers----"
            For i = 0 to 7
                If .Handle(i) > 0 Then
                    .usbFlag += 1
                    .RetValue = libusb_kernel_driver_active(.Handle(i),0)          ''check if kernel has attached a driver
                    If .RetValue > 0 Then                                          ''if so
                        .RetValue = libusb_detach_kernel_driver(.Handle(i), 0)     ''detach it
                        If .PrintFlag > 0 Then Print "Detach from Kernel"
                    Endif
                    .RetValue = libusb_claim_interface(.Handle(i), 0)               ''now we can claim the interface
                    If .RetValue = 0 Then
                            .usbFlag += 1                                           ''This allows usbThread to proceed
                            If .PrintFlag > 0 Then Print "Claimed I/F ";i
                        Else
                            Print "Claim I/F Fail   "
                            Return
                    EndIf
                    ReAllocate(Buffer,64)
                    ''------value 3 in call = index of descriptor for iSerialNumber--------
                    .RetValue = libusb_get_string_descriptor_ascii(.Handle(i),3,Buffer,64)
                    MyDev = i
                    ''---RetValue = number of char's in iSerialNumber string------
                    If .RetValue > 0 Then
                            Dim Nbr as Ushort
                            If .PrintFlag > 0 Then Print "Chr's in Serial =";.RetValue
                            .SerialNbr(MyDev) = ""
                            For Nbr = 0 to .RetValue
                                .SerialNbr(MyDev) += Chr(Buffer[Nbr])
                            Next
                        Else
                            If .PrintFlag > 0 Then Print "----string_descriptor not supported on this device----"
                    EndIf
                    If .PrintFlag > 0 Then Print .SerialNbr(MyDev)                     
                EndIf
            Next
            If cnt > 0 Then libusb_free_device_list(ppList,1)
        EndIf
    End With
End Sub
Sub ReadOnce
    '---------------------------------------------------------
    'This Sub reads a Control Transfer from endpoint &h81
    'as a result of the request done in WriteOnce previously
    '---------------------------------------------------------
    With usbPort
        If .Handle(MyDev) > 0 Then
            .RetValue = libusb_interrupt_transfer(.Handle(MyDev), &H81, Buffer, 64, @.RxBytes, 500 )
            If .RetValue = 0 Then
                If .RxBytes = 64 Then
                    .ValString(MyDev) = ""
                    For i as Integer = 1 to .RxBytes-1             '-1 for zero terminated string
                        If (Buffer[i] > 47) And (Buffer[i] < 58) Then 'if 0-9
                            .ValString(MyDev) += Chr(Buffer[i])
                        EndIf
                        If (i > 8) and Buffer[i] = 0 Then Exit For 'dont read trailing zeroes
                    Next
                    If .PrintFlag > 0 Then Print "Value of Read of MyDev ";MyDev;" ";Val(.ValString(MyDev))
                End If
            EndIf
            If .RetValue < 0 Then
                Print "Read Control Transfer Failed"
            EndIf           
        EndIf
    End With
End Sub
Sub WriteOnce
    ''---------------------------------------------------------
    ''This Sub writes a Control Transfer request to endpoint 1
    ''---------------------------------------------------------
    With usbPort
        ReAllocate(Buffer,64)
        Buffer[0] = &H01
        Buffer[1] = 82      '' 'R'
        Buffer[2] = 68      '' 'D'
        If .Handle(MyDev) > 0 Then
            .RetValue = libusb_interrupt_transfer(.Handle(MyDev), &H01, Buffer, 8, @.TxBytes, 500 )
            If .RetValue < 0 Then
                Print "Write Control Transfer Failed"
                Print "Bytes Sent = ";.TxBytes
                Return
            EndIf
        EndIf
    End With
End Sub
Sub usbQuit
    With usbPort
        Dim i as uShort
        '----First must release i/f Then close device------------
        For i = 0 To 7
            If .Handle(i) > 0 Then
                .RetValue = libusb_release_interface(.Handle(i), 0)
                libusb_close(.Handle(i))
                If .RetValue = 0 Then
                        If .PrintFlag > 0 Then Print "I/F ";i;" Release=; Success"
                    Else
                        Print "I/F ";i;" Release=; Failed"
                EndIf
            EndIf
        Next
            If .usbFlag > 2 Then Print "Success..."
            Deallocate Buffer
            Print "Buffer Closed"
            Print "libusb Closed"
            Libusb_exit(0)
            Print "libusb exited"
    End With
End Sub

    ''-----------------------------------------------------------------------------------
    ''  After confirming with lsusb (in Linux Terminal) assign .Vendor / .Product Numbers
    ''-----------------------------------------------------------------------------------
    With usbPort
        .PrintFlag = 1
        .Vendor(0) = "0A07":.Product(0) = "0046"  'Ontrak ADU70 24 bit A2D Load Cell interface
        .Vendor(1) = "0A07":.Product(1) = "0046"  '           ditto
        .Vendor(2) = "1605":.Product(2) = "8018"  'AccesIO USB-IDIO-16L.(32 bit I/O Board)
        .Vendor(3) = "1605":.Product(3) = "8077"  'AccesIO USB-AO16-4E. (16 bit I/O + 4 bit A/O)
        .Vendor(4) = "":.Product(4) = ""  'Ontrak ADU70 24 bit A2D Load Cell interface
        .Vendor(5) = "":.Product(5) = ""  '           ditto
        .Vendor(6) = "":.Product(6) = ""  'AccesIO USB-IDIO-16L.(32 bit I/O Board)
        .Vendor(7) = "":.Product(7) = ""  'AccesIO USB-AO16-4E. (16 bit I/O + 4 bit A/O)
        Buffer = Allocate(64)
        usbInitialize          ''indexes .usbFlag to 3 if succesfull
        If .usbFlag > 2 Then
            If .PrintFlag > 0 Then Print "----Writing & Reading from .Vendor(0) and .Vendor(1) only----"
            MyDev = 0
            WriteOnce           ''write request to endpoint 1
            ReadOnce            ''read response from endpoint 81
            MyDev = 1
            WriteOnce
            ReadOnce'
        EndIf
        usbQuit
    End With
    Print "Any key to quit"
   Sleep

And the new .bi file (still using same libusb-1.0.bi

Code: Select all

Type usbPort
    Handle(0 to 7)      As Long Ptr
    Found               As Short
    usbFlag             As Short
    'Hd                  As Short
    PrintFlag           As Short
    RxBytes             As Long
    TxBytes             As Long
    RetValue            As Long
    ChrByte             As String * 1
    ValString(0 to 7)   As String * 24
    SerialNbr(0 to 7)   As String * 6
    Vendor (0 to 7)     As String * 4
    Product(0 to 7)     As String * 4
End Type
Dim Shared usbPort as usbPort
'------------------------------------
Dim Shared Buffer As UByte Ptr
Dim shared as libusb_device Ptr dev
dim shared as libusb_device_descriptor desc
dim shared as libusb_device_handle ptr pHandle
dim shared as libusb_device ptr pDevice
dim shared as libusb_device ptr ptr ppList
dim shared as ssize_t cnt = 0, i = 0
dim shared as short ix = 0 , MyDev = 0


declare sub usbinitialize()
declare sub WriteOnce()
declare sub ReadOnce()
declare sub usbQuit ()

And the result on my Linux system.

Code: Select all

----Reading all usb devices to assign pDevice to MyDev numbers----
Load desc.;0A07:0046 From Device 0
0A07:0046
Found MyDev  0; Device Nbr 27603040
Load desc.;0438:7900 From Device 1
Load desc.;1D6B:0002 From Device 2
Load desc.;0A07:0046 From Device 3
0A07:0046
Found MyDev  1; Device Nbr 27553296
Load desc.;8087:07DC From Device 4
Load desc.;046D:C31C From Device 5
Load desc.;0438:7900 From Device 6
Load desc.;1D6B:0002 From Device 7
Load desc.;1D6B:0003 From Device 8
Load desc.;1605:8077 From Device 9
1605:8077
Found MyDev  3; Device Nbr 27450128
Load desc.;046D:C52F From Device 10
Load desc.;1D6B:0002 From Device 11
----Claiming MyDev's and getting Serial Numbers----
Claimed I/F  0
Chr's in Serial = 6
T00014
Claimed I/F  1
Chr's in Serial = 6
T00543
Claimed I/F  3
----string_descriptor not supported on this device----
     
----Writing & Reading from .Vendor(0) and .Vendor(1) only----
Value of Read of MyDev  0  10435088
Value of Read of MyDev  1  8410986
I/F 0 Release=; Success
I/F 1 Release=; Success
I/F 3 Release=; Success
Success...
Buffer Closed
libusb Closed
libusb exited
Any key to quit


Happy for anyone to improve the code.

Regards

Return to “Hardware Interfaces / Communication”

Who is online

Users browsing this forum: No registered users and 1 guest