Other topics about Sample Programs
This sample program demonstrates how to retrieve and write formatted data arrays in the ASCII or binary transfer format.
The Read_Click() holds the sweep on channel 1, then read the stimulus array and the formatted data array for trace 1. The data is listed on the sheet of Excel.
The Write_Click() write the data on the same sheet into formatted data array.
See Retrieving Measurement Results for this programming.
Sub Read_Click()
Dim ReadData() As Double
Dim Poin As Integer
Dim FreqData() As Double
Dim DataType As String
'*** The variables of the resource manager and the instrument I/O are declared.
Dim ioMgr As VisaComLib.ResourceManager
Dim Ena As VisaComLib.FormattedIO488
'*** The memory area of the resource manager and the instrument I/O are acquired.
Set ioMgr = New VisaComLib.ResourceManager
Set Ena = New VisaComLib.FormattedIO488
'*** Open the instrument.
Set Ena.IO = ioMgr.Open("GPIB0::17::INSTR")
Ena.IO.Timeout = 10000
'*** Abort sweeping.
Ena.WriteString ":CALC1:PAR1:SEL", True
Ena.WriteString ":INIT1:CONT OFF", True
Ena.WriteString ":ABOR", True
'*** Get num of point of the stimulus data.
Ena.WriteString ":SENS1:SWE:POIN?", True
Poin = Ena.ReadNumber
ReDim FreqData(Poin - 1)
DataType = Cells(3, 2)
Select Case DataType
Case "Ascii"
Ena.WriteString ":FORM:DATA ASC", True
'*** Get the frequency data.
Ena.WriteString ":SENS1:FREQ:DATA?", True
FreqData() = Ena.ReadList(ASCIIType_R8, ",")
'*** Get the measurement data.
ReDim ReadData(Poin * 2 - 1)
Ena.WriteString ":CALC1:DATA:FDAT?", True
ReadData() = Ena.ReadList(ASCIIType_R8, ",")
Case "Binary"
Ena.WriteString ":FORM:DATA REAL", True
'*** Get the frequency data.
Ena.WriteString ":SENS1:FREQ:DATA?", True
FreqData = Ena.ReadIEEEBlock(BinaryType_R8, False, True)
'*** Get the measurement data.
Ena.WriteString ":CALC1:DATA:FDAT?", True
ReadData = Ena.ReadIEEEBlock(BinaryType_R8, False, True)
End Select
'*** set data for new sheet
ActiveSheet.Cells(10, 1) = "Frequency"
ActiveSheet.Cells(10, 2) = "Data 1"
ActiveSheet.Cells(10, 3) = "Data 2"
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
Ena.IO.Close
End Sub
Sub Write_Click()
Dim WriteData() As Double
Dim Poin As Integer
Dim DataType As String
'*** The variables of the resource manager and the instrument I/O are declared.
Dim ioMgr As VisaComLib.ResourceManager
Dim Ena As VisaComLib.FormattedIO488
'*** The memory area of the resource manager and the instrument I/O are acquired.
Set ioMgr = New VisaComLib.ResourceManager
Set Ena = New VisaComLib.FormattedIO488
'*** Open the instrument.
Set Ena.IO = ioMgr.Open("GPIB0::17::INSTR")
Ena.IO.Timeout = 10000
'*** Abort sweep
Ena.WriteString ":CALC1:PAR1:SEL", True
Ena.WriteString ":INIT1:CONT OFF", True
Ena.WriteString ":ABOR", True
'*** Get num of point.
Ena.WriteString ":SENS1:SWE:POIN?", True
Poin = Ena.ReadNumber
ReDim WriteData(Poin * 2 - 1) As Double
'*** Set data for array variable, and send data for the ENA
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(3, 2)
Select Case DataType
Case "Ascii"
Ena.WriteString ":FORM:DATA ASC", True
Ena.WriteString "CALC1:DATA:FDAT ", False
Ena.WriteList WriteData, ASCIIType_R8, ",", True
Case "Binary"
Ena.WriteString ":FORM:DATA REAL", True
Ena.WriteIEEEBlock ":CALC1:DATA:FDAT ", WriteData, True
End Select
'*** end procedure
Ena.IO.Close
End Sub