' I have only done Bulk Usb programming, never any interrupt stuff,
' so I haven't tested the interrupt functions.
' The declares I used are shown below the code.
Option Explicit
' variable starts with m - module level,
' starts with p - procedure level ()function or sub
' starts with c - constant
' mabyt = _module level _array of _byte
Private Const clMaxBufferLoc = 255
Private mabytSourceFile( clMaxBufferLoc ) As Byte
'Above code must be before 1st sub or function definition
Private Sub FillBuffer( ByVal vsStringToSend As String, _
VyRef rbStringStored As Boolean)
Dim plStrLen As Long
Dim plCurArrayLoc As Long
Dim psSourceChar As String
plStrLen = Len(vsStringToSend)
If ( plStrLen >= clMaxBufferLoc) then
rbStringStored =False
Exit Sub
Endif
For plCurArrayLoc = 0 To (plStrLen - 1)
psSourceChar = Mid(psSourceFile, (1 + plCurArrayLoc), 1)
mabytSourceFile(plCurArrayLoc) = Asc(psSourceChar)
Next plCurArrayLoc
rbStringStored = True
End Sub
Private Sub WriteHello()
Dim psTest As String
Dim plBufferPtr As Long
Dim plBufferLen As Long
Dim plNrBytesWritten As Long
Dim pbStringStoredInBuffer As Boolean
psTest = "Hello"
Call FillBuffer(psTest, pbStringStoredInBuffer)
If pbStringStoredInBuffer Then
plBufferLen = Len(psTest)
' don't send a pointer to a variable declared inside a function,
' only use pointers to permanent fixed size arrays
plBufferPtr = VarPtr(mabytSourceFile(0))
' Note the use of ByVal to make sure nothing turns into a pointer
plNrBytesWritten = UsbBulkWrite(ByVal mlCurDeviceHandle, _
ByVal clDt2_USB_ENDPOINT_CommandWrite, _
ByVal plSmallBufferStartLoc, ByVal plBufferLen, _
ByVal clDt2_USB_CommandTimeout)
End If
End Sub
' Declares - put in a module
' For any function that Gets a string or a structure with
' different data types, just pass a pointer (long type) to an
' array of bytes that is big enough for the
' string or structure, then process it one byte at a time.
' "libusbvb0.dll" should be in the same directory as the program
Declare Sub UsbInit Lib "libusbvb0.dll" _
Alias "vb_usb_init" ()
Declare Sub UsbSetDebug Lib "libusbvb0.dll" _
Alias "vb_usb_set_debug" ( _
ByVal level As Long)
Declare Function UsbOpen Lib "libusbvb0.dll" _
Alias "vb_usb_open" ( _
ByVal Index As Long, _
ByVal vid As Long, _
ByVal pid As Long) As Long
Declare Function UsbClose Lib "libusbvb0.dll" _
Alias "vb_usb_close" ( _
ByVal dev 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, _
ByVal buf As Long, _
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, _
ByVal buf As Long, _
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, _
ByVal buf As Long, _
ByVal size As Long) As Long
Declare Function UsbGetDescriptor Lib "libusbvb0.dll" _
Alias "vb_usb_get_descriptor" ( _
ByVal dev As Long, _
ByVal dtype As Long, _
ByVal Index As Long, _
ByVal buf As Long, _
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, _
ByVal buf As Long, _
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, _
ByVal buf As Long, _
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, _
ByVal buf As Long, _
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, _
ByVal buf As Long, _
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 Long, _
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
|