![Rohde & Schwarz 1307.9002K03 Quick Start Manual Download Page 156](http://html1.mh-extra.com/html/rohde-and-schwarz/1307-9002k03/1307-9002k03_quick-start-manual_1477765156.webp)
Controlling the R&S
FSVA/FSV Remotely
R&S
®
FSVA/FSV
141
Quick Start Guide 1321.3066.02 ─ 06
Since the DLL returns zero-terminated strings in responses, a string of suffi-
cient 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
corresponding 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 procedure 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
exception when a VISA error occurs:
Public Sub CheckError(ByVal vi As Long, status As Long)
Dim ErrorMessage As String * 1024
'Initialize error message string
Brief Introduction to Remote Control