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

📄 usbtestmodule.vb

📁 CyPress的C8051F32X系列底层驱动(C语言)及上位机demo(vc环境)
💻 VB
字号:
Module USBTestModule

    ' Declare statements for all the functions in the SiF32xUSb DLL
    ' NOTE: These statements assume that the DLL file is located in
    '       the same directory as this project.
    '       If you change the location of the DLL, be sure to change the location
    '       in the declare statements also.
    Public Declare Function F32x_GetNumDevices Lib "SiF32xUSb.dll" (ByRef lpwdNumDevices As Integer) As Integer
    Public Declare Function F32x_GetProductString Lib "SiF32xUSb.dll" (ByVal dwDeviceNum As Integer, ByRef lpvDeviceString As Byte, ByVal dwFlags As Integer) As Integer
    Public Declare Function F32x_Open Lib "SiF32xUSb.dll" (ByVal dwDevice As UInt32, ByRef cyHandle As UInt32) As Integer
    Public Declare Function F32x_Close Lib "SiF32xUSb.dll" (ByVal cyHandle As UInt32) As Integer
    Public Declare Function F32x_Read Lib "SiF32xUSb.dll" (ByVal cyHandle As UInt32, ByRef lpBuffer As Byte, ByVal dwBytesToRead As Integer, ByRef lpdwBytesReturned As Integer) As Integer
    Public Declare Function F32x_Write Lib "SiF32xUSb.dll" (ByVal cyHandle As UInt32, ByRef lpBuffer As Byte, ByVal dwBytesToWrite As Integer, ByRef lpdwBytesWritten As Integer) As Integer
    Public Declare Function F32x_SetTimeouts Lib "SiF32xUSb.dll" (ByVal dwReadTimeout As Integer, ByVal dwWriteTimeout As Integer) As Integer
    Public Declare Function F32x_GetTimeouts Lib "SiF32xUSb.dll" (ByRef lpdwReadTimeout As Integer, ByRef lpdwWriteTimeout As Integer) As Integer
    Public Declare Function F32x_CheckRXQueue Lib "SiF32xUSb.dll" (ByVal cyHandle As UInt32, ByRef lpdwNumBytesInQueue As UInt32, ByRef lpdwQueueStatus As UInt32) As Integer

    'Masks for the serial number and description
    Public Const F32x_RETURN_SERIAL_NUMBER = &H0
    Public Const F32x_RETURN_DESCRIPTION = &H1

    'Masks for return values from the device
    Public Const F32x_SUCCESS = &H0
    Public Const F32x_DEVICE_NOT_FOUND = &HFF
    Public Const F32x_INVALID_HANDLE = &H1
    Public Const F32x_READ_ERROR = &H2
    Public Const F32x_RX_QUEUE_NOT_READY = &H3
    Public Const F32x_WRITE_ERROR = &H4
    Public Const F32x_RESET_ERROR = &H5
    Public Const F32x_INVALID_BUFFER = &H6
    Public Const F32x_INVALID_REQUEST_LENGTH = &H7
    Public Const F32x_DEVICE_IO_FAILED = &H8

    Public Const F32x_QUEUE_NO_OVERRUN = &H0
    Public Const F32x_QUEUE_OVERRUN = &H1
    Public Const F32x_QUEUE_READY = &H2

    Public Const F32x_MAX_DEVICE_STRLEN = 256
    Public Const F32x_MAX_READ_SIZE = 64
    Public Const F32x_MAX_WRITE_SIZE = 64

    Public Const INVALID_HANDLE_VALUE = &H1

    Public Const MAX_PACKET_SIZE = &H40
    Public Const MAX_WRITE_PKTS = &H8

    Public Const FT_READ_MSG = &H0
    Public Const FT_WRITE_MSG = &H1
    Public Const FT_READ_ACK = &H2
    Public Const FT_MSG_SIZE = &H3


    Public hUSBDevice As UInt32
    Public Status As Integer
    Public TempString As String

    Public Function ConvertToVBString(ByVal Str)

        Dim NewString As String
        Dim i As Integer

        'for the received string array, loop until we get
        'a 0 char, or until the max length has been obtained
        'then add the ascii char value to a vb string
        i = 0
        Do While (i < F32x_MAX_DEVICE_STRLEN) And (Str(i) <> 0)
            NewString = NewString + Chr(Str(i))
            i = i + 1
        Loop

        ConvertToVBString = NewString

    End Function

End Module


⌨️ 快捷键说明

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