Quick Start
R&S
®
ESR
121
User Manual 1175.7068.02 ─ 12
●
Creating a response buffer
Since the DLL returns zero-terminated strings in responses, a string of sufficient
length must be created before the functions
InstrRead()
and
ilrd()
are called,
because Visual Basic inserts a length specification in front of the strings and this
specification is not updated by the DLL. The following two means of creating the
length specification for a string are provided:
Dim Rd as String * 100
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)
Brief Introduction to Remote Control