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

📄 windrvr.bas

📁 用VB通过并口控制I2C总线
💻 BAS
📖 第 1 页 / 共 4 页
字号:
Global Const LICENSE_MSG_GEN  As Long = &H2000
Global Const LICENSE_MSG_EDU  As Long = &H4000
Global Const LICENSE_MSG_INT  As Long = &H8000&
Global Const LICENSE_KER_PLUG As Long = &H10000
Global Const LICENSE_LINUX As Long = &H20000
Global Const LICENSE_CE    As Long = &H80000
Global Const LICENSE_VXWORKS As Long = &H10000000
Global Const LICENSE_THIS_PC As Long = &H100000
Global Const LICENSE_WIZARD  As Long = &H200000
Global Const LICENSE_SOLARIS As Long = &H800000
Global Const LICENSE_CPU0 As Long = &H40000
Global Const LICENSE_CPU1 As Long = &H1000000
Global Const LICENSE_CPU2 As Long = &H2000000
Global Const LICENSE_CPU3 As Long = &H4000000
Global Const LICENSE_USB  As Long = &H8000000

Global Const LICENSE2_EVENT As Long = &H8
Global Const LICENSE2_WDLIB As Long = &H10
Global Const LICENSE2_WDF As Long = &H20

Type WD_LICENSE
    cLicense As String * 128 ' Buffer with license string to register.
                       ' If valid license, it's setting information will 
                       ' be returned by WD_License() in dwLicense/dwLicense2.
                       ' If empty string, WD_License() will return
                       ' the information for WinDriver license(s) currently
                       ' registered in the system.
    dwLicense  As Long ' License settings returned from WD_License():
                       ' LICENSE_DEMO, LICENSE_WD etc... (or 0 for 
                       ' invalid license).
    dwLicense2 As Long ' If dwLicense cannot hold all the information, then
                       ' the additional info will be returned in dwLicense2.
End Type

Type WD_BUS
    dwBusType  As Long      ' Bus Type: ISA, EISA, PCI, PCMCIA
    dwBusNum   As Long      ' Bus number
    dwSlotFunc As Long      ' Slot number on Bus
End Type

Global Const WD_BUS_ISA = 1
Global Const WD_BUS_EISA = 2
Global Const WD_BUS_PCI = 5
Global Const WD_BUS_PCMCIA = 8

Global Const ITEM_NONE = 0
Global Const ITEM_INTERRUPT = 1
Global Const ITEM_MEMORY = 2
Global Const ITEM_IO = 3
Global Const ITEM_BUS = 5

Global Const WD_ITEM_DO_NOT_MAP_KERNEL = 1

Type WD_ITEMS
    Item         As Long ' ITEM_TYPE
    fNotSharable As Long
    dwContext As Long ' Reserved for internal use
    dwOptions As Long    ' can be WD_ITEM_DO_NOT_MAP_KERNEL
    ' for ITEM_INTERRUPT
    ' dw1 - number of interrupt to install
    ' dw2 - interrupt options: INTERRUPT_LEVEL_SENSITIVE
    ' dw3 - returns the handle of the interrupt installed
    ' for ITEM_MEMORY
    ' dw1 - physical address on card
    ' dw2 - address range
    ' dw3 - returns the address to pass on to transfer commands
    ' dw4 - returns the address for direct user read/write
    ' dw5 - returns the CPU physical address of card
    ' dw6 - Base Address Register number of PCI card
    ' for ITEM_IO
    ' dw1 - beginning of io address
    ' dw2 - io range
    ' dw3 - Base Address Register number of PCI card
    dw1 As Long
    dw2 As Long
    dw3 As Long
    dw4 As Long
    dw5 As Long
    dw6 As Long
End Type

Global Const WD_CARD_ITEMS = 20

Type WD_CARD
    dwItems As Long
    Item(0 To WD_CARD_ITEMS - 1) As WD_ITEMS
End Type

Type WD_CARD_REGISTER
    Card           As WD_CARD ' card to register
    fCheckLockOnly As Long    ' only check if card is lockable, return hCard=1 if OK
    hCard          As Long    ' handle of card
    dwOptions      As Long    ' should be zero
    cName(0 To 31)      As Byte        ' name of card
    cDescription(0 To 100 - 1) As Byte ' description
End Type

Global Const WD_PCI_CARDS = 100

Type WD_PCI_SLOT
    dwBus  As Long
    dwSlot As Long
    dwFunction As Long
End Type

Type WD_PCI_ID
    dwVendorID As Long
    dwDeviceID As Long
End Type

Type WD_PCI_SCAN_CARDS
    searchId As WD_PCI_ID ' if dwVendorId = 0, scan all
                          ' vendor Ids
                          ' if dwDeviceId = 0, scan all
                          ' device Ids
    dwCards  As Long   ' Number of cards found
    cardId(0 To WD_PCI_CARDS - 1) As WD_PCI_ID
                     ' VendorID & DeviceID of cards found
    cardSlot(0 To WD_PCI_CARDS - 1) As WD_PCI_SLOT
                     ' PCI slot info of cards found
End Type

Type WD_PCI_CARD_INFO
    pciSlot As WD_PCI_SLOT ' PCI slot
    Card    As WD_CARD     ' Get card parameters for PCI slot
End Type

Global Const PCI_ACCESS_OK = 0
Global Const PCI_ACCESS_ERROR = 1
Global Const PCI_BAD_BUS = 2
Global Const PCI_BAD_SLOT = 3

Type WD_PCI_CONFIG_DUMP
    pciSlot  As WD_PCI_SLOT ' PCI bus, slot and function number
    pBuffer  As PVOID       ' buffer for read/write
    dwOffset As Long        ' offset in pci configuration space
                            ' to read/write from
    dwBytes  As Long       ' bytes to read/write from/to buffer
                                ' returns the # of bytes read/written
    fIsRead  As Long       ' if 1 then read pci config, 0 write pci config
    dwResult As Long       ' PCI_ACCESS_RESULT
End Type

Global Const WD_ISAPNP_CARDS = 16
Global Const WD_ISAPNP_COMPATIBLE_IDS = 10
Global Const WD_ISAPNP_COMP_ID_LENGTH = 7  ' ISA compressed ID is 7 chars long
Global Const WD_ISAPNP_ANSI_LENGTH = 32    ' ISA ANSI ID is limited to 32 chars long


Type WD_ISAPNP_COMP_ID
    compID(0 To WD_ISAPNP_COMP_ID_LENGTH) As Byte
End Type
Type WD_ISAPNP_ANSI
    ansi(0 To WD_ISAPNP_ANSI_LENGTH + 3) As Byte ' add 3 bytes for DWORD alignment
End Type



Type WD_ISAPNP_CARD_ID
    cVendor  As WD_ISAPNP_COMP_ID ' Vendor ID
    dwSerial As Long ' Serial number of card
End Type


Type WD_ISAPNP_CARD
    cardId As WD_ISAPNP_CARD_ID ' VendorID & serial number of cards found
    dcLogicalDevices As Long   ' Logical devices on the card
    bPnPVersionMajor As Byte    ' ISA PnP version Major
    bPnPVersionMinor As Byte    ' ISA PnP version Minor
    bVendorVersionMajor As Byte ' Vendor version Major
    bVendorVersionMinor As Byte ' Vendor version Minor
    cIdent As WD_ISAPNP_ANSI    ' Device identifier
End Type

Type WD_ISAPNP_SCAN_CARDS
    searchId As WD_ISAPNP_CARD_ID ' if searchId.cVendor[0]==0 - scan all vendor IDs
                                      ' if searchId.dwSerial==0 - scan all serial numbers
    dwCards As Long  ' number of cards found
    Card(0 To WD_ISAPNP_CARDS - 1) As WD_ISAPNP_CARD ' cards found
End Type


Type WD_ISAPNP_CARD_INFO
    cardId   As WD_ISAPNP_CARD_ID  ' VendorID and serial number of card
    dwLogicalDevice     As Long   ' logical device in card
    cLogicalDeviceId    As WD_ISAPNP_COMP_ID  ' logical device ID
    dwCompatibleDevices As Long   ' number of compatible device IDs
    CompatibleDevice(0 To WD_ISAPNP_COMPATIBLE_IDS - 1) As WD_ISAPNP_COMP_ID ' Compatible device IDs
    cIdent As WD_ISAPNP_ANSI  ' Device identifier
    Card As WD_CARD  ' get card parameters for the ISA PnP card
End Type

Global Const ISAPNP_ACCESS_OK = 0
Global Const ISAPNP_ACCESS_ERROR = 1
Global Const ISAPNP_BAD_ID = 2

Type WD_ISAPNP_CONFIG_DUMP
    cardId   As WD_ISAPNP_CARD_ID  ' VendorID and serial number of card
    dwOffset As Long   ' offset in ISA PnP configuration space to read/write from
    fIsRead  As Long   ' if 1 then read ISA PnP config, 0 write ISA PnP config
    bData    As Byte    ' result data of byte read/write
    dwResult As Long ' ISAPNP_ACCESS_RESULT
End Type

Global Const WD_PCMCIA_CARDS = 8
Global Const WD_PCMCIA_VERSION_LEN = 4
Global Const WD_PCMCIA_MANUFACTURER_LEN = 48
Global Const WD_PCMCIA_PRODUCTNAME_LEN = 48
Global Const WD_PCMCIA_MAX_SOCKET = 2
Global Const WD_PCMCIA_MAX_FUNCTION = 2


Type WD_PCMCIA_SLOT
    uSocket    As Byte  ' Specifies the socket number (first socket is 0)
    uFunction  As Byte  ' Specifies the function number (first function is 0)
    uPadding0  As Byte  ' 2 bytes padding so structure will be 4 bytes aligned
    uPadding1  As Byte
End Type

Type WD_PCMCIA_ID
    dwManufacturerId As Long ' card manufacturer
    dwCardId         As Long ' card type and model
End Type

Type WD_PCMCIA_SCAN_CARDS
    searchId As WD_PCMCIA_ID                              ' device ID to search for
    dwCards As Long                                       ' number of cards found
    cardId(0 To WD_PCMCIA_CARDS - 1) As WD_PCMCIA_ID      ' device IDs of cards found
    cardSlot(0 To WD_PCMCIA_CARDS - 1) As WD_PCMCIA_SLOT  ' pcmcia slot info of cards found
End Type

Type WD_PCMCIA_CARD_INFO
    pcmciaSlot As WD_PCMCIA_SLOT  ' pcmcia slot
    Card As WD_CARD               ' get card parameters for pcmcia slot
    cVersion(0 To WD_PCMCIA_VERSION_LEN - 1) As Byte
    cManufacturer(0 To WD_PCMCIA_MANUFACTURER_LEN - 1) As Byte
    cProductName(0 To WD_PCMCIA_PRODUCTNAME_LEN - 1) As Byte
    dwManufacturerId As Long      ' card manufacturer
    dwCardId As Long              ' card type and model
    dwFuncId As Long              ' card function code
End Type

Type WD_PCMCIA_CONFIG_DUMP
    pcmciaSlot As WD_PCMCIA_SLOT
    pBuffer    As PVOID     ' buffer for read/write
    dwOffset   As Long      ' offset in pcmcia configuration space to
                            ' read/write from
    dwBytes    As Long      ' bytes to read/write from/to buffer
                            ' returns the number of bytes read/wrote
    fIsRead    As Long      ' if 1 then read pci config, 0 write pci config
    dwResult   As Long      ' PCMCIA_ACCESS_RESULT
End Type

Global Const SLEEP_NON_BUSY = 1

Type WD_SLEEP
    dwMicroSeconds As Long ' Sleep time in Micro Seconds (1/1,000,000 Second)
    dwOptions      As Long ' can be:
                           ' SLEEP_NON_BUSY this is accurate only for times above 10000 uSec
End Type

Global Const D_OFF = 0
Global Const D_ERROR = 1
Global Const D_WARN = 2
Global Const D_INFO = 3
Global Const D_TRACE = 4

Global Const S_ALL As Long = &HFFFFFFFF
Global Const S_IO As Long = &H8
Global Const S_MEM As Long = &H10
Global Const S_INT As Long = &H20
Global Const S_PCI As Long = &H40
Global Const S_DMA As Long = &H80
Global Const S_MISC As Long = &H100
Global Const S_LICENSE As Long = &H200
Global Const S_ISAPNP As Long = &H400
Global Const S_PCMCIA As Long = &H800
Global Const S_KER_PLUG As Long = &H10000
Global Const S_CARD_REG As Long = &H2000

Global Const DEBUG_STATUS = 1
Global Const DEBUG_SET_FILTER = 2
Global Const DEBUG_SET_BUFFER = 3
Global Const DEBUG_CLEAR_BUFFER = 4
Global Const DEBUG_DUMP_SEC_ON = 5
Global Const DEBUG_DUMP_SEC_OFF = 6
Global Const KERNEL_DEBUGGER_ON = 7
Global Const KERNEL_DEBUGGER_OFF = 8

'from win32API
Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function DeviceIoControl Lib "kernel32" ( _
    ByVal hDevice As Long, _
    ByVal dwIoControlCode As Long, _
          lpInBuffer As Any, _
    ByVal nInBufferSize As Long, _
          lpOutBuffer As Long, _
    ByVal nOutBufferSize As Long, _
          lpBytesReturned As Long, _
    ByVal lpOverlapped As Long) As Long
Declare Sub memcpy Lib "kernel32" Alias "RtlMoveMemory" _
         (ByVal hpvDest As Long, ByVal hpvSource As Any, ByVal cbCopy As Long)
Private Const GENERIC_READ = &H80000000
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const OPEN_EXISTING = 3
Private Const FILE_FLAG_OVERLAPPED = &H40000000
Global Const INVALID_HANDLE_VALUE = -1

'call this function with the variable of which you need the pointer and the last two params pass 1
'address = WD_VB_GetAddress (Variable, 1, 1) 'this extracts the address of Variable
Declare Function WD_VB_GetAddress Lib "kernel32" Alias "MulDiv" (ByRef dwNum As Any, ByVal one As Long, ByVal one_ As Long) As Long

Type WD_DEBUG
    dwCmd As Long          ' DEBUG_COMMAND as DEBUG_STATUS, DEBUG_SET_FILTER, DEBUG_SET_BUFFER, DEBUG_CLEAR_BUFFER
                           ' used for DEBUG_SET_FILTER
    dwLevel As Long        ' DEBUG_LEVEL as D_ERROR, D_WARN..., or D_OFF to turn debugging off
    dwSection As Long      ' DEBUG_SECTION as for all sections in driver as S_ALL
                           ' for partial sections as S_IO, S_MEM...
    dwLevelMessageBox As Long  ' DEBUG_LEVEL to print in a message box
                               ' used for DEBUG_SET_BUFFER
    dwBufferSize As Long   ' size of buffer in kernel
End Type

Type PChar

⌨️ 快捷键说明

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