'Begin by initializing the system
status = viOpenDefaultRM(dfltRM)
'Initial failed
If (status < VI_SUCCESS) Then
MsgBox " Failed to open the instrument! "
Exit Function
End If
'Open the instrument
status = viOpen(dfltRM, rsrcName, VI_NULL, VI_NULL, sesn)
'Open instrument failed
If (status < VI_SUCCESS) Then
MsgBox " Failed to open the instrument! "
Exit Function
End If
' Read from the instrument
stasus = viRead(sesn, strTemp0, 256, rSize)
' Read failed
If (status < VI_SUCCESS) Then
MsgBox " Failed to read from the instrument! "
Exit Function
End If
'Close the system
status = viClose(sesn)
status = viClose(dfltRM)
' Remove the space at the end of the string
strTemp1 = Left(strTemp0, rSize)
InstrRead = strTemp1
End Function
5. Add the control event codes.
1) Connect to the instrument
' Connect to the instrument
Private Sub CmdConnect_Click()
Const MAX_CNT = 200
Dim status As Long
Dim dfltRM As Long
Dim sesn As Long
Dim fList As Long
Dim buffer As String * MAX_CNT, Desc As String * 256
Dim nList As Long, retCount As Long
Dim rsrcName(19) As String * VI_FIND_BUFLEN, instrDesc As String *
VI_FIND_BUFLEN
Dim i, j As Long
Dim strRet As String
Dim bFindDG As Boolean
‘Initialize the system
status = viOpenDefaultRM(dfltRM)
' Initialize failed