Gå til innhold

Visual Basic 6, Windows XP & USB?


Anbefalte innlegg

Videoannonse
Annonse

OK, eg har fonne ut litt nå, men eg lure på kossen eg kan bruka det eg har fonne ut... :hmm: Poenget e at eg fant en driver, eller ein i c++ forumet viste meg en driver, men kossen bruke eg ann i VB6?

 

her e en link te driveren: (LibUSB-Win32 fra Sourceforge.net)

http://libusb-win32.sourceforge.net

 

OG Dokumentasjonen:

http://libusb.sourceforge.net/doc/

 

Någen som kan hjlpa meg her? eg begynte på ein modul i VB6 som kunne hjelpa meg, men så fekk eg ubeskrivelige problemer med någen Structurer, vis någen vil hjelpa meg, her e koden...:

Attribute VB_Name = "LibUSB"
'Some information about the Module:
'----------------------------------
'API's listed: (libusb0.dll)
'    USB_Init
'    USB_Find_Busses
'    USB_Find_Devices
'    USB_Get_Busses
'    USB_Open
'    USB_Close
'    USB_Set_Configuration
'    USB_Set_AltInterface
'    USB_ResetEp
'    USB_Clear_Halt
'    USB_Reset
'    USB_Claim_Interface
'    USB_Release_Interface
'    USB_Control_Msg
'    USB_Get_String
'    USB_Get_String_Simple
'    USB_Get_Descriptor
'    USB_Get_Descriptor
'    USB_Bulk_Write
'    USB_Bulk_Read
'    USB_Interrupt_Write
'    USB_Interrupt_Read
'----------------------------------
'Types in this Module:
'    USB_Bus
'    USB_Device
'    USB_Device_Descriptor
'    USB_Config_Descriptor
'    USB_Interface
'    USB_Interface_Descriptor
'    USB_EndPoint_Descriptor
'
'    PS.! There is one structure/type missing, that is
'         the USB_Dev_Handle:
'
'         struct usb_dev_handle;
'         typedef struct usb_dev_handle usb_dev_handle;
'
'         I just have no clue on how to convert the above structure...
'
'----------------------------------
'
'   This module is written by Richard Hagen
'   Thx to all the people in LibUSB & LibUSB-Win32 teams &
'   the people that help them...
'
'   You can modify or rewrite this.... I dont cear, just
'   remember, if you rewite it and its better that this one,
'   Please send a copy to me;) @ [email protected]... thx
'
'***************************************************************
'**** The API declarations...
'***************************************************************
Declare Sub USB_Init Lib "libusb0.dll" ()
Declare Function USB_Find_Busses Lib "libusb0.dll" () As Integer
Declare Function USB_Find_Devices Lib "libusb0.dll" () As Integer
Declare Function USB_Get_Busses Lib "libusb0.dll" () As USB_Bus
Declare Function USB_Open Lib "libusb0.dll" (ByRef Device As USB_Device) As usb_dev_handle
Declare Function USB_Close Lib "libusb0.dll" (ByRef Device As usb_dev_handle) As Integer
Declare Function USB_Set_Configuration Lib "libusb0.dll" (ByRef Device As usb_dev_handle, ByVal Configuration As Integer) As Integer
Declare Function USB_Set_AltInterface Lib "libusb0.dll" (ByRef Device As usb_dev_handle, ByVal Alternate As Integer) As Integer
Declare Function USB_ResetEp Lib "libusb0.dll" (ByRef Device As usb_dev_handle, ByVal EndPoint As Long) As Integer
Declare Function USB_Clear_Halt Lib "libusb0.dll" (ByRef Device As usb_dev_handle, ByVal EndPoint As Long) As Integer
Declare Function USB_Reset Lib "libusb0.dll" (ByRef Device As usb_dev_handle) As Integer
Declare Function USB_Claim_Interface Lib "libusb0.dll" (ByRef Device As usb_dev_handle, ByVal Interface As Integer) As Integer
Declare Function USB_Release_Interface Lib "libusb0.dll" (ByRef Device As usb_dev_handle, ByVal Interface As Integer) As Integer
Declare Function USB_Control_Msg Lib "libusb0.dll" (ByRef Device As usb_dev_handle, ByVal RequestType As Integer, ByVal Request As Integer, ByVal Value As Integer, ByVal Index As Integer, ByRef Bytes As String, ByVal Size As Integer, ByVal TimeOut As Integer) As Integer
Declare Function USB_Get_String Lib "libusb0.dll" (ByRef Device As usb_dev_handle, ByVal Index As Integer, ByVal LangId As Integer, ByRef Buf As String, ByVal BufLen As Long) As Integer
Declare Function USB_Get_String_Simple Lib "libusb0.dll" (ByRef Device As usb_dev_handle, ByVal Index As Integer, ByRef Buf As String, ByVal BufLen As Long) As Integer
Declare Function USB_Get_Descriptor Lib "libusb0.dll" (ByRef Device As usb_dev_handle, ByVal sType As String, ByVal Index As String, ByRef Buf, ByVal Size As Integer) As Integer
Declare Function USB_Get_Descriptor_By_EndPoint Lib "libusb0.dll" (ByRef Device As usb_dev_handle, ByVal EndPoint As Integer, ByVal sType As String, ByVal Index As String, ByRef Buf, ByVal Size As Integer) As Integer
Declare Function USB_Bulk_Write Lib "libusb0.dll" (ByRef Device As usb_dev_handle, ByVal EndPoint As Integer, ByRef Bytes As String, ByVal Size As Integer, ByVal TimeOut As Integer) As Integer
Declare Function USB_Bulk_Read Lib "libusb0.dll" (ByRef Device As usb_dev_handle, ByVal EndPoint As Integer, ByRef Bytes As Byte, ByVal Size As Integer, ByVal TimeOut As Integer) As Integer
Declare Function USB_Interrupt_Write Lib "libusb0.dll" (ByRef Device As usb_dev_handle, ByVal EndPoint As Integer, ByRef Bytes As Byte, ByVal Size As Integer, ByVal TimeOut As Integer) As Integer
Declare Function USB_Interrupt_Read Lib "libusb0.dll" (ByRef Device As usb_dev_handle, ByVal EndPoint As Integer, ByRef Bytes As Byte, ByVal Size As Integer, ByVal TimeOut As Integer) As Integer
  
'*****************************************************************
'**** All the Constants...
'*****************************************************************
'Device and/or Interface Class codes
Const USB_CLASS_PER_INTERFACE = 0 '/* for DeviceClass */
Const USB_CLASS_AUDIO = 1
Const USB_CLASS_COMM = 2
Const USB_CLASS_HID = 3
Const USB_CLASS_PRINTER = 7
Const USB_CLASS_MASS_STORAGE = 8
Const USB_CLASS_HUB = 9
Const USB_CLASS_DATA = 10
Const USB_CLASS_VENDOR_SPEC = &HFF

'Descriptor types
Const USB_DT_DEVICE = &H1
Const USB_DT_CONFIG = &H2
Const USB_DT_STRING = &H3
Const USB_DT_INTERFACE = &H4
Const USB_DT_ENDPOINT = &H5

Const USB_DT_HID = &H21
Const USB_DT_REPORT = &H22
Const USB_DT_PHYSICAL = &H23
Const USB_DT_HUB = &H29

'Descriptor sizes per descriptor type
Const USB_DT_DEVICE_SIZE = 18
Const USB_DT_CONFIG_SIZE = 9
Const USB_DT_INTERFACE_SIZE = 9
Const USB_DT_ENDPOINT_SIZE = 7
Const USB_DT_ENDPOINT_AUDIO_SIZE = 9 '/* Audio extension */
Const USB_DT_HUB_NONVAR_SIZE = 7

'Enpoint Descriptors...
Const USB_MAXENDPOINTS = 32
Const USB_ENDPOINT_ADDRESS_MASK = &HF '/* in bEndpointAddress */
Const USB_ENDPOINT_DIR_MASK = &H80
Const USB_ENDPOINT_TYPE_MASK = &H3 '/* in bmAttributes */
Const USB_ENDPOINT_TYPE_CONTROL = 0
Const USB_ENDPOINT_TYPE_ISOCHRONOUS = 1
Const USB_ENDPOINT_TYPE_BULK = 2
Const USB_ENDPOINT_TYPE_INTERRUPT = 3

'Diverse
Const USB_MAXINTERFACES = 32
Const USB_MAXALTSETTING = 128
Const USB_MAXCONFIG = 8
Const LibUSB_Path_Max = 512
'Standard requests
Const USB_REQ_GET_STATUS = &H0
Const USB_REQ_CLEAR_FEATURE = &H1
'/* 0x02 is reserved */
Const USB_REQ_SET_FEATURE = &H3
'/* 0x04 is reserved */
Const USB_REQ_SET_ADDRESS = &H5
Const USB_REQ_GET_DESCRIPTOR = &H6
Const USB_REQ_SET_DESCRIPTOR = &H7
Const USB_REQ_GET_CONFIGURATION = &H8
Const USB_REQ_SET_CONFIGURATION = &H9
Const USB_REQ_GET_INTERFACE = &HA
Const USB_REQ_SET_INTERFACE = &HB
Const USB_REQ_SYNCH_FRAME = &HC

'Help needed also here:(
'Const USB_TYPE_STANDARD      = (0x00 << 5)
'Const USB_TYPE_CLASS        =  (0x01 << 5)
'Const USB_TYPE_VENDOR       =  (0x02 << 5)
'Const USB_TYPE_RESERVED     =  (0x03 << 5)

Const USB_RECIP_DEVICE = &H0
Const USB_RECIP_INTERFACE = &H1
Const USB_RECIP_ENDPOINT = &H2
Const USB_RECIP_OTHER = &H3

'Various libusb API related stuff
Const USB_ENDPOINT_IN = &H80
Const USB_ENDPOINT_OUT = &H0

'Error codes
Const USB_ERROR_BEGIN = 500000

'****************************************************************
'**** Here is all the structures:
'****************************************************************
Type USB_Bus
   Next As USB_Bus
   Prev As USB_Bus
   DirName(LibUSB_Path_Max) As String * 255
   Devices As USB_Device
   Location As Double
End Type

Type USB_Device
   Next As USB_Device
   Prev As USB_Device
   filename(LibUSB_Path_Max) As String * 255
   Bus As USB_Bus
   Descriptor As USB_Device_Descriptor
   Config As USB_Config_Descriptor
   'Dev As Noting ' Darwin support
End Type

Type USB_Device_Descriptor
   bLenght As String * 255 'unsigned char bLenght
   bDescriptorType As String * 255
   bcdUSB As Long 'unsigned short bcdUSB
   bDeviceClass As String * 255
   bDeviceSubClass As String * 255
   bMaxPacketSize0 As String * 255
   idVendor As Long
   idProduct As Long
   bcdDevice As Long
   iManufacturer As String * 255
   iProduct As String * 255
   iSerialNumber  As String * 255
   bNumConfigurations As String * 255
End Type

Type USB_Config_Descriptor
   bLenght As String * 255
   bDescriptorType As String * 255
   wTotalLength As Long
   bNumInterfaces As String * 255
   bConfigurationValue As String * 255
   iConfiguration As String * 255
   bmAttributes As String * 255
   MaxPower As String * 255
   Interface As USB_Interface
   Extra As String * 255
   ExtraLen As Long
End Type

Type USB_Interface
   AltSetting As USB_Interface_Descriptor
   Num_AltSetting As Integer
End Type

Type USB_Interface_Descriptor
   bLength As String * 255
   bDescriptorType As String * 255
   bInterfaceNumber As String * 255
   bAlternateSetting As String * 255
   bNumEndpoints As String * 255
   bInterfaceClass As String * 255
   bInterfaceSubClass As String * 255
   bInterfaceProtocol As String * 255
   iInterface As String * 255
   EndPoint As USB_EndPoint_Descriptor
   Extra As String * 255
   ExtraLen As Integer
End Type

Type USB_EndPoint_Descriptor
   bLength As String * 255
   bDescriptorType As String * 255
   bEndpointAddress As String * 255
   bmAttributes As String * 255
   wMaxPacketSize As String * 255
   bInterval As String * 255
   bRefresh As String * 255
   bSynchAddress As String * 255
   Extra As String * 255
   ExtraLen As Integer
End Type

 

Någen ide, eventuelt tips te foregående kode eller någen andre muligheter når det gjelder kommunikasjon med USB porten...

 

PS: Koden vil IKKE virke...(eller, kansje deler av den...)

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...