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

📄 pcgen2.bas

📁 usb pci detection to usb port device
💻 BAS
📖 第 1 页 / 共 5 页
字号:
Attribute VB_Name = "PCGEN2"



'###############################################################################
'## Method "GENI_Change_Setup" is used to change the contents of one or more
'## SETUP structure components in the PCGEN card's dual-port RAM.  See GFK-0845,
'## "Genius I/O Geni Board User's Manual" for details.
'##
'## Inputs
'##      o Pointer to filled in GENI_SETUP record (all except configuration settings)
'##
'## Returns
'##      o Result of setup change
'##          - GENI_NoError
'##          - GENI_NotOK
'##          - GENI_Busy
'##          - GENI_BadCommandSyntax
'##          - GENI_CommandProcessingError
'##          - GENI_CommandTimeout
'##          - GENI_UnknownError
'##
'## No side effects
'##
'## PDL:
'##      Copy new setup information into card's dual-port RAM
'##      Initiate configuration change command
'##      Wait maximum of 1.5 seconds for command to complete
'###############################################################################
Public Function GENI_Change_Setup(Setup As GENI_SETUP) As Integer
    
    Dim tmwait As Double
    Dim status As Byte

    '## Check for GENI OK _and_ command block is free
    If GetVar(MemoryBaseAddress + SRI_GENI_STATUS_OFFSET + 1, 1) <> GENI_OK Then
        GENI_Change_Setup = GENI_NotOK
    End If
    If GetVar(MemoryBaseAddress + SRI_COMMAND_OFFSET, 1) = INPROGRESS Then
        GENI_Change_Setup = GENI_Busy
    End If

    '## Update setup data in Shared RAM
    SetVar (MemoryBaseAddress + SRI_GENI_SETUP_OFFSET + 1), Setup.reference_address, 2
    SetVar (MemoryBaseAddress + SRI_GENI_SETUP_OFFSET + 3), Setup.broadcast_control_data_length, 1
    SetVar (MemoryBaseAddress + SRI_GENI_SETUP_OFFSET + 4), Setup.directed_control_data_length, 1
    SetVar (MemoryBaseAddress + SRI_GENI_SETUP_OFFSET + 5), Setup.io_buffer_length, 1

    '## Set up command block for configuration change & initiate command
    SetVar (MemoryBaseAddress + SRI_COMMAND_OFFSET + 1), CHANGE_CONFIG, 1
    SetVar (MemoryBaseAddress + SRI_COMMAND_OFFSET), INCOMECMD, 1

    '## Check for command complete; wait a maximum of 1.5 seconds
    tmwait = GetTickCount
    Do While GetTickCount < tmwait + 1500
        status = GetVar(MemoryBaseAddress + SRI_COMMAND_OFFSET, 1)
        If status = CCOMPLETE Or SYNTAXERR Or PROCERR Then Exit Do
        DoEvents
    Loop

    '## Return result of configuration change command
    If status = CCOMPLETE Then
        GENI_Change_Setup = GENI_NoError
    ElseIf status = SYNTAXERR Then
        GENI_Change_Setup = GENI_BadCommandSyntax
    ElseIf status = PROCERR Then
        GENI_Change_Setup = GENI_CommandProcessingError
    ElseIf GetTickCount > tmwait + 1500 Then
        GENI_Change_Setup = GENI_CommandTimeout
    Else
        GENI_Change_Setup = GENI_UnknownError
    End If

End Function

'## ***************************************************************************
Public Sub GENI_Broadcast_Global_Data(devdata As DEVICE_DATA)

Dim I     As Integer
Dim Setup As GENI_SETUP

    For I = 0 To (Setup.broadcast_control_data_length)
        SRI.broadcast_control_output_table(I) = devdata.broadcast_global_data(I)
    Next I

End Sub

'###############################################################################
'## Method "GENI_Current_Setup" is used to return the SETUP structure from the
'## PCGEN card's dual-port RAM.  See GFK-0845, "Genius I/O Geni Board User's Manual"
'## for details.
'##
'## Inputs
'##        o Pointer to GENI_SETUP record
'##
'## Returns
'##        o GENI_SETUP information from dual-port RAM
'##
'## No side effects
'##
'## PDL:
'##        Return card's setup information from dual-port RAM
'###############################################################################
Public Function GENI_Current_Setup(Setup As GENI_SETUP)

    CopyMemory SRI, ByVal VarPtr(MemoryBaseAddress), 14224
    With Setup
        .configuration_register_settings = SRI.Setup.configuration_register_settings
        '## SBA, baud rate, outputs control
        .reference_address = SRI.Setup.reference_address
        '## Reference address
        .broadcast_control_data_length = SRI.Setup.broadcast_control_data_length
        '## Broadcast control data length
        .directed_control_data_length = SRI.Setup.directed_control_data_length
        '## Directed control data length
        .io_buffer_length = SRI.Setup.io_buffer_length
        '## I/O buffer length
    End With 'setup

End Function

'###############################################################################
'## Method "GENI_Current_Status" is used to return the STATUS structure from the
'## PCGEN card's dual-port RAM.  See GFK-0845, "Genius I/O Geni Board User's Manual"
'## for details.
'##
'## Inputs
'##        o Pointer to GENI_STATUS record
'##
'## Returns
'##        o GENI_STATUS information from dual-port RAM
'##
'## No side effects
'##
'## PDL:
'##        Return card's status information from dual-port RAM
'###############################################################################
Public Function GENI_Current_Status(status As GENI_STATUS)

    With status
        .firmware_revision = SRI.status.firmware_revision
        .ok_status = SRI.status.ok_status
        .hardware_status = SRI.status.hardware_status
        .bus_status = SRI.status.bus_status
        .bus_error_count = SRI.status.bus_error_count
        .bus_scan_time = SRI.status.bus_scan_time
    End With 'status

End Function

'// ############################################################################
'// Destructor "~GENI" is used to destroy a GENI class object, releasing all of
'// its resources in the process.  The PCGEN card itself is placed into reset.
'//
'// Inputs
'//        o None
'//
'// Returns nothing
'//
'// Side effects:
'//        o Stores destructor failure error in class static variable "InitializationResult".
'//
'// PDL:
'//        Write board reset to card's control register
'//        Free dual-port memory area
'// ############################################################################
Public Sub GENI_Destruct()

Dim result     As Boolean
Dim dwret      As Long
Dim DeviceData As GENPORT_WRITE_INPUT

    If hWin32Device <> INVALID_HANDLE_VALUE Then
        '// Turn off card
        DeviceData.PortNumber = CONTROL_REG
        DeviceData.WriteData = 0
        IOCTL_GEGENIUS_WRITE_PORT = CTL_CODE(FILE_DEVICE_UNKNOWN, &H911, METHOD_BUFFERED, FILE_WRITE_ACCESS)
        result = DeviceIoControl(hWin32Device, IOCTL_GEGENIUS_WRITE_PORT, DeviceData, ByVal CLng(LenB(DeviceData)), CLng(0), ByVal CLng(0), dwret, ByVal CLng(0))
        If Not result Then
            InitializationResult = Err.LastDllError()
            'Exit Sub
        End If
        '// Free Shared Memory range
        IOCTL_GEGENIUS_UNMAP_MEMORY = CTL_CODE(FILE_DEVICE_UNKNOWN, &H913, METHOD_BUFFERED, FILE_ANY_ACCESS)
        result = DeviceIoControl(hWin32Device, IOCTL_GEGENIUS_UNMAP_MEMORY, MemoryBaseAddress, ByVal CLng(LenB(MemoryBaseAddress)), CLng(0), ByVal CLng(0), dwret, ByVal CLng(0))
        If Not result Then
            InitializationResult = Err.LastDllError()
            'Exit Sub
        End If
        '// Close windows handle
        CloseHandle (hWin32Device)
    End If

End Sub

'###############################################################################
'## Method "LocateCard" is used to open a PCGEN device and map it into the PCI
'## address space.
'##
'## Inputs
'##        o Device number
'##
'## Returns one of the following GENI return codes:
'##        o GENI_NoError
'##        o GENI_BadDeviceReference
'##        o May also return a DeviceIoControl error code (non-zero positive #)
'##          see "System Error Code" in Windows platform SDK for decoding a
'##        device error code.
'##
'## Side effects:
'##        o Stores card's window handle in class static variable "hWin32Device".
'##        o Stores card's memory pointer in class static variable "MemoryBaseAddress".
'##
'## PDL:
'##        Open device as "\\.\GEGENIUS#" (where # in (0..3))
'##        Map device's dual port memory into PCI address space
'##        Leave device in reset for now
'###############################################################################
Public Function GENI_LocateCard(ByVal Device As Integer) As Integer

Dim result    As Boolean
Dim dwret     As Long   ' System.UInt32

    cGEGENIUS = "\\.\GEGENIUS0"
    If (Device < 0) Or (Device > (MAX_CARDS_SUPPORTED - 1)) Then
        GENI_LocateCard = GENI_BadDeviceReference
        LocationResult = GENI_BadDeviceReference
    End If
    ' Get Windows handle to Device
    hWin32Device = CreateFile(cGEGENIUS, GENERIC_READ Or GENERIC_WRITE, 0, ByVal CLng(0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
    
    'Grab any errors
    If hWin32Device = INVALID_HANDLE_VALUE Then
        GENI_LocateCard = (CInt(Fix(Err.LastDllError())))
        LocationResult = (CInt(Fix(Err.LastDllError())))
    End If
    
    ' Map Shared RAM into local process
    IOCTL_GEGENIUS_MAP_MEMORY = CTL_CODE(FILE_DEVICE_UNKNOWN, &H912, METHOD_BUFFERED, FILE_ANY_ACCESS)
    result = DeviceIoControl(ByVal hWin32Device, IOCTL_GEGENIUS_MAP_MEMORY, CLng(0), ByVal CLng(0), MemoryBaseAddress, ByVal CLng(LenB(MemoryBaseAddress)), dwret, ByVal CLng(0))
    If result = 0 Then
        GENI_LocateCard = (CInt(Fix(Err.LastDllError())))
        LocationResult = (CInt(Fix(Err.LastDllError())))
    Else 'NOT RESULT...
        GENI_LocateCard = (GENI_NoError)
        LocationResult = (GENI_NoError)
    End If

End Function

'## ***************************************************************************
'## ***************************************************************************
Public Sub GENI_Return_Broadcast_Global_Data(devdata As DEVICE_DATA)

Dim I     As Integer
Dim Setup As GENI_SETUP

    For I = 0 To (Setup.broadcast_control_data_length)
        devdata.broadcast_global_data(I) = SRI.broadcast_control_output_table(I)
    Next I

End Sub

'###############################################################################
'## Method "GENI_Return_Device_Data" is used to return all the broadcast and
'## directed control data provided by a particular device.  See GFK-0845, "Genius
'## I/O Geni Board User's Manual" for details.
'##
'## Inputs
'##        o Serial Bus Address of device to access
'##        o Pointer to structure used to store I/O data
'##
'## Returns
'##        o Result of setup change
'##            - GENI_NoError
'##            - GENI_NotOK
'##            - GENI_BadSBAReference
'##            - GENI_InappropriateDevice
'##            - GENI_IOTable_Lockout_Failure
'##            - GENI_NoDevice
'##
'## Side effects
'##        o Dual-port RAM locked out for multi-byte coherent access to I/O data
'##          (except in case of 8 circuit discrete blocks)
'##
'## PDL:
'##        Use device model number to determine type And quantity of data supported
'##        Look up requested data in dual port RAM device I/O tables
'###############################################################################
Public Function GENI_Return_Device_Data(SBA As Integer, _
                                        devdata As DEVICE_DATA) As Integer

'## Serial Bus Address of device to access  '## Storage for device's data

Dim I      As Integer
Dim result As Integer
Dim Setup  As GENI_SETUP

    ''Dim iOffset As Integer

⌨️ 快捷键说明

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