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

📄 pcgen2.bas

📁 usb pci detection to usb port device
💻 BAS
📖 第 1 页 / 共 5 页
字号:
            '     devdata.ANALOG_4IN_2OUT.analog_inputs(i) =
            'SRI.device_io_table ((SBA * SRI.setup.io_buffer_length) + iOffset) +
            '256 * SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + (iOffset + 1))
        Next I
        '## Check to see if this device is the assigned controller if so, can copy
        '## outputs from output table, else must request via datagram
        If Not (SRI.devices(SBA).outputs_disable) Then  '## outputs are enabled
            For I = 0 To 1 '## Access analog outputs from output portion of table
                'iOffset = (32 * SRI.setup.io_buffer_length) + (2 * i)
                '         devdata.ANALOG_4IN_2OUT.analog_outputs(i) =
                'SRI.device_io_table ((SBA * SRI.setup.io_buffer_length) + iOffset) +
                '256 * SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + (iOffset + 1))
            Next I
            result = RemoveIOTableLockout()
        Else   '## outputs are disabled request analog outputs via datagram'NOT NOT...
            result = RemoveIOTableLockout()  '## can release I/O table from lockout
            If result <> GENI_NoError Then
                GoTo endselect
            End If
            result = ReadBlockIODatagram(SBA, 22, 4)   '## only need outputs
            If result <> GENI_NoError Then
                GoTo endselect
            End If
            For I = 0 To 1 '## Need to skip first two "overhead" bytes...
                'iOffset = 2 * i
                '         devdata.ANALOG_4IN_2OUT.analog_outputs(i) =
                'SRI.read_datagram_buffer (2 + 0 + iOffset) +
                '256 * SRI.read_datagram_buffer(2 + 0 + iOffset + 1)
            Next I
        End If
    Case DevType_Current_Source_4in_2out_Analog_24VDC_48VDC         '## (IC660BBA024)
        '## Twelve total bytes of data required (8 bytes inputs, 4 bytes outputs)
        '## must lock out I/O table
        result = RequestIOTableLockout()
        If result <> GENI_NoError Then
            GoTo endselect
        End If
        For I = 0 To 3 '## Access analog inputs from input portion of table (8 bytes)
            'iOffset = 2 * i
            '     devdata.ANALOG_4IN_2OUT.analog_inputs(i) =
            'SRI.device_io_table ((SBA * SRI.setup.io_buffer_length) + iOffset) +
            '256 * SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + (iOffset + 1))
        Next I
        '## Check to see if this device is the assigned controller if so, can copy
        '## outputs from output table, else must request via datagram
        If Not (SRI.devices(SBA).outputs_disable) Then  '## outputs are enabled
            For I = 0 To 1 '## Access analog outputs from output portion of table
                'iOffset = (32 * SRI.setup.io_buffer_length) + (2 * i)
                '         devdata.ANALOG_4IN_2OUT.analog_outputs(i) =
                'SRI.device_io_table ((SBA * SRI.setup.io_buffer_length) + iOffset) +
                '256 * SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + (iOffset + 1))
            Next I
            result = RemoveIOTableLockout()
        Else   '## outputs are disabled request analog outputs via datagram'NOT NOT...
            result = RemoveIOTableLockout()  '## can release I/O table from lockout
            If result <> GENI_NoError Then
                GoTo endselect
            End If
            result = ReadBlockIODatagram(SBA, 22, 4)   '## only need outputs
            If result <> GENI_NoError Then
                GoTo endselect
            End If
            For I = 0 To 1 '## Need to skip first two "overhead" bytes...
                'iOffset = 2 * i
                '         devdata.ANALOG_4IN_2OUT.analog_outputs(i) =
                'SRI.read_datagram_buffer (2 + 0 + iOffset) +
                '256 * SRI.read_datagram_buffer(2 + 0 + iOffset + 1)
            Next I
        End If
    Case DevType_GENI
    Case DevType_Series_9070_Bus_Controller
    Case 0 'DevType_Series_9030_Bus_Controller:
        If SBA <> SerialBusAddress Then    '## GENI or GBC device on the bus
            Select Case (SRI.devices(SBA).broadcast_control_data_length)
            Case 10  '## device is not broadcasting ANY data
                result = GENI_NoError
            Case 1  '## 1 byte being broadcast no need to lock out I/O table
                devdata.broadcast_global_data(0) = SRI.device_io_table((SBA * SRI.Setup.io_buffer_length) + 0)
                result = GENI_NoError
            Case Else   '## (2..128 bytes being broadcast must lock out I/O table
                '      result = RequestIOTableLockout()
                '      If (result <> GENI_NoError) Then GoTo endselect
                For I = 0 To 128 'UBound(SRI.devices(SBA).broadcast_control_data_length)
                    devdata.broadcast_global_data(I) = SRI.device_io_table((SBA * SRI.Setup.io_buffer_length) + I)
                Next I
                '     result = RemoveIOTableLockout()
            End Select
            '         Else   '## This PCGEN device return its directed control input data
            '             GENI_Current_Setup (Andsetup)
            '             For i = 0 To UBound(setup.directed_control_data_length)
            '                 devdata.directed_control_data(i) = SRI.directed_control_input_table(i)
            '             Next i
        End If
    Case Else
        '## @@ Need to expand other data producing/consuming devices here as well...
        result = GENI_InappropriateDevice  '## Unknown or @@unsupported device...
endselect:
    End Select
    GENI_Return_Device_Data = (result)

End Function

'## ***************************************************************************
'## ***************************************************************************
Public Function GENI_Return_Directed_Control_Output_Data(ByVal iSBA As Integer, _
                                                         devdata As DEVICE_DATA) As Integer

'Dim i As Integer

Dim iResult As Integer

    Select Case (SRI.devices(iSBA).directed_control_data_length)
    Case 0
        iResult = GENI_NoError
    Case 1
        '      devdata.directed_control_data(0) =
        'SRI.device_io_table (((32 + iSBA) * SRI.setup.io_buffer_length) + 0)
        iResult = GENI_NoError
    Case Else          '## case 2..128
        iResult = RequestIOTableLockout()
        '       If (iResult <> GENI_NoError) Then End Select
        '       For i = 0 To UBound(SRI.devices(iSBA).directed_control_data_length)
        '           devdata.directed_control_data(i) =
        ''               SRI.device_io_table(((32 + iSBA) * SRI.setup.io_buffer_length) + i)
        '       Next i
        iResult = RemoveIOTableLockout()
    End Select
    GENI_Return_Directed_Control_Output_Data = (iResult)

End Function

'###############################################################################
Public Function ReadBlockIODatagram(ByVal SBA As Integer, _
                                    ByVal Offset As Byte, _
                                    NoBytes As Byte) As Integer

'## Device SBA to interrogate   '## Starting offset in block data memory    '## Number of data bytes to return

Dim iResult As Integer

    '## Set up datagram for transmission -- tells block how many bytes
    '## to return from a given starting offset
    With SRI
        .transmit_datagram_buffer(0) = Offset
        .transmit_datagram_buffer(1) = NoBytes
        '## Set up command block for transmit datagram with reply And initiate command
        .command_block.COMMAND = XMIT_DATAGRAM_WITH_REPLY
        '    SRI.command_block.xmit_with_reply_datagram_options.Destination = CByte(LOBYTE(LOWORD(SBA)))
        '    SRI.command_block.xmit_with_reply_datagram_options.Function = GEF_DATAGRAM
        '    SRI.command_block.xmit_with_reply_datagram_options.Xmit_Subfunction = SF_READ_BLOCK_IO
        '    SRI.command_block.xmit_with_reply_datagram_options.Recv_Subfunction = SF_READ_BLOCK_IO_REPLY
        '    SRI.command_block.xmit_with_reply_datagram_options.Priority = NORMAL_PRIORITY
        '    SRI.command_block.xmit_with_reply_datagram_options.Xmit_Length = 2
    End With 'SRI
    iResult = TransmitDatagramWithReply(NoBytes + 2)  '## Data bytes + xmit echo
    ReadBlockIODatagram = (iResult)

End Function

'###############################################################################
'## Method "ReadConfigurationDatagram" is used to request a segment of an I/O block's
'## configuration data via a "Transmit Datagram with Reply" command.  See GFK-0845,
'## "Genius I/O Geni Board User's Manual" for details on configuration formats.
'## See GEK-90486F-1, "Genius I/O System and Communications User's Manual for
'## details on datagrams.
'##
'## Inputs
'##        o Serial Bus Address of device to interrogate
'##        o Offset into device's configuration data
'##        o Number of consecutive bytes of configuration data requested
'##
'## Returns
'##        o Result of configuration data request
'##            - GENI_NoError
'##            - GENI_BadReplyLength
'##            - GENI_BadCommandSyntax
'##            - GENI_CommandProcessingError
'##            - GENI_CommandTimeout
'##            - GENI_UnknownError
'##
'## Side effects
'##        o "Read Datagram Buffer" in dual port RAM filled in with requested data
'##
'## PDL:
'##        Fill in Transmit Datagram With Reply datagram in dual-port RAM
'##        Initiate command to return portion of device's configuration data
'##        Wait a maximum of 10 seconds for command to complete
'###############################################################################
Public Function ReadConfigurationDatagram(ByVal SBA As Integer, _
                                          ByVal Offset As Byte, _
                                          NoBytes As Byte) As Integer

'## Device SBA to interrogate   '## Starting offset in block cfg memory '## Number of cfg bytes to return

Dim iResult As Integer

    '## Set up datagram for transmission -- tells block how many bytes
    '## to return from a given starting offset
    With SRI
        .transmit_datagram_buffer(0) = Offset
        .transmit_datagram_buffer(1) = NoBytes
        '## Set up command block for transmit datagram with reply And initiate command
        .command_block.COMMAND = XMIT_DATAGRAM_WITH_REPLY
        '    SRI.command_block.xmit_with_reply_datagram_options.Destination = CByte(LOBYTE(LOWORD(SBA)))
        '    SRI.command_block.xmit_with_reply_datagram_options.Function = GEF_DATAGRAM
        '    SRI.command_block.xmit_with_reply_datagram_options.Xmit_Subfunction = SF_READ_CONFIG
        '    SRI.command_block.xmit_with_reply_datagram_options.Recv_Subfunction = SF_READ_CONFIG_REPLY
        '    SRI.command_block.xmit_with_reply_datagram_options.Priority = NORMAL_PRIORITY
        '    SRI.command_block.xmit_with_reply_datagram_options.Xmit_Length = 2
    End With 'SRI
    iResult = TransmitDatagramWithReply(NoBytes + 2)  '## Cfg bytes + xmit echo
    ReadConfigurationDatagram = (iResult)

End Function

'###############################################################################
'## Method "ReadIdentificationDatagram" is used to ...
'###############################################################################
Public Function ReadIdentificationDatagram(ByVal SBA As Integer) As Integer

'## Device SBA to interrogate

Dim iResult As Integer

    '## Set up command block for transmit datagram with reply And initiate command
    SRI.command_block.COMMAND = XMIT_DATAGRAM_WITH_REPLY
    '    SRI.command_block.xmit_with_reply_datagram_options.Destination = CByte(LOBYTE(LOWORD(SBA)))
    '    SRI.command_block.xmit_with_reply_datagram_options.Function = GEF_DATAGRAM
    '    SRI.command_block.xmit_with_reply_datagram_options.Xmit_Subfunction = SF_READ_ID
    '    SRI.command_block.xmit_with_reply_datagram_options.Recv_Subfunction = SF_READ_ID_REPLY
    '    SRI.command_block.xmit_with_reply_datagram_options.Priority = NORMAL_PRIORITY
    '    SRIcommand_block.xmit_with_reply_datagram_options.Xmit_Length = 0
    iResult = TransmitDatagramWithReply(12)
    ReadIdentificationDatagram = (iResult)

End Function

'###############################################################################
'## Method "RemoveIOTableLockout" is used to remove the lock out of the dual-port
'## shared RAM to allow normal access on the field side.  See GFK-0845, "Genius
'## I/O Geni Board User's Manual" for details.
'##
'## Inputs
'##        o None
'##
'## Returns
'##        o Result of setup change
'##            - GENI_NoError
'##            - GENI_IOTable_Lockout_Failure
'##
'## Side effects
'##        o I/O table entries can again be updated by the PCGEN card field side
'##
'## PDL:
'##        Release I/O table lockout semaphore
'##        Wait maximum of 1.5 seconds for the lockout release to be recognized
'###############################################################################
Public Function RemoveIOTableLockout() As Integer

'Dim clkStart As Double
'Dim duration As Double

    '## Can release lockout semaphore when request and state are both true
'    If SRI.iotable_lockout_request And SRI.iotable_lockout_state Then
'        SRI.iotable_lockout_request = False
'    Else 'NOT SRI.IOTABLE_LOCKOUT_REQUEST...
'        RemoveIOTableLockout = (GENI_IOTable_Lockout_Failure)
'    End If
    '## Wait maximum of 1.5 seconds for state to go false, indicating release acknowledged
'    clkStart = getticktime
'    Do While (SRI.iotable_lockout_state) And (duration <= 1500)
'        Sleep (10)
'        duration = getticktime - clkStart
'        DoEvents
'    Loop
'    If SRI.iotable_lockout_state Then
'        RemoveIOTableLockout = (GENI_IOTable_Lockout_Failure)
'    Else 'SRI.IOTABLE_LOCKOUT_STATE = FALSE/0
'        RemoveIOTableLockout = (GENI_NoError)
'    End If

End Function

'###############################################################################
'## Method "RequestIOTableLockout" is used to lock out the dual-port shared RAM
'## from access on the field side, in order to ensure data coherency for the host.
'## The lockout should be released as soon as possible to avoid degrading I/O
'## throughput performance.  See GFK-0845, "Genius I/O Geni Board User's Manual"
'## for details.
'##
'## Inputs
'##        o None
'##
'## Returns
'##        o Result of setup change
'##            - GENI_NoError
'##            - GENI_IOTable_Lockout_Failure
'##
'## Side effects

⌨️ 快捷键说明

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