⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libusb.bas

📁 USBLIB FOR VB,USBLIB FOR VB
💻 BAS
📖 第 1 页 / 共 2 页
字号:
'        Example:      Dim my_handle , my_index as long
'                      Const my_vid = &hdd8
'
'                      my_index=0
'                      do
'                         my_handle= USBopen (my_index,my_vid,-1)
'                         usbclose my_handle
'                         my_index=my_index+1
'                      loop until my_handle=0
'                      Debug.Print " There are " & my_index & " devices with VID " & hex$(my_pid)
'        Opening a device in this way allows you to 'walk' all the device belonging to one vendor.

Declare Function UsbOpen Lib "libusbvb0.dll" _
        Alias "vb_usb_open" ( _
        ByVal index As Long, _
        ByVal VID As Long, _
        ByVal PID As Long) _
        As Long

' ********************************************* USB Close **************************************************
' When you no longer need access to a USB device you have to release it.
' USB_close does exactly that. Just pass it the handle you got from UsbOpen.
' USB_close returns a '1' if succesful.

Declare Function UsbClose Lib "libusbvb0.dll" _
        Alias "vb_usb_close" ( _
        ByVal dev As Long) _
        As Long

' ********************************************* USB GetDescriptor*******************************************
' Any USB devices contains a set of data called 'descriptors' that provide information about the device
' usbgetdescriptors allows you to retrieve this dataset.
' The returning dataset is a complex structure. In order to make delaing with this data easier a number of predefined
' types have been defined that will directly format the returning data.
'
' Example:  dim my_handle as long
'           dim my_descriptor as USBdeviceDescriptor
'           my_handle=usbopen(0,-1,-1)     ' we open the first device attached
'           if (usbgetdescriptor(my_handle, USB_DT_DEVICE,0,my_descriptor,USB_DT_DEVICE_SIZE) <> USB_DT_DEVICE_SIZE) then
'              debug.print " no descriptor found "
'           end if
'
' USBgetDescriptor returns 0 if the call failed, so you need to check this.
' The retrieved data is loaded into the provided variable ( in this case my_descriptor)
' USBgetdescriptors can get a number of different descriptors. USB provides a Device , Config and interface descriptor.
' The important thing is to call usbgetdescriptors with the correct information :
' Example : dim my_handle as long
'           dim my_descriptor as USBDeviceDescriptor
'           dim my_config     as USBconfigdescriptor

'           usbgetdescriptor (my_handle, USB_DT_DEVICE   ,0,my_descriptor,USB_DT_DEVICE_SIZE)
'           usbgetdescriptor (my_handle, USB_DT_CONFIG   ,0,my_config    ,USB_DT_CONFIG_SIZE)
'
' USBGetDescriptor is a generic routine. The next couple routines make life easier since they already fill in
' most of the information for you

Declare Function UsbGetDescriptor Lib "libusbvb0.dll" _
        Alias "vb_usb_get_descriptor" ( _
        ByVal dev As Long, _
        ByVal dtype As Long, _
        ByVal index As Long, _
        ByRef buf As Any, _
        ByVal size As Long) _
        As Long
  
' ********************************************* USBGetDeviceDescriptor*******************************************
' This is a modification of the generic USBGetDescriptor to fetch the Device descriptor
' Pass the handle of the open device and the variable where you want the information to be stored
' Make sure that the variable is cast as a USBdeviceDescriptor.
' The function returns true when successful, and false when it failed.
' Example :
'           Dim my_handle As Long
'           dim my_descriptor as USBDeviceDescriptor
'           my_handle = usbopen(0,-1,-1)  ' open the first usb device
'           if USBGetDeviceDescriptor (my_handle,my_descriptor) = false then
'              debug.print " Failed "
'           else
'              debug.print "VID " & my_descriptor.idvendor
'              debug.print "PID " & my_descriptor.idproduct
'           end if
'
' The returned data is stored in my_descriptor.
' It is very important that that variable is cast as a USBdeviceDescriptor in order to have enough reserved storage.
' If the variable is cast as the wrong type your program will crash and burn...

Declare Function UsbGetDeviceDescriptor Lib "libusbvb0.dll" _
        Alias "vb_usb_get_device_descriptor" ( _
        ByVal dev As Long, _
        ByRef descriptor As UsbDeviceDescriptor) _
        As Boolean

' **************************************** USBGetConfigurationDescriptor*******************************************
' This is a modification of the generic USBGetDescriptor to fetch the Configuration descriptor
' Pass the handle of the open device and the variable where you want the information to be stored
' You also need to pass which configuration descriptor you want to read.
' A Given USB device can have multiple configuration. Especially so called composite devices like keyboard/mouse
' wireless receivers , or webcams with built in audio ( composite audio/video device )
' Make sure that the variable is cast as a USBdeviceDescriptor.
' The function returns true when successful, and false when it failed.
' Example :
'           Dim my_handle As Long
'           dim my_descriptor as USBDeviceDescriptor
'           dim my_config     as USBconfigDescriptor
'           dim x
'           my_handle = usbopen(0,-1,-1)  ' open the first usb device
'           if USBGetDeviceDescriptor (my_handle,my_descriptor) = false then
'              debug.print " Failed "
'           else
'              for x = my_descriptor.bNumconfigurations -1
'                  If UsbGetConfigurationDescriptor(handle, x, dev_config) Then
'                     debug.print "configuration " & x & " Has " & my_config.bNumInterfaces & " Interfaces "
'                  end if
'              next x
'           end if
'
' The returned data is stored in my_config.
' It is very important that that variable is cast as a USBconfigDescriptor in order to have enough reserved storage.
' If the variable is cast as the wrong type your program will crash and burn...

Declare Function UsbGetConfigurationDescriptor Lib "libusbvb0.dll" _
        Alias "vb_usb_get_configuration_descriptor" ( _
        ByVal dev As Long, _
        ByVal config_index As Long, _
        ByRef descriptor As UsbConfigDescriptor) As Boolean



Declare Function UsbGetInterfaceDescriptor Lib "libusbvb0.dll" _
  Alias "vb_usb_get_interface_descriptor" ( _
  ByVal dev As Long, _
  ByVal config_index As Long, _
  ByVal interface_index As Long, _
  ByVal alt_index As Long, _
  ByRef descriptor As UsbInterfaceDescriptor) As Boolean

Declare Function UsbGetEndpointDescriptor Lib "libusbvb0.dll" _
  Alias "vb_usb_get_endpoint_descriptor" ( _
  ByVal dev As Long, _
  ByVal config_index As Long, _
  ByVal interface_index As Long, _
  ByVal alt_index As Long, _
  ByVal endpoint_index As Long, _
  ByRef descriptor As UsbEndPointDescriptor) As Boolean

Declare Function UsbGetStringDescriptor Lib "libusbvb0.dll" _
  Alias "vb_usb_get_string_descriptor" ( _
  ByVal dev As Long, _
  ByVal index As Long, _
  ByVal langid As Long, _
  ByRef buf As Any, _
  ByVal size As Long) As Long

Declare Function UsbGetString Lib "libusbvb0.dll" _
  Alias "vb_usb_get_string" ( _
  ByVal dev As Long, _
  ByVal index As Long, _
  ByVal langid As Long, _
  ByRef buf As Any, _
  ByVal size As Long) As Long

Declare Function UsbGetStringSimple Lib "libusbvb0.dll" _
  Alias "vb_usb_get_string_simple" ( _
  ByVal dev As Long, _
  ByVal index As Long, _
  ByRef buf As Any, _
  ByVal size As Long) As Long

Declare Function UsbGetDescriptorByEndpoint Lib "libusbvb0.dll" _
  Alias "vb_usb_get_descriptor_by_endpoint" ( _
  ByVal dev As Long, _
  ByVal ep As Long, _
  ByVal dtype As Long, _
  ByVal index As Long, _
  ByRef buf As Any, _
  ByVal size As Long) As Long

Declare Function UsbBulkWrite Lib "libusbvb0.dll" _
  Alias "vb_usb_bulk_write" ( _
  ByVal dev As Long, _
  ByVal ep As Long, _
  ByRef buf As Any, _
  ByVal size As Long, _
  ByVal timeout As Long) As Long

Declare Function UsbBulkRead Lib "libusbvb0.dll" _
  Alias "vb_usb_bulk_read" ( _
  ByVal dev As Long, _
  ByVal ep As Long, _
  ByRef buf As Any, _
  ByVal size As Long, _
  ByVal timeout As Long) As Long

Declare Function UsbInterruptWrite Lib "libusbvb0.dll" _
  Alias "vb_usb_interrupt_write" ( _
  ByVal dev As Long, _
  ByVal ep As Long, _
  ByRef buf As Any, _
  ByVal size As Long, _
  ByVal timeout As Long) As Long

Declare Function UsbInterruptRead Lib "libusbvb0.dll" _
  Alias "vb_usb_interrupt_read" ( _
  ByVal dev As Long, _
  ByVal ep As Long, _
  ByRef buf As Any, _
  ByVal size As Long, _
  ByVal timeout As Long) As Long

Declare Function UsbControlMsg Lib "libusbvb0.dll" _
  Alias "vb_usb_control_msg" ( _
  ByVal dev As Long, _
  ByVal requesttype As Long, _
  ByVal request As Long, _
  ByVal value As Long, _
  ByVal index As Long, _
  ByVal buf As Any, _
  ByVal size As Long, _
  ByVal timeout As Long) As Long

Declare Function UsbSetConfiguration Lib "libusbvb0.dll" _
  Alias "vb_usb_set_configuration" ( _
  ByVal dev As Long, _
  ByVal configuration As Long) As Long

Declare Function UsbClaimInterface Lib "libusbvb0.dll" _
  Alias "vb_usb_claim_interface" ( _
  ByVal dev As Long, _
  ByVal interface As Long) As Long

Declare Function UsbReleaseInterface Lib "libusbvb0.dll" _
  Alias "vb_usb_release_interface" ( _
  ByVal dev As Long, _
  ByVal interface As Long) As Long

Declare Function UsbSetAltinterface Lib "libusbvb0.dll" _
  Alias "vb_usb_set_altinterface" ( _
  ByVal dev As Long, _
  ByVal alternate As Long) As Long

Declare Function UsbResetEp Lib "libusbvb0.dll" _
  Alias "vb_usb_resetep" ( _
  ByVal dev As Long, _
  ByVal ep As Long) As Long

Declare Function UsbClearHalt Lib "libusbvb0.dll" _
  Alias "vb_usb_clear_halt" ( _
  ByVal dev As Long, _
  ByVal ep As Long) As Long

Declare Function UsbReset Lib "libusbvb0.dll" _
  Alias "vb_usb_reset" ( _
  ByVal dev As Long) As Long

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -