📄 genifunctions.bas
字号:
heartbeat_enable As Integer
' Enable host/PCGEN heartbeat monitoring
heartbeat_timeout_multiplier As Byte
' Heartbeat time interval
reserved_2(4929) As Byte
' Reserved area
devices(31) As DEVICE_CONFIG
' Device configuration table
directed_control_input_table(127) As Byte
' PCGEN Directed Control input table
broadcast_control_output_table(127) As Byte
' PCGEN Broadcast Control output table
device_io_table(8191) As Byte
' Device I/O table
End Type 'Shared_RAM_Interface
'## ----------------------------------------------------------------------------
' Control register declarations
Private Const BoardResetRelease As Byte = &H40
Private Const WDT_Disable As Byte = &H20
Private Const HHM_PresentTest As Byte = &H8
'###############################################################################
'## Method "CardSetup" is used to complete the configuration and initialization
'## of a PCGEN card which has already been located as part of a previous
'## constructor call.
'##
'## Inputs
'## o Outputs enable/disable
'## o Genius bus baud rate
'## o Card's serial bus address
'##
'## Returns one of the following GENI return codes:
'## o GENI_NoError
'## 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 SBA in class static variable "SerialBusAddress".
'##
'## PDL:
'## Write outputs control, baud rate and SBA to card's configuration register
'## Write release from reset and disable watchdog timer to control register
'## Delay 4 seconds to allow board to come out of reset
'###############################################################################
Public Function CardSetup(OutputsControl As GENI_Outputs, _
BaudRate As GENI_BaudRate, _
ByVal SBA As Integer) As Integer
'## Outputs enabled/disabled '## Bus baud rate '## PCGEN card serial bus address
Dim result As Boolean
Dim dwret As Long
Dim DeviceData As GENPORT_WRITE_INPUT
Dim tmwait As Double
'## Set Baud rate, Serial Bus Address and Outputs control
DeviceData.PortNumber = CONFIG_REG
DeviceData.WriteData = CLng((OutputsControl) Or (BaudRate) Or (SBA))
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))
'Grab any errors
If Not result Then
CardSetup = (Err.LastDllError())
InitializationResult = (Err.LastDllError())
Exit Function
End If
'## Bring board out of reset and disable watchdog timer
'## If watchdog is to be enabled here, need to do a read from Shared RAM
'## to reset watchdog before enabling it (functionality not provided...)
DeviceData.PortNumber = CONTROL_REG
DeviceData.WriteData = BoardResetRelease Or WDT_Disable
'## Disable Watchdog, bring out of reset
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
CardSetup = (Err.LastDllError())
InitializationResult = (Err.LastDllError())
Exit Function
End If
'## Wait for 4 seconds to get board up from reset state
'## If the Watchdog is enabled, need to be reading from Shared RAM
'## during a startup delay to service Watchdog
tmwait = GetTickCount
Do While GetTickCount < (tmwait + 4000)
DoEvents
Loop
SerialBusAddress = SBA
CardSetup = (GENI_NoError)
InitializationResult = (GENI_NoError)
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
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
With Setup
SetVar (MemoryBaseAddress + SRI_GENI_SETUP_OFFSET + 1), .reference_address, 2
SetVar (MemoryBaseAddress + SRI_GENI_SETUP_OFFSET + 3), .broadcast_control_data_length, 1
SetVar (MemoryBaseAddress + SRI_GENI_SETUP_OFFSET + 4), .directed_control_data_length, 1
SetVar (MemoryBaseAddress + SRI_GENI_SETUP_OFFSET + 5), .io_buffer_length, 1
'## Set up command block for configuration change & initiate command
End With 'Setup
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
End If
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
'## ############################################################################
'## 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
'Only dealing with a single card here.
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))
'Grab any errors
If result = 0 Then
GENI_LocateCard = (CInt(Fix(Err.LastDllError())))
LocationResult = (CInt(Fix(Err.LastDllError())))
Else
GENI_LocateCard = (GENI_NoError)
LocationResult = (GENI_NoError)
End If
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -