R&S ESR Series User Manual page 606

Emi test receiver
Table of Contents

Advertisement

®
R&S
ESR
Dim Rd as String
Rd = Space$(100)
Creating Wrapper Procedures for Writing and Reading
Since the "VISA" functions require command and response strings and their corre-
sponding length in two separate parameters, the main program code is easier to
read and maintain if the read and write functions are encapsulated. Here, the pro-
cedure InstrWrite() encapsulates the function viWrite() and InstrRead()
encapsulates viRead(). In addition, these wrappers include status checking:
Public Sub InstrWrite(ByVal vi As Long, ByVal Cmd As String)
Dim status As Long
Dim retCount As Long
'Send command to instrument and check for status
status = viWrite(vi, Cmd, Len(Cmd), retCount)
'Check for errors - this will raise an error if status is not VI_SUCCESS
CALL CheckError(vi, status)
End Sub
Public Sub InstrRead(ByVal vi As Long, Response As String, _
ByVal count As Long, retCount As Long)
Dim status As Long
'Initialize response string
Response = Space(count)
'...and read
status = viRead(vi, Response, count, retCount)
'Check for errors - this will raise an error if status is not VI_SUCCESS
CALL CheckError(vi, status)
'adjust string length
Response = Left(Response, retCount)
End Sub
The following function illustrates status/error checking. The procedure raises an excep-
tion when a VISA error occurs:
Public Sub CheckError(ByVal vi As Long, status As Long)
Dim ErrorMessage As String * 1024
'Initialize error message string
ErrorMessage = ""
If (status < 0) Then
'Query the error message from VISA
If (viStatusDesc(vi, status, ErrorMessage) = VI_SUCCESS) Then
End If
Err.Raise (status)
End If
End Sub
User Manual 1175.7068.02 ─ 12
Err.Description = ErrorMessage
Remote Control
Controlling the R&S ESR Remotely
603

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents