This Excel VBA Program with VISA-COM does the following:
Reads data from the analyzer
Puts the data back into memory
To run this program, you need:
An established GPIB interface connection
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 FDATA lines.
Sub SampleGetPutData()
'*** The variables of the resource manager and the instrument I/O are declared.
Dim ioMgr As VisaComLib.ResourceManager
Dim GPIB As VisaComLib.FormattedIO488
'*** The memory area of the resource manager and the instrument I/O are acquired.
Set ioMgr = New VisaComLib.ResourceManager
Set GPIB = New VisaComLib.FormattedIO488
'*** Open the instrument.
Set GPIB.IO = ioMgr.Open("GPIB0::16::INSTR")
GPIB.IO.timeout = 10000
Dim Numpts As Long
Dim Datam As Variant
'Select the measurement
GPIB.WriteString "CALCulate1:MEASure1:PARameter 'S21'", True
'Read the number of data points
GPIB.WriteString "SENSe1:SWEep:POINts?", True
Numpts = GPIB.ReadNumber
'Turn continuous sweep off
GPIB.WriteString "INITiate:CONTinuous OFF", True
'Take a sweep
GPIB.WriteString "INITiate1:IMMediate;*WAI", True
'Ask for the Data
'PICK ONE OF THESE LOCATIONS TO READ
GPIB.WriteString "CALCulate1:MEASure1:DATA:FDATA?", True ' Formatted Meas
'GPIB.WriteString "CALCulate1:MEASure1:DATA:FMEM?", True ' Formatted Memory
'GPIB.WriteString "CALCulate1:MEASure1:DATA:SDATA?", True ' Corrected, Complex Meas
'GPIB.WriteString "CALCulate1:MEASure1:DATA:SMEM?", True ' Corrected, Complex Memory
'GPIB.WriteString "SENSe1:CORRection:CSET:ETERm:DATA? 'Directivity(1,1)'", True ' Error-Term Directivity
'Parse the data
Datam = GPIB.ReadList(ASCIIType_R8, ",")
'PUT THE DATA BACK IN
GPIB.WriteString "CALCulate1:MEASure1:DATA:FDATA ", False ' Formatted Meas
'GPIB.WriteString "CALCulate1:MEASure1:DATA:FMEM ", False ' Formatted Memory
'GPIB.WriteString "CALCulate1:MEASure1:DATA:SDATA ", False ' Corrected, Complex Meas
'GPIB.WriteString "CALCulate1:MEASure1:DATA:SMEM ", False ' Corrected, Complex Memory
'GPIB.WriteString "SENSe1:CORRection:CSET:ETERm:DATA 'Directivity(1,1)',", False ' Error-Term Directivity
GPIB.WriteList Datam, ASCIIType_R8, ",", True
'*** End procedure
GPIB.IO.Close
End Sub