Reading/Writing Data

Other topics about Reading/Writing Measurement Data

Overview

The program listed in the below section is written in VISA-COM with Excel VBA. It can be executed from the external PC controller. The program demonstrates how to read/write data.

Reading/Writing Data Sample Program in Excel VBA

Reading Data

Sub Read_Click()

  Dim ReadData() As Double, FreqData() As Double

  Dim Poin As Integer, DataType As String, TraceNo As String

  

  '*** The variables of the resource manager and the instrument I/O are declared.

  Dim ioMgr As VisaComLib.ResourceManager

  Dim Analyzer As VisaComLib.FormattedIO488

 

  '*** The memory area of the resource manager and the instrument I/O are acquired.

  Set ioMgr = New VisaComLib.ResourceManager

  Set Analyzer = New VisaComLib.FormattedIO488

  

  '*** Open the instrument.

  Set Analyzer.IO = ioMgr.Open("GPIB0::17::INSTR")

  Analyzer.IO.Timeout = 10000

 

  '*** Abort sweeping.

  Analyzer.WriteString ":INIT1:CONT OFF", True

  Analyzer.WriteString ":ABOR", True

 

  '*** Select trace

  TraceNo = Cells(3, 2)

  Analyzer.WriteString ":CALC1:PAR" & TraceNo & ":SEL", True

 

  '*** Get number of point of the stimulus data.

  Analyzer.WriteString ":SENS1:SWE:POIN?", True

  Poin = Analyzer.ReadNumber

  ReDim FreqData(Poin - 1)

  ReDim ReadData(Poin * 2 - 1)

  

  DataType = Cells(5, 2)

  Select Case DataType

  Case "Ascii"

    Analyzer.WriteString ":FORM:DATA ASC", True

 

    '*** Get the frequency data.

    Analyzer.WriteString ":SENS1:FREQ:DATA?", True

    FreqData = Analyzer.ReadList(ASCIIType_R8, ",")

 

    '*** Get the measurement data.

    Analyzer.WriteString ":CALC1:DATA:FDAT?", True

    ReadData = Analyzer.ReadList(ASCIIType_R8, ",")

  Case "Binary"

    Analyzer.WriteString ":FORM:DATA REAL", True

 

    '*** Get the frequency data.

    Analyzer.WriteString ":SENS1:FREQ:DATA?", True

    FreqData = Analyzer.ReadIEEEBlock(BinaryType_R8, False, True)

 

    '*** Get the measurement data.

    Analyzer.WriteString ":CALC1:DATA:FDAT?", True

    ReadData = Analyzer.ReadIEEEBlock(BinaryType_R8, False, True)

  End Select

 

  '*** Set data for new sheet

  ActiveSheet.Cells(10, 1) = "Frequency"

  ActiveSheet.Cells(10, 2) = "Primary"

  ActiveSheet.Cells(10, 3) = "Secondary"

  ActiveSheet.Range("A11:C1000").Clear

  For i = 1 To Poin

    ActiveSheet.Cells(i + 10, 1) = FreqData(i - 1)

    ActiveSheet.Cells(i + 10, 2).Value = ReadData(i * 2 - 2)

    ActiveSheet.Cells(i + 10, 3).Value = ReadData(i * 2 - 1)

  Next i

 

  '*** End procedure

  Analyzer.IO.Close

End Sub

 

Writing Data

Sub Write_Click()

  Dim WriteData() As Double

  Dim Poin As Integer, DataType As String, TraceNo As String

 

  '*** The variables of the resource manager and the instrument I/O are declared.

  Dim ioMgr As VisaComLib.ResourceManager

  Dim Analyzer As VisaComLib.FormattedIO488

 

  '*** The memory area of the resource manager and the instrument I/O are acquired.

  Set ioMgr = New VisaComLib.ResourceManager

  Set Analyzer = New VisaComLib.FormattedIO488

 

  '*** Open the instrument.

  Set Analyzer.IO = ioMgr.Open("GPIB0::17::INSTR")

  Analyzer.IO.Timeout = 10000

 

  '*** Abort sweeping.

  Analyzer.WriteString ":INIT1:CONT OFF", True

  Analyzer.WriteString ":ABOR", True

 

  '*** Select trace

  TraceNo = Cells(3, 2)

  Analyzer.WriteString ":CALC1:PAR" & TraceNo & ":SEL", True

 

  '*** Get number of point.

  Analyzer.WriteString ":SENS1:SWE:POIN?", True

  Poin = Analyzer.ReadNumber

  ReDim WriteData(Poin * 2 - 1) As Double

 

  '*** Set data for array variable, and send data for the Analyzer

  For i = 1 To Poin

    WriteData(i * 2 - 2) = ActiveSheet.Cells(i + 10, 2).Value

    WriteData(i * 2 - 1) = ActiveSheet.Cells(i + 10, 3).Value

  Next i

  

  DataType = Cells(5, 2)

  Select Case DataType

  Case "Ascii"

    Analyzer.WriteString ":FORM:DATA ASC", True

    Analyzer.WriteString "CALC1:DATA:FDAT ", False

    Analyzer.WriteList WriteData, ASCIIType_R8, ",", True

  Case "Binary"

    Analyzer.WriteString ":FORM:DATA REAL", True

    Analyzer.WriteIEEEBlock ":CALC1:DATA:FDAT ", WriteData, True

  End Select

 

  '*** End procedure

  Analyzer.IO.Close

 

End Sub