📄 s2l2.bas
字号:
Option Explicit
'**********************************************************************
'* S2L2.bas - (Section 2, Lesson 2) RECEIVING AN INTEGER FROM THE
'* TARGET
'* This is the RTDX Host Client for Section 2, Lesson 2
'*
'* This example receives integer value 5 from the target
'**********************************************************************
'**********************************************************************
' Insert code from Step #3 here - to include RTDX return code contants
'**********************************************************************
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.
Sub main()
'******************************************************************
' Insert code from Step #4 here - to declare a variable of type
' Object. This will be used to
' access the methods of the
' interface
'******************************************************************
Dim rtdx As Object
Dim data As Long
Dim status As Long
On Error GoTo Error_Handler
'******************************************************************
' Insert code from Step #5 here - to create an instance of the RTDX
' COM Object
'******************************************************************
Set rtdx = CreateObject("RTDX")
'******************************************************************
' Insert code from Step #6 here - to open channel ochan for reading
'******************************************************************
status = rtdx.Open("ochan", "R")
If status <> Success Then
Debug.Print "Opening of channel ochan failed"
Goto Error_Handler
End If
Do
' *************************************************************
' Insert code from Step #7 here - to read a 32-bit integer from
' the target
'**************************************************************
status = rtdx.ReadI4(data)
Select Case (status)
Case Success
If status = Success Then
Debug.Print "Value " & _
data & _
" was received from the target"
End If
Case ENoDataAvailable
Debug.Print "No data is currently available"
Case EEndOfLogFile
Debug.Print "End of log file has been detected"
Case Failure
Debug.Print "ReadI4 returned failure"
Exit Do
Case Else
Debug.Print "Unknown return code"
Exit Do
End Select
Loop Until status = EEndOfLogFile
'******************************************************************
' Insert code from Step #8 here - to close the channel
'******************************************************************
status = rtdx.Close()
'******************************************************************
' Insert code from Step #9 here - to release reference
' to RTDX COM Object
'******************************************************************
Set rtdx = Nothing
Exit Sub
Error_Handler:
Debug.Print "Error in COM method call"
Set rtdx = Nothing
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -