📄 pcgen2.bas
字号:
'## o I/O table entries cannot be updated by the PCGEN card field side
'##
'## PDL:
'## Set I/O table lockout semaphore
'## Wait maximum of 1.5 seconds for the lockout to be recognized
'###############################################################################
Public Function RequestIOTableLockout() As Integer
Dim clkStart As Double
Dim duration As Double
'## Can set lockout semaphore when request and state are both false
If Not (SRI.iotable_lockout_request) And Not (SRI.iotable_lockout_state) Then
SRI.iotable_lockout_request = True
Else 'NOT NOT...
RequestIOTableLockout = (GENI_IOTable_Lockout_Failure)
End If
'## Wait maximum of 1.5 seconds for state to go true, indicating semaphore acknowledged
clkStart = GetTickCount
Do While Not (SRI.iotable_lockout_state) And (duration <= 1500)
'Sleep (10)
duration = GetTickCount = clkStart
DoEvents
Loop
If Not (SRI.iotable_lockout_state) Then
RequestIOTableLockout = (GENI_IOTable_Lockout_Failure)
Else 'NOT NOT...
RequestIOTableLockout = (GENI_NoError)
End If
End Function
'
'###############################################################################
'###############################################################################
Public Function TransmitDatagramWithReply(ByVal iNoReplyBytes As Integer) As Integer
Dim clkStart As Double
Dim duration As Double
Dim status As Byte
SRI.command_block.status = INCOMECMD '## Initiate command
'## Check for command complete wait a maximum of 10 seconds
clkStart = GetTickCount
Do While Not ((status And (CCOMPLETE Or SYNTAXERR Or PROCERR)) And (duration <= 10000))
'Sleep (4) '## Typical minimum Genius bus scan time let other tasks run
duration = GetTickCount - clkStart
status = SRI.command_block.status
DoEvents
Loop
'## Return any error result of command
If ((status And SYNTAXERR) = SYNTAXERR) Then
TransmitDatagramWithReply = (GENI_BadCommandSyntax)
ElseIf ((status And PROCERR) = PROCERR) Then 'NOT ((STATUS...
TransmitDatagramWithReply = (GENI_CommandProcessingError)
ElseIf (duration > 10000) Then 'NOT ((STATUS...
TransmitDatagramWithReply = (GENI_CommandTimeout)
ElseIf ((status And CCOMPLETE) <> CCOMPLETE) Then 'NOT (DURATION...
TransmitDatagramWithReply = (GENI_UnknownError)
'If (SRI.command_block.xmit_with_reply_datagram_options.Recv_Length <> iNoReplyBytes) Then
' TransmitDatagramWithReply = (GENI_BadReplyLength)
'Else
' TransmitDatagramWithReply = (GENI_NoError)
'End If
End If
End Function
''
'''###############################################################################
'''## Method "GENI_PCI_Address" is used to return a pointer to the start of the
'''## PCGEN card's dual port memory. This routine is provided to display debugging
'''## information when needed. User's should not have to access dual port memory
'''## directly rather, additional methods should be supplied as required.
'''##
'''## Inputs
'''## o None
'''##
'''## Returns
'''## o Pointer to dual-port memory
'''##
'''## No side effects
'''##
'''## PDL:
'''## Return pointer to card's dual-port memory
'''###############################################################################
''Public Function GENI_PCI_Address() As Long
''
''
''
''
''GENI_PCI_Address = MemoryBaseAddress
''End Function
''
''
'''###############################################################################
'''## Method "GENI_Windows_Handle" is used to return the handle assigned to the
'''## PCGEN card by Windows. This routine is provided to display debugging
'''## information when needed. User's should not have to access card registers
'''## directly rather, additional methods should be supplied as required.
'''##
'''## Inputs
'''## o None
'''##
'''## Returns
'''## o Windows device handle
'''##
'''## No side effects
'''##
'''## PDL:
'''## Return card's Windows device handle
'''###############################################################################
''Public Function GENI_Windows_Handle() As Long
''
''
''
''
''GENI_Windows_Handle = hWin32Device
''End Function
''
''
'''
'''###############################################################################
'''## 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 '## GENI_SETUP structure
''
''
''
''Dim clkStart As Long
''Dim duration As Double
''Dim status As Byte
'''
''CopyMemory SRI.setup, ByVal VarPtr(MemoryBaseAddress + 19), 16
''' '## Check for GENI OK _and_ command block is free
''If ((SRI.status.ok_status And GENI_OK) = False) Then
''GENI_Change_Setup = (GENI_NotOK)
''End If
''If ((SRI.command_block.status And INPROGRESS) <> False) Then
''GENI_Change_Setup = (GENI_Busy)
''End If
''' '## Update setup data in Shared RAM
''
''With SRI
''.setup.reference_address = setup.reference_address
''.setup.broadcast_control_data_length = setup.broadcast_control_data_length
''.setup.directed_control_data_length = setup.directed_control_data_length
''.setup.io_buffer_length = setup.io_buffer_length
''' '## Set up command block for configuration change And initiate command
''.command_block.COMMAND = CHANGE_CONFIG
''.command_block.status = INCOMECMD
'''
''' '## Check for command complete wait a maximum of 1.5 seconds
''End With 'SRI
''clkStart = GetTickCount
''Do While Not ((status And (CCOMPLETE Or SYNTAXERR Or PROCERR)) And (duration <= 1500))
''duration = GetTickCount - clkStart
''status = SRI.command_block.status
''DoEvents
''Loop
'''
''' '## Return result of configuration change command
''If ((status And CCOMPLETE) = CCOMPLETE) Then
''GENI_Change_Setup = (GENI_NoError)
''ElseIf ((status And SYNTAXERR) = SYNTAXERR) Then
''GENI_Change_Setup = (GENI_BadCommandSyntax)
''ElseIf ((status And PROCERR) = PROCERR) Then
''GENI_Change_Setup = (GENI_CommandProcessingError)
''ElseIf (duration > 1.5) Then
''GENI_Change_Setup = (GENI_CommandTimeout)
''Else
''GENI_Change_Setup = (GENI_UnknownError)
''End If
''CopyMemory ByVal VarPtr(MemoryBaseAddress + 19), SRI.setup, 16
''End Function
''
''
'''###############################################################################
'''## Method "GENI_Device_Configuration" is used to return the DEVICE_CONFIG
'''## structure from the PCGEN card's dual-port RAM, for a device of interest
'''## located at a specific SBA on the Genius bus. See GFK-0845, "Genius I/O Geni
'''## Board User's Manual" for details.
'''##
'''## Inputs
'''## o Pointer to DEVICE_CONFIG record
'''##
'''## Returns
'''## o GENI_STATUS information from dual-port RAM
'''##
'''## No side effects
'''##
'''## PDL:
'''## Return device configuration from dual-port RAM for given SBA on the bus
'''###############################################################################
''Public Sub GENI_Device_Configuration(ByVal SBA As Integer, dcb As DEVICE_CONFIG)
''
''
''
''
''
'''## Device SBA '## Device configuration
''CopyMemory SRI, ByVal VarPtr(MemoryBaseAddress), 14224
''
''With dcb
''.model_number = SRI.devices(SBA).model_number
''.outputs_disable = SRI.devices(SBA).outputs_disable
''.device_present = SRI.devices(SBA).device_present
''.reference_address = SRI.devices(SBA).reference_address
''.broadcast_control_data_length = SRI.devices(SBA).broadcast_control_data_length
''.directed_control_data_length = SRI.devices(SBA).directed_control_data_length
''.block_config = SRI.devices(SBA).block_config
''' return
''End With 'dcb
''End Function
''
''
'''###############################################################################
'''## Method "GENI_Return_IO_Block_Configuration" is used to return an I/O block's
'''## configuration data. See GFK-0845, "Genius I/O Geni Board User's Manual" for
'''## details.
'''##
'''## Inputs
'''## o Serial Bus Address of device to interrogate
'''## o Pointer to structure into which the configuration data will be placed
'''##
'''## Returns
'''## o Result of configuration data request
'''## - GENI_NoError
'''## - GENI_NoDevice
'''## - GENI_InappropriateDevice
'''## - GENI_NotOK
'''## - GENI_Busy
'''## - GENI_BadReplyLength
'''## - GENI_BadCommandSyntax
'''## - GENI_CommandProcessingError
'''## - GENI_CommandTimeout
'''## - GENI_UnknownError
'''##
'''## No side effects
'''##
'''## PDL:
'''## Use device model number to determine number of data requests required
'''## Issue command(s) to the device to return all its configuration data
'''###############################################################################
''Public Function GENI_Return_IO_Block_Configuration(SBA As Integer, iocb As IO_CONFIG) As Integer
''
''
''
''
''
'''## Device SBA to interrogate '## Point to IO_CONFIG structure
''Dim result As Integer
''Dim i As Integer
'''## Check for GENI OK _and_ command block is free
''If Not (SRI.status.ok_status And GENI_OK) Then
''GENI_Return_IO_Block_Configuration = (GENI_NotOK)
''ElseIf (SRI.command_block.status And INPROGRESS) Then
''GENI_Return_IO_Block_Configuration = (GENI_Busy)
''End If
'''## Verify that caller provided SBA is valid, then use it to check for
'''## device present
''If ((SBA < 0) Or (SBA > 31)) Then
''GENI_Return_IO_Block_Configuration = (GENI_BadSBAReference)
''ElseIf Not (SRI.devices(SBA).device_present) Then
''
''' If (SBA = SRI.SerialBusAddress) Then
''' GENI_Return_IO_Block_Configuration = (GENI_InappropriateDevice)
''' Else
''' GENI_Return_IO_Block_Configuration = (GENI_NoDevice)
''' End If
''End If
'''## The number of datagrams required to obtain the requested configuration
'''## data from a block depends on the model number. The maximum number of
'''## bytes which can be requested in a single datagram is 16.
''Select Case (SRI.devices(SBA).model_number)
'''## ********************************
'''## 8 Circuit Discrete I/O Blocks **
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -