📄 pcgen2.bas
字号:
'## Check for PCGEN card itself to be OK
If Not (SRI.status.ok_status And GENI_OK) Then
GENI_Return_Device_Data = (GENI_NotOK)
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_Device_Data = (GENI_BadSBAReference)
End If
If Not (SRI.devices(SBA).device_present) Then
If SBA <> SerialBusAddress Then
GENI_Return_Device_Data = (GENI_NoDevice)
End If
End If
If SBA <> SerialBusAddress Then
devdata.block_type = SRI.devices(SBA).model_number
Else '## This PCGEN device, which is of type GENI'NOT SBA...
devdata.block_type = DevType_GENI
End If
Select Case (devdata.block_type)
Case DevType_Circ_8_115VAC_Grouped_PhaseA '## (IC660CBD100)
'## Only 1 byte of data no need to lockout I/O table
'devdata.discrete_blocks(0) = SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + 0)
result = GENI_NoError
Case DevType_Circ_8_115VAC_125VDC_Isolated_PhaseA '## (IC660CBS100)
'## Only 1 byte of data no need to lockout I/O table
'devdata.discrete_blocks(0) = SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + 0)
result = GENI_NoError
Case DevType_Circ_8_115VAC_2A_Grouped '## (IC660BBD100)
'## Only 1 byte of data no need to lockout I/O table
'devdata.discrete_blocks(0) = SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + 0)
result = GENI_NoError
Case DevType_Circ_8_115VAC_125VDC_Isolated '## (IC660BBS100)
'## Only 1 byte of data no need to lockout I/O table
'devdata.discrete_blocks(0) = SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + 0)
result = GENI_NoError
Case DevType_Circ_8_220VAC_Grouped '## (IC660??????)
'## Only 1 byte of data no need to lockout I/O table
'devdata.discrete_blocks(0) = SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + 0)
result = GENI_NoError
Case DevType_Circ_8_115VAC_LowLeakage_Grouped '## (IC660BBD101)
'## Only 1 byte of data no need to lockout I/O table
'devdata.discrete_blocks(0) = SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + 0)
result = GENI_NoError
Case DevType_Circ_16_24VDC_48VDC_Sink_PhaseA '## (IC660CBD021)
'## Two bytes of data required must lock out I/O table
result = RequestIOTableLockout()
If result <> GENI_NoError Then
GoTo endselect
End If
For I = 0 To 1
' devdata.discrete_blocks(i) = SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + i)
Next I
result = RemoveIOTableLockout()
Case DevType_Circ_16_24VDC_48VDC_Source_PhaseA '## (IC660CBD020)
'## Two bytes of data required must lock out I/O table
result = RequestIOTableLockout()
If result <> GENI_NoError Then
GoTo endselect
End If
For I = 0 To 1
' devdata.discrete_blocks(i) = SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + i)
Next I
result = RemoveIOTableLockout()
Case DevType_Circ_16_24VDC_48VDC_Sink '## (IC660BBD020 / IC660BBD023)
'## Two bytes of data required must lock out I/O table
result = RequestIOTableLockout()
If result <> GENI_NoError Then
GoTo endselect
End If
For I = 0 To 1
' devdata.discrete_blocks(i) = SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + i)
Next I
result = RemoveIOTableLockout()
Case DevType_Circ_16_12VDC_24VDC_48VDC_Source '## (IC660BBD021 / IC660BBD022)
'## Two bytes of data required must lock out I/O table
result = RequestIOTableLockout()
If result <> GENI_NoError Then
GoTo endselect
End If
For I = 0 To 1
' devdata.discrete_blocks(i) = SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + i)
Next I
result = RemoveIOTableLockout()
Case DevType_Circ_16_Normally_Open_Relay '## (IC660BBR101)
'## Two bytes of data required must lock out I/O table
result = RequestIOTableLockout()
If result <> GENI_NoError Then
GoTo endselect
End If
For I = 0 To 1
' devdata.discrete_blocks(i) = SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + i)
Next I
result = RemoveIOTableLockout()
Case DevType_Circ_16_Normally_Closed_Relay '## (IC660BBR100)
'## Two bytes of data required must lock out I/O table
result = RequestIOTableLockout()
If result <> GENI_NoError Then
GoTo endselect
End If
For I = 0 To 1
' devdata.discrete_blocks(i) = SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + i)
Next I
result = RemoveIOTableLockout()
Case DevType_Circ_16_115VAC_Input '## (IC660BBD110)
'## Two bytes of data required must lock out I/O table
result = RequestIOTableLockout()
If result <> GENI_NoError Then
GoTo endselect
End If
For I = 0 To 1
' devdata.discrete_blocks(i) = SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + i)
Next I
result = RemoveIOTableLockout()
Case DevType_Circ_32_5VDC_12VDC_24VDC_Sink '## (IC660BBD025)
'## Four bytes of data required must lock out I/O table
result = RequestIOTableLockout()
If result <> GENI_NoError Then
GoTo endselect
End If
For I = 0 To 3
' devdata.discrete_blocks(i) = SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + i)
Next I
result = RemoveIOTableLockout()
Case DevType_Circ_32_12VDC_24VDC_Source '## (IC660BBD024)
'## Four bytes of data required must lock out I/O table
result = RequestIOTableLockout()
If result <> GENI_NoError Then
GoTo endselect
End If
For I = 0 To 3
' devdata.discrete_blocks(i) = SRI.device_io_table((SBA * SRI.setup.io_buffer_length) + i)
Next I
result = RemoveIOTableLockout()
Case DevType_Voltage_Current_4in_2out_Analog_115VAC '## (IC660BBA100)
'## 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_Voltage_Current_4in_2out_Analog_24VDC_48VDC '## (IC660BBA020)
'## 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_Voltage_Current_4in_2out_Analog_115VAC_PhaseA '## (IC660CBA100)
'## 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_Voltage_Current_4in_2out_Analog_24VDC_48VDC_PhaseA '## (IC660CBA020)
'## 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_Current_Source_4in_2out_Analog_115VAC_125VDC '## (IC660BBA104)
'## 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -