Getting and Putting Data using SCPI


This Visual Basic Program does the following:

To run this program, you need:

 See Other SCPI Example Programs

Note: To change the read and write location of data, removing the comment from the beginning of ONE of the lines, and replace the comment in the beginning of the SDATA and SMEM lines.


Private Sub ReadWrite_Click()
Dim i As Integer
Dim t As Integer
Dim q As Integer
Dim dat As String
Dim cmd As String
Dim datum() As Double

GPIB.Configure
GPIB.Write "SYSTem:PRESet;*wai"


'Select the measurement

GPIB.Write "CALCulate:PARameter:SELect 'CH1_S11_1'"


'Read the number of data points

GPIB.Write "SENSe1:SWEep:POIN?"
numpts = GPIB.Read


'Turn continuous sweep off

GPIB.Write "INITiate:CONTinuous OFF"


'Take a sweep

GPIB.Write "INITiate:IMMediate;*wai"


'Ask for the Data

'PICK ONE OF THESE LOCATIONS TO READ

'GPIB.Write "CALCulate:DATA? FDATA" 'Formatted Meas
'GPIB.Write "CALCulate:DATA? FMEM" 'Formatted Memory

GPIB.Write "CALCulate:DATA? SDATA" 'Corrected, Complex Meas

'GPIB.Write "CALCulate:DATA? SMEM" 'Corrected, Complex Memory
'GPIB.Write "CALCulate:DATA? SCORR1" 'Error-Term Directivity


'Number of values returned per data point

'q = 1 ' Pick this if reading FDATA or FMEM

q = 2 ' Otherwise pick this


'Parse the data

ReDim datum(q, numpts)
For i = 0 To numpts - 1
  For t = 0 To q - 1
  
'Read the Data
  dat = GPIB.Read(20)
  
'Parse it into an array
  datum(t, i) = Val(dat)
  Next t
Next i


'PUT THE DATA BACK IN

GPIB.Write "format ascii"


'PICK ONE OF THESE LOCATIONS TO PUT THE DATA
'cmd = "CALCulate:DATA FDATA," 'Formatted Meas
'cmd = "CALCulate:DATA FMEM," 'Formatted Memory
'cmd = "CALCulate:DATA SDATA," 'Corrected, Complex Meas

cmd = "CALCulate:DATA SMEM," 'Corrected, Complex Memory

'cmd = "CALCulate:DATA SCORR1," 'Error-Term Directivity


For i = 0 To numpts - 1
  For t = 0 To q - 1
  If i = numpts - 1 And t = q - 1 Then
  cmd = cmd & Format(datum(t, i))
  Else
  cmd = cmd & Format(datum(t, i)) & ","
  End If
  Next t
Next i

GPIB.Write cmd
End Sub