📄 s2l6.bas
字号:
Option Explicit
'**********************************************************************
'* S2L6.bas - (Section 2, Lesson 6) RECEIVING DATA FROM MULTIPLE
'* CHANNELS
'* This is the RTDX Host Client for Section 2, Lesson 6
'*
'* This example receives integer values:
'* 3 from channel ochan1
'* 2 from channel ochan2
'* 1 from channel ochan3
'**********************************************************************
Const Success = &H0 ' Method call is valid
Const Failure = &H80004005 ' Method call failed
Const ENoDataAvailable = &H8003001E ' No data was available.
' However, more data may be
' available in the future.
Const EEndOfLogFile = &H80030002 ' No data was available
' The end of the log file has
' been reached.
'**********************************************************************
' Insert code from Step #3 here - to create a structure to hold the
' attributes
'**********************************************************************
Public Type RTDX_Channel
obj As Object
name As String
type As String
opened As Boolean
End Type
Sub main()
'******************************************************************
' Insert code here to create an array instance of the type
' RTDX_Channel
'******************************************************************
Dim rtdx(1 To 3) As RTDX_Channel
Dim data As Long
Dim status As Long
Dim i As Long
On Error GoTo Error_Handler
'******************************************************************
' Insert code from Step #4 here - to initialize the channel name
'******************************************************************
rtdx(1).name = "ochan1"
rtdx(2).name = "ochan2"
rtdx(3).name = "ochan3"
'******************************************************************
' Insert code from Step #5 here - to create an instance of the RTDX
' COM Object and open the channels
'******************************************************************
For i = LBound(rtdx) To UBound(rtdx)
rtdx(i).type = "R"
rtdx(i).opened = False
Set rtdx(i).obj = CreateObject("RTDX")
status = rtdx(i).obj.Open(rtdx(i).name, _
rtdx(i).type)
If status <> Success Then
Debug.Print "Opening of channel " & _
rtdx(i).name & _
" failed"
Else
rtdx(i).opened = True
End If
Next i
For i = LBound(rtdx) To UBound(rtdx)
If rtdx(i).opened Then
'**********************************************************
' Insert code from Step #6 here - to read a 32-bit integer
' from the target
'**********************************************************
status = rtdx(i).obj.ReadI4(data)
Select Case (status)
Case Success
Debug.Print "Value " & _
data & _
" was received from target via channel " & _
rtdx(i).name
Case ENoDataAvailable
Debug.Print "No data is currently available"
Case EEndOfLogFile
Debug.Print "End of log file has been detected"
rtdx(i).opened = False
Case Failure
Debug.Print "ReadI4 returned failure"
rtdx(i).opened = False
Case Else
Debug.Print "Unknown return code"
Exit For
End Select
End If
Next i
'******************************************************************
' Insert code from Step #7 here - to close the channel and release
' the reference to the RTDX COM
' object
'******************************************************************
For i = LBound(rtdx) To UBound(rtdx)
status = rtdx(i).obj.Close()
Set rtdx(i).obj = Nothing
Next i
Exit Sub
Error_Handler:
Debug.Print "Error in COM method call"
' Release the reference to the RTDX COM object
For i = LBound(rtdx) To UBound(rtdx)
Set rtdx(i).obj = Nothing
Next i
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -