Remote Control
R&S
®
ESR
616
User Manual 1175.7068.02 ─ 12
REM ************************************************************************
Public Sub ReadTrace()
'--------- Creating variables ----------------------------------------------
Dim traceData(1400) As Single 'Buffer for floating point binary data
Dim digits As Byte 'Number of characters in
'length specification
Dim traceBytes As Integer 'Len. of trace data in bytes
Dim traceValues As Integer 'No. of meas. values in buff.
Dim BinBuffer as String * 5600 'String buffer for binary data
Dim retCount as Long
asciiResult$ = Space$(28000) 'Buffer for ASCII trace data
result$ = Space$(100) 'Buffer for simple results
startFreq$ = Space$(100) 'Buffer for start frequency
span$ = Space$(100) 'Buffer for span
'--------- Default setting of the R&S FSV ---------------------------------
CALL SetupInstrument 'Default setting
CALL InstrWrite(analyzer,"INIT:CONT OFF")
'Switch to single sweep
CALL InstrWrite(analyzer,"INIT;*WAI") 'Perform sweep with sync
'--------- Defining the frequency range for output -------------------------
CALL InstrWrite(analyzer,"FREQ:STARt?") 'Read start frequency
CALL InstrRead(analyzer,startFreq$, 100, retCount)
startFreq = Val(startFreq$)
CALL InstrWrite(analyzer,"FREQ:SPAN?") 'Read span
CALL InstrRead(analyzer,span$, 100, retCount)
span = Val(span$)
'--------- Reading out in binary format ------------------------------------
CALL InstrWrite(analyzer, "FORMAT REAL,32")
'Set binary format
CALL InstrWrite(analyzer, "TRAC1? TRACE1")
'Read trace 1
CALL InstrRead(analyzer, result$, 2, retCount)
'Read and store length
digits = Val(Mid$(result$, 2, 1)) 'spec. for number of characters
result$ = Space$(100) 'Reinitialize buffer
CALL InstrRead(analyzer, result$, digits, retCount)
'Read and store length
traceBytes = Val(Left$(result$, digits))
'specification
CALL InstrRead(analyzer, BinBuffer, traceBytes, retCount)
'Read trace data into buffer
CopyMemory traceData(0), ByVal BinBuffer, traceBytes
'Copy data into float array
'--------- Outputting binary data as frequency/level pairs -----------------
traceValues = traceBytes/4 'Single precision = 4 bytes
stepsize = span/traceValues 'Calculate frequency step size
For i = 0 To traceValues - 1
Debug.Print "Value["; i; "] = "; ststepsize*i; ", "; traceData(i)
Next i
'--------- Default setting of zero span ------------------------------------
Controlling the R&S
ESR Remotely