📄 s2l8.bas
字号:
Option Explicit
'**********************************************************************
'* S2L8.bas - (Section 2, Lesson 8) SEEKING THROUGH MESSAGES
'* This is the RTDX Host Client for Section 2, Lesson 8
'*
'* This example receives integer values 1-10 from the target, then uses
'* the Seek() method to read the values in reverse order.
'**********************************************************************
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()
Dim rtdx As Object
Dim data As Integer
Dim status As Long
Dim nummsgs As Long
Dim i As Long
On Error GoTo Error_Handler
' Create an instance of the RTDX COM object
Set rtdx = CreateObject("RTDX")
' 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
'******************************************************************
' Insert code from Step #3 here - to get the total number of
' messages received by the host
'******************************************************************
status = rtdx.GetNumMsgs(nummsgs)
If status <> Success Then
Debug.Print "GetNumMsgs returned failure"
GoTo Error_Handler
End If
' Read data from beginning to end
Debug.Print "Reading data from beginning to end"
For i = 1 To nummsgs
' Read a 16-bit integer from the target
status = rtdx.ReadI2(data)
Select Case (status)
Case Success
Debug.Print "Value " & _
data & _
" was received from the target"
Case ENoDataAvailable
Debug.Print "No data is currently available"
Case Failure
Debug.Print "ReadI2 returned failure"
Exit For
Case Else
Debug.Print "Unknown return code"
Exit For
End Select
Next i
'******************************************************************
' Insert code from Step #4 here - to rewind the log of data
'******************************************************************
status = rtdx.Rewind()
If status <> Success Then
Debug.Print "Rewind returned failure"
GoTo Error_Handler
End If
' Read data from end to beginning
Debug.Print Chr(10) & "Reading data from end to beginning"
For i = nummsgs To 1 Step -1
'**************************************************************
' Insert code from Step #5 here - to Seek to a specific message
'**************************************************************
status = rtdx.Seek(i)
If status <> Success Then
Debug.Print "Seek returned failure"
GoTo Error_Handler
End If
' Read a 16-bit integer from the target
status = rtdx.ReadI2(data)
Select Case (status)
Case Is = Success
Debug.Print "Value " & _
data & _
" was received from the target"
Case Is = ENoDataAvailable
Debug.Print "No data is currently available"
Case Is = Failure
Debug.Print "ReadI2 returned failure"
Exit For
Case Else
Debug.Print "Unknown return code"
Exit For
End Select
Next i
' Close the channel
status = rtdx.Close()
' Release the reference to the 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 + -