分数肯定的再加,关键是高手你能否拿得到

kw123 2003-08-15 10:59:58
我现在有一千九百多分,遇到一个难题。对于高手来说是不难的。请告诉我它的工作流程和程序解释说明。(我是用pb,bcb,c的).分数肯定加
一:窗体程序
' EZ-USB Bulk Transfer Example
' copyright (c) 2000 Cypress Semiconductor
'
' file: frmBulk.frm

Option Explicit

Public strBuffer As String

Private Sub Form_Load()
Dim Index As Integer
Dim sDriverName As String
Dim hDriver As Long

' find all the attached EZ-USB devices and
' add them to the devices drop-down list
For Index = 0 To MAX_USB_DEV_NUMBER - 1
sDriverName = "Ezusb-" & Index
hDriver = OpenDriver(sDriverName)
If hDriver > 0 Then
cmbDriverName.AddItem sDriverName
CloseHandle hDriver
End If
Next

If cmbDriverName.ListCount > 0 Then
cmbDriverName.Text = cmbDriverName.List(0)
Else
ErrMsg (eBadDriver)
End
End If
End Sub

Private Sub Label1_Click(Index As Integer)

End Sub

Private Sub txtIn_Change()

Dim buffer(63) As Byte
Dim result As Long
Dim i As Integer
Dim lDataLen As Long
Dim sDriverName As String

' keep track of new text added to input text
strBuffer = strBuffer + Right(txtIn, 1)

' have we hit the "xfer trigger"?
If Len(strBuffer) = Val(txtBlkSize.Text) Then

' put new string data into byte buffer
lDataLen = Len(strBuffer)
For i = 1 To lDataLen
buffer(i - 1) = Asc(Mid(strBuffer, i, 1))
Next
strBuffer = ""

sDriverName = cmbDriverName.Text

' write the data to the EZ-USB board
result = DoBulkXfer(sDriverName, eWrite, buffer, lDataLen)
If result <> 1 Then: ErrMsg (result): Exit Sub

' clear out buffer
For i = 0 To 63 ' no rabbits up my sleeve
buffer(i) = 0
Next

' get text back from EZ-USB board
result = DoBulkXfer(sDriverName, eRead, buffer, lDataLen)
If result <> 1 Then: ErrMsg (result): Exit Sub

' move characters from buffer to output text area
For i = 1 To lDataLen
txtOut.Text = txtOut.Text + Chr(buffer(i - 1))
Next

End If ' xfer trigger reached

End Sub

Private Sub txtBlkSize_Change()
Dim temp As Integer
' coerce input to text representing number between 1 and 64
temp = Val(txtBlkSize)

If temp < 0 Or temp > 64 Then
MsgBox "Enter a valid Bulk Transfer block size between 1 and 64.", vbInformation, "Input Error"
txtBlkSize.SelStart = 0
txtBlkSize.SelLength = 3
End If
End Sub

Private Sub cmdClearIn_Click()
txtIn.Text = ""
End Sub

Private Sub cmdClearOut_Click()
txtOut.Text = ""
End Sub

Private Sub Form_Activate()
txtBlkSize.SetFocus
End Sub

...全文
134 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
kw123 2003-11-14
  • 打赏
  • 举报
回复
结帐,问题还是自己解决
kw123 2003-08-18
  • 打赏
  • 举报
回复
还是自己up
qingming81 2003-08-15
  • 打赏
  • 举报
回复
EZ-USB Bulk Transfer Example:EZ-USB批量转移示例。
jlum99 2003-08-15
  • 打赏
  • 举报
回复
有点意思.....
jlum99 2003-08-15
  • 打赏
  • 举报
回复
用createfile 对端口操作.
kw123 2003-08-15
  • 打赏
  • 举报
回复
你把这三个模块复制到一个地方就是一个完整的工程!
期待你的回答!!!!!!!!
kw123 2003-08-15
  • 打赏
  • 举报
回复
模块程序(2)
Public Type BulkTransferControlType
lPipeNum As Long
End Type

Public Enum USBDPipeEnum
eUsbdPipeTypeControl = 0
eUsbdPipeTypeIsochronous
eUsbdPipeTypeBulk
eUsbdPipeTypeInterrupt
End Enum

Public Type USBDPipeInformationType
'
' OUTPUT
' These fields are filled in by USBD
'
iMaximumPacketSize As Integer 'Maximum packet size for this pipe
bEndpointAddress As Byte ' 8 bit USB endpoint address (includes direction)
' taken from endpoint descriptor
bInterval As Byte ' Polling interval in ms if interrupt pipe

PipeType As USBDPipeEnum ' PipeType identifies type of transfer valid for this pipe
lPipeHandle As Long

'
' INPUT
' These fields are filled in by the client driver
'
lMaximumTransferSize As Long ' Maximum size for a single request
' in bytes.
lPipeFlags As Long
End Type

Public Type USBDInterfaceInformationType
iLength As Integer ' Length of this structure, including
' all pipe information structures that
' follow.
'
' INPUT
'
' Interface number and Alternate setting this
' structure is associated with
'
bInterfaceNumber As Byte
bAlternateSetting As Byte

'
' OUTPUT
' These fields are filled in by USBD
'
bClass As Byte
bSubClass As Byte
bProtocol As Byte
bReserved As Byte

lInterfaceHandle As Long
lNumberOfPipes As Long

Pipes(MAX_PIPES) As USBDPipeInformationType
End Type


Function DoBulkXfer(strDriver As String, pipe As Integer, ByRef buffer() As Byte, ByRef dataLen As Long) As Long
' transfers a block of bytes to or from EZ-USB device using Bulk Transfer
'
' IN strDriver symbolic link name assigned to device driver, e.g. "Ezusb-0"
' IN pipe numeric pipe id
' I/O buffer byte array for data
' I/O dataLen integer variable containing number of valid data bytes in buffer
'
' returns: 1 = successful transfer
' 0 = unsuccessful transfer; caller should call EZGetLastError function
' -1 = bad parameter
' -2 = bad driver
' -3 = bad pipe number
Dim hDriverHandle As Long
Dim result As Long
Dim btc As BulkTransferControlType
Dim pi As USBDInterfaceInformationType
Dim usbDD As USBDeviceDescriptorType
Dim lBytesReturned As Long

' get a handle to the requested driver
hDriverHandle = OpenDriver(strDriver)
'
If hDriverHandle > 0 Then

' is ep_pair.hex loaded into the EZ-USB firmware?

result = DeviceIoControl(hDriverHandle, IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR, usbDD, Len(usbDD), usbDD, Len(usbDD), lBytesReturned, 0)

If result = 0 Then: DoBulkXfer = result

' VID 0x547 and PID 0x1002 set up by ep_pair.hex download
If usbDD.iVendorID <> &H547 And usbDD.iProductID <> &H1002 Then
DoBulkXfer = eBadPipe
Exit Function
End If

' get data about caller's pipe
result = GetPipeInfo(strDriver, pi)

If result = 0 Then
DoBulkXfer = result
Exit Function
End If

' is caller's pipe legal?
If pi.lNumberOfPipes <= pipe Then
DoBulkXfer = eBadPipe
Exit Function
Else ' put the pipe id into the BulkTransferControl structure
btc.lPipeNum = pipe
End If

' determine the endpoint direction and do the device call
If (pi.Pipes(pipe).bEndpointAddress > 128) Then
result = DeviceIoControl(hDriverHandle, IOCTL_EZUSB_BULK_READ, btc, Len(btc), buffer(0), dataLen, dataLen, 0)
Else
result = DeviceIoControl(hDriverHandle, IOCTL_EZUSB_BULK_WRITE, btc, Len(btc), buffer(0), dataLen, dataLen, 0)
End If

' close the driver
CloseHandle (hDriverHandle)

DoBulkXfer = result

Else

DoBulkXfer = eBadDriver

End If

End Function

Function GetPipeInfo(strDriver As String, pi As USBDInterfaceInformationType) As Long
' retrieves information about available pipes
'
' IN strDriver symbolic link name assigned to device driver, e.g. "Ezusb-0"
' OUT pi holds information about pipes after successful return
'
' returns: 1 = successful call
' 0 = unsuccessful call

Dim result As Long
Dim hDriverHandle As Long
Dim lBytesReturned As Long

hDriverHandle = OpenDriver(strDriver)

GetPipeInfo = 0

If hDriverHandle > 0 Then

result = DeviceIoControl(hDriverHandle, IOCTL_Ezusb_GET_PIPE_INFO, pi, Len(pi), pi, Len(pi), lBytesReturned, 0)
CloseHandle (hDriverHandle)
End If

GetPipeInfo = result

End Function
Function OpenDriver(sDriverName As String) As Long
' get handle to EZ-USB driver
'
' IN sDriverName symbolic link name assigned during enumeration
'
' returns: driver handle
'
' called by: BulkXFer
' GetPipeInfo

Dim result As Long
Dim driverName As String

driverName = "\\.\" & sDriverName

result = CreateFile(driverName, (GENERIC_READ Or GENERIC_WRITE), (FILE_SHARE_READ Or FILE_SHARE_WRITE), ByVal 0, OPEN_EXISTING, 0&, 0)

If result < 0 Then
result = GetLastError()
End If
OpenDriver = result

End Function

Sub ErrMsg(err As ErrorEnum)
' display error messages to user
'
' IN err error code returned from BulkXfer
'
' called By: BulkXfer

Select Case err

Case eBadDriver
MsgBox "Selected EZ-USB Device Driver was not found. Perhaps no device is connected.", vbOKOnly + vbCritical, "BulkXFer Error"
Case eBadPipe
MsgBox "Correct Pipe not found. Perhaps ""Ep-pair.hex"" was not downloaded to a development board.", vbOKOnly + vbCritical, "BulkXFer Error"
Case Else
MsgBox "Unknown Error.", vbOKOnly + vbCritical, "BulkXFer Error"
End Select

End Sub
kw123 2003-08-15
  • 打赏
  • 举报
回复
二:模块程序(1)
'
' ´«ÊäÊý¾Ý
'
' EZ-USB Bulk Transfer Example
' copyright (c) 2000 Cypress Semiconductor
' file: BulkXfer.bas

Option Explicit

' = = = = W I N A P I = = = =

Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, ByVal lpOverlapped As Long) As Long
Public Declare Function GetLastError Lib "kernel32" () As Long

' = = = = C O N S T A N T S = = = =

Public Const GENERIC_READ = &H80000000
Public Const GENERIC_WRITE = &H40000000
Public Const FILE_SHARE_READ = &H1
Public Const FILE_SHARE_WRITE = &H2
Public Const OPEN_EXISTING = 3

Public Const METHOD_BUFFERED = 0
Public Const METHOD_IN_DIRECT = 1
Public Const METHOD_OUT_DIRECT = 2

Public Const MAX_PIPES = 16
Public Const MAX_USB_DEV_NUMBER = 32

Enum ErrorEnum
eBadParam = -1
eBadDriver = -2
eBadPipe = -3
End Enum

Enum EZ_ReadOrWrite
eWrite = 1
eRead = 0
End Enum

Public Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Boolean
End Type

' = = = = I O C T L D E F I N I O N S = = = =

' Set the base of the IOCTL control codes
Private Const Ezusb_IOCTL_INDEX = &H800

' (DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method)
' note: DeviceType for each control code is FILE_DEVICE_UNKNOWN
' FILE_DEVICE_UNKNOWN * 2^16 = &H220000
' 'Access' = FILE_ANY_ACCESS = 0

Public Const IOCTL_Ezusb_GET_PIPE_INFO = _
&H220000 + METHOD_BUFFERED + (Ezusb_IOCTL_INDEX + 0) * 4

Private Const IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR = _
&H220000 + METHOD_BUFFERED + (Ezusb_IOCTL_INDEX + 1) * 4

Public Const IOCTL_EZUSB_BULK_READ = _
&H220000 + METHOD_OUT_DIRECT + (Ezusb_IOCTL_INDEX + 19) * 4

Public Const IOCTL_EZUSB_BULK_WRITE = _
&H220000 + METHOD_IN_DIRECT + (Ezusb_IOCTL_INDEX + 20) * 4

' = = = = U S B R e q ' d D a t a T y p e s = = = =
Public Type USBDeviceDescriptorType ' USB device descriptor
bDescriptorLength As Byte
bDescriptor As Byte
iSpecRelease As Integer
bDeviceClass As Byte
bDeviceSubClass As Byte
bDeviceProtocol As Byte
bMaxPacketSize As Byte
iVendorID As Integer
iProductID As Integer
iDeviceRelease As Integer
bManufacturer As Byte
bProduct As Byte
bSerialNumber As Byte
bNumberConfigurations As Byte
fill(128) As Byte
End Type
kw123 2003-08-15
  • 打赏
  • 举报
回复
有人再解释吗?
up有分
qingming81 2003-08-15
  • 打赏
  • 举报
回复
模块程序(2)
Public Type BulkTransferControlType
lPipeNum As Long
End Type

Public Enum USBDPipeEnum
eUsbdPipeTypeControl = 0
eUsbdPipeTypeIsochronous
eUsbdPipeTypeBulk
eUsbdPipeTypeInterrupt
End Enum

Public Type USBDPipeInformationType
'
' OUTPUT
' These fields are filled in by USBD
'这些区域用USBD填入
'
iMaximumPacketSize As Integer 'Maximum packet size for this pipe
bEndpointAddress As Byte ' 8 bit USB endpoint address (includes direction)
' taken from endpoint descriptor
bInterval As Byte ' Polling interval in ms if interrupt pipe

PipeType As USBDPipeEnum ' PipeType identifies type of transfer valid for this pipe
lPipeHandle As Long

'
' INPUT
' These fields are filled in by the client driver
'这些区域为用户驱动器填入
'
lMaximumTransferSize As Long ' Maximum size for a single request
' in bytes.
''单个要求的最大字节长度。
lPipeFlags As Long
End Type

Public Type USBDInterfaceInformationType
iLength As Integer ' Length of this structure, including
' all pipe information structures that
' follow.
'该结构的长度包括如下所有管道信息结构
'
' INPUT '输入
'
' Interface number and Alternate setting this
' structure is associated with
'该结构连接的接口数字和备用设备
'
bInterfaceNumber As Byte
bAlternateSetting As Byte

'
' OUTPUT '输出
' These fields are filled in by USBD
'这些区域为USBD填入
'
bClass As Byte
bSubClass As Byte
bProtocol As Byte
bReserved As Byte

lInterfaceHandle As Long
lNumberOfPipes As Long

Pipes(MAX_PIPES) As USBDPipeInformationType
End Type


Function DoBulkXfer(strDriver As String, pipe As Integer, ByRef buffer() As Byte, ByRef dataLen As Long) As Long
' transfers a block of bytes to or from EZ-USB device using Bulk Transfer
'用批量传递,传递大量字节至EZ-USB或从EZ-USB传出。
'
' IN strDriver symbolic link name assigned to device driver, e.g. "Ezusb-0"
' IN strDriver 分配给设备驱动器的符号连接名称,如“Ezusb-0”。
' IN pipe numeric pipe id
' IN pipe 数字管道ID
' I/O buffer byte array for data
' I/O buffer 数据字节数组
' I/O dataLen integer variable containing number of valid data bytes in buffer
' I/O dataLen 缓冲器中含确定数据字节的整型变量
'
' returns: 1 = successful transfer
' 0 = unsuccessful transfer; caller should call EZGetLastError function
' -1 = bad parameter
' -2 = bad driver
' -3 = bad pipe number
' returns: 1 = 传递成功
' 0 = 传递不成功,调用EZGetLastError错误处理功能
' -1 = 参数不合法
' -2 = 驱动器不合法
' -3 = 管道数字不合法
Dim hDriverHandle As Long
Dim result As Long
Dim btc As BulkTransferControlType
Dim pi As USBDInterfaceInformationType
Dim usbDD As USBDeviceDescriptorType
Dim lBytesReturned As Long

' get a handle to the requested driver
'获得要求的驱动器句柄
hDriverHandle = OpenDriver(strDriver)
'
If hDriverHandle > 0 Then

' is ep_pair.hex loaded into the EZ-USB firmware?
'ep_pair.hex载入EZ-USB固件吗?

result = DeviceIoControl(hDriverHandle, IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR, usbDD, Len(usbDD), usbDD, Len(usbDD), lBytesReturned, 0)

If result = 0 Then: DoBulkXfer = result

' VID 0x547 and PID 0x1002 set up by ep_pair.hex download
' ep_pair.hex载入的VID 0x547和PID 0x1002设置
If usbDD.iVendorID <> &H547 And usbDD.iProductID <> &H1002 Then
DoBulkXfer = eBadPipe
Exit Function
End If

' get data about caller's pipe
'获得调用程序管道数据
result = GetPipeInfo(strDriver, pi)

If result = 0 Then
DoBulkXfer = result
Exit Function
End If

' is caller's pipe legal?
'调用程序管道合法吗?
If pi.lNumberOfPipes <= pipe Then
DoBulkXfer = eBadPipe
Exit Function
Else
' put the pipe id into the BulkTransferControl structure
'将管道ID输入BulkTransferControl结构
btc.lPipeNum = pipe
End If

' determine the endpoint direction and do the device call
' 判断终点方向并执行设备调用
If (pi.Pipes(pipe).bEndpointAddress > 128) Then
result = DeviceIoControl(hDriverHandle, IOCTL_EZUSB_BULK_READ, btc, Len(btc), buffer(0), dataLen, dataLen, 0)
Else
result = DeviceIoControl(hDriverHandle, IOCTL_EZUSB_BULK_WRITE, btc, Len(btc), buffer(0), dataLen, dataLen, 0)
End If

' close the driver
'关闭驱动器
CloseHandle (hDriverHandle)

DoBulkXfer = result

Else

DoBulkXfer = eBadDriver

End If

End Function

Function GetPipeInfo(strDriver As String, pi As USBDInterfaceInformationType) As Long
' retrieves information about available pipes
'检索现存管道信息。
'
' IN strDriver symbolic link name assigned to device driver, e.g. "Ezusb-0"
' IN strDriver 指示设备驱动器的符号连接名称,如"Ezusb-0"
' OUT pi holds information about pipes after successful return
' OUT pi 获取返回成功时的信息

' returns: 1 = successful call
' 0 = unsuccessful call
' returns: 1 = 调用成功
' 0 = 调用不成功

Dim result As Long
Dim hDriverHandle As Long
Dim lBytesReturned As Long

hDriverHandle = OpenDriver(strDriver)

GetPipeInfo = 0

If hDriverHandle > 0 Then

result = DeviceIoControl(hDriverHandle, IOCTL_Ezusb_GET_PIPE_INFO, pi, Len(pi), pi, Len(pi), lBytesReturned, 0)
CloseHandle (hDriverHandle)
End If

GetPipeInfo = result

End Function
Function OpenDriver(sDriverName As String) As Long
' get handle to EZ-USB driver
'取得EZ-USB驱动器
'
' IN sDriverName symbolic link name assigned during enumeration
' IN sDriverName 数字时分配的符号连接名称

' returns: driver handle
' 返回: 驱动器句柄
'
' called by: BulkXFer
' GetPipeInfo
' 调用者: BulkXFer
' GetPipeInfo

Dim result As Long
Dim driverName As String

driverName = "\\.\" & sDriverName

result = CreateFile(driverName, (GENERIC_READ Or GENERIC_WRITE), (FILE_SHARE_READ Or FILE_SHARE_WRITE), ByVal 0, OPEN_EXISTING, 0&, 0)

If result < 0 Then
result = GetLastError()
End If
OpenDriver = result

End Function

Sub ErrMsg(err As ErrorEnum)
' display error messages to user
'给用户显示错误
'
' IN err error code returned from BulkXfer
' IN err BulkXfer返回的错误码
'
' called By: BulkXfer
' 调用者: BulkXfer

Select Case err

Case eBadDriver
MsgBox "Selected EZ-USB Device Driver was not found. Perhaps no device is connected.", vbOKOnly + vbCritical, "BulkXFer Error"
Case eBadPipe
MsgBox "Correct Pipe not found. Perhaps ""Ep-pair.hex"" was not downloaded to a development board.", vbOKOnly + vbCritical, "BulkXFer Error"
Case Else
MsgBox "Unknown Error.", vbOKOnly + vbCritical, "BulkXFer Error"
End Select

End Sub
qingming81 2003-08-15
  • 打赏
  • 举报
回复
'代码没有测试,但可以将其英文注释翻译出来,也许可以看吧。

一:窗体程序

' EZ-USB Bulk Transfer Example
'EZ-USB批量传递例程
' copyright (c) 2000 Cypress Semiconductor
'
' file: frmBulk.frm

Option Explicit

Public strBuffer As String

Private Sub Form_Load()
Dim Index As Integer
Dim sDriverName As String
Dim hDriver As Long

' find all the attached EZ-USB devices and
' add them to the devices drop-down list
'查找所有连接的EZ-USB设备并添加这些设备到下拉列表中。
For Index = 0 To MAX_USB_DEV_NUMBER - 1
sDriverName = "Ezusb-" & Index
hDriver = OpenDriver(sDriverName)
If hDriver > 0 Then
cmbDriverName.AddItem sDriverName
CloseHandle hDriver
End If
Next

If cmbDriverName.ListCount > 0 Then
cmbDriverName.Text = cmbDriverName.List(0)
Else
ErrMsg (eBadDriver)
End
End If
End Sub

Private Sub Label1_Click(Index As Integer)

End Sub

Private Sub txtIn_Change()

Dim buffer(63) As Byte
Dim result As Long
Dim i As Integer
Dim lDataLen As Long
Dim sDriverName As String

' keep track of new text added to input text
'让新文本添加至输入文本中。
strBuffer = strBuffer + Right(txtIn, 1)

' have we hit the "xfer trigger"?
'我们是否到达“xfer板机”
If Len(strBuffer) = Val(txtBlkSize.Text) Then

' put new string data into byte buffer
'将新字符串数据加入字节缓冲器
lDataLen = Len(strBuffer)
For i = 1 To lDataLen
buffer(i - 1) = Asc(Mid(strBuffer, i, 1))
Next
strBuffer = ""

sDriverName = cmbDriverName.Text

' write the data to the EZ-USB board
'写数据到EZ-USB板
result = DoBulkXfer(sDriverName, eWrite, buffer, lDataLen)
If result <> 1 Then: ErrMsg (result): Exit Sub

' clear out buffer
'清空缓冲器
For i = 0 To 63 ' no rabbits up my sleeve
buffer(i) = 0
Next

' get text back from EZ-USB board
'从EZ-USB板取回文本
result = DoBulkXfer(sDriverName, eRead, buffer, lDataLen)
If result <> 1 Then: ErrMsg (result): Exit Sub

' move characters from buffer to output text area
'将字符从缓冲器移至输出文本区。
For i = 1 To lDataLen
txtOut.Text = txtOut.Text + Chr(buffer(i - 1))
Next

End If ' xfer trigger reached '到达xfer板机

End Sub

Private Sub txtBlkSize_Change()
Dim temp As Integer
' coerce input to text representing number between 1 and 64
'强制输入表示数字1-64之间的文本
temp = Val(txtBlkSize)

If temp < 0 Or temp > 64 Then
MsgBox "Enter a valid Bulk Transfer block size between 1 and 64.", vbInformation, "Input Error"
txtBlkSize.SelStart = 0
txtBlkSize.SelLength = 3
End If
End Sub

Private Sub cmdClearIn_Click()
txtIn.Text = ""
End Sub

Private Sub cmdClearOut_Click()
txtOut.Text = ""
End Sub

Private Sub Form_Activate()
txtBlkSize.SetFocus
End Sub


二:模块程序(1)
'
' ´«ÊäÊý¾Ý
'
' EZ-USB Bulk Transfer Example
'EZ-USB批量传递例程
' copyright (c) 2000 Cypress Semiconductor
' file: BulkXfer.bas

Option Explicit

' = = = = W I N A P I = = = =

Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, ByVal lpOverlapped As Long) As Long
Public Declare Function GetLastError Lib "kernel32" () As Long

' = = = = C O N S T A N T S = = = =

Public Const GENERIC_READ = &H80000000
Public Const GENERIC_WRITE = &H40000000
Public Const FILE_SHARE_READ = &H1
Public Const FILE_SHARE_WRITE = &H2
Public Const OPEN_EXISTING = 3

Public Const METHOD_BUFFERED = 0
Public Const METHOD_IN_DIRECT = 1
Public Const METHOD_OUT_DIRECT = 2

Public Const MAX_PIPES = 16
Public Const MAX_USB_DEV_NUMBER = 32

Enum ErrorEnum
eBadParam = -1
eBadDriver = -2
eBadPipe = -3
End Enum

Enum EZ_ReadOrWrite
eWrite = 1
eRead = 0
End Enum

Public Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Boolean
End Type

' = = = = I O C T L D E F I N I O N S = = = =
'I O C T L定义
' Set the base of the IOCTL control codes
'设置I O C T L控制码
Private Const Ezusb_IOCTL_INDEX = &H800

' (DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method)
' note: DeviceType for each control code is FILE_DEVICE_UNKNOWN
'每个控制码设备类型是FILE_DEVICE_UNKNOWN
' FILE_DEVICE_UNKNOWN * 2^16 = &H220000
' 'Access' = FILE_ANY_ACCESS = 0

Public Const IOCTL_Ezusb_GET_PIPE_INFO = _
&H220000 + METHOD_BUFFERED + (Ezusb_IOCTL_INDEX + 0) * 4

Private Const IOCTL_Ezusb_GET_DEVICE_DESCRIPTOR = _
&H220000 + METHOD_BUFFERED + (Ezusb_IOCTL_INDEX + 1) * 4

Public Const IOCTL_EZUSB_BULK_READ = _
&H220000 + METHOD_OUT_DIRECT + (Ezusb_IOCTL_INDEX + 19) * 4

Public Const IOCTL_EZUSB_BULK_WRITE = _
&H220000 + METHOD_IN_DIRECT + (Ezusb_IOCTL_INDEX + 20) * 4

' = = = = U S B R e q ' d D a t a T y p e s = = = =
Public Type USBDeviceDescriptorType ' USB device descriptor
bDescriptorLength As Byte
bDescriptor As Byte
iSpecRelease As Integer
bDeviceClass As Byte
bDeviceSubClass As Byte
bDeviceProtocol As Byte
bMaxPacketSize As Byte
iVendorID As Integer
iProductID As Integer
iDeviceRelease As Integer
bManufacturer As Byte
bProduct As Byte
bSerialNumber As Byte
bNumberConfigurations As Byte
fill(128) As Byte
End Type

7,787

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧