Reading Data in ASCII Format

Other topics about Sample Programs

Overview

This sample program demonstrates how to retrieve formatted data arrays in the ASCII transfer format.

This program holds the sweep on channel 1, then retrieves and displays the stimulus array for channel 1 and the formatted data array for trace 1.

See Retrieving Measurement Results for this programming.

Sample Program in Excel VBA using VISA

Sub read_asc_Click()

    '

    Dim defrm As Long

    Dim vi As Long

    Dim Result As String * 10000

    Dim Res As Variant

    Dim Res2 As Variant

    Dim Nop As Long

    Const TimeOutTime = 10000

    '

    ' Open the Analyzer

    Call viOpenDefaultRM(defrm)

    Call viOpen(defrm, "GPIB0::17::INSTR", 0, 0, vi)

    Call viSetAttribute(vi, VI_ATTR_TMO_VALUE, TimeOutTime)

    '

    ' Select Parameter 1

    Call viVPrintf(vi, ":CALC1:PAR1:SEL" + vbLf, 0)

    Call viVPrintf(vi, ":INIT1:CONT OFF" + vbLf, 0)

    Call viVPrintf(vi, ":ABOR" + vbLf, 0)

    '

    ' Read out NOP Data in ASCII transfer format

    Call viVPrintf(vi, ":SENS1:SWE:POIN?" + vbLf, 0)

    Call viVScanf(vi, "%t", Result)

    Nop = Val(Result)

    ReDim FMTData(Nop, 2)

    ReDim Freq(Nop)

    '

    ' Read out Measurement Data in ASCII transfer format

    Call viVPrintf(vi, ":FORM:DATA ASC" + vbLf, 0)

    Result = ""

    Call viVPrintf(vi, ":CALC1:DATA:FDAT?" + vbLf, 0)

    Call viVScanf(vi, "%t", Result)

    Res = Split(Result, ",")

    '

    Range("A6:D1607").Clear 'Clear cells of Excel

    '

    ' Write data in cells of Excel

    j = 0

    For i = 1 To Nop

        Cells(i + 5, 1) = i

        Cells(i + 5, 3) = Val(Res(j))

        Cells(i + 5, 4) = Val(Res(j + 1))

        j = j + 2

    Next i

    '

    ' Read out Measurement Frequency Data in ASCII transfer format

    Result = ""

    Call viVPrintf(vi, ":SENS1:FREQ:DATA?" + vbLf, 0)

    Call viVScanf(vi, "%t", Result)

    Res2 = Split(Result, ",")

    '

    '  Write data in cells of Excel

    For i = 1 To Nop

        Cells(i + 5, 2) = Val(Res2(i - 1))

    Next i

    '

    ' Close the Analyzer

    Call viClose(vi)

    Call viClose(defrm)

End Sub

Sample Program in Excel VBA using VISA-COM

Private Sub Read_ASC_Click()

  Dim ReadData() As Double

  Dim Poin As Integer

  Dim FreqData() As Double

  

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

  Dim ioMgr As VisaComLib.ResourceManager

  Dim Age506x As VisaComLib.FormattedIO488

 

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

  Set ioMgr = New VisaComLib.ResourceManager

  Set Age506x = New VisaComLib.FormattedIO488

  

  '*** Open the instrument.

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

  Age506x.IO.timeout = 10000

 

  '*** Abort sweeping of channel1/trace1.

  Age506x.WriteString ":CALC1:PAR1:SEL", True

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

  Age506x.WriteString ":ABOR", True

  

  '*** Set the ascii format.

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

 

  '*** Get num of point and the stimulus data.

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

  Poin = Age506x.ReadNumber

  ReDim FreqData(Poin - 1)

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

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

  

  '*** Get the measurement data.

  ReDim ReadData(Poin * 2 - 1)

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

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

 

  '*** set data for new sheet

  Sheets.Add

  ActiveSheet.Name = Format(Year(Date), "0000") & Format(Month(Date), "00") & Format(Day(Date), "00") _

                    & Format(Hour(Time), "00") & Format(Minute(Time), "00") & Format(Second(Time), "00")

  ActiveSheet.Cells(5, 3) = "Frequency"

  ActiveSheet.Cells(5, 4) = "Data 1"

  ActiveSheet.Cells(5, 5) = "Data 2"

  For i = 1 To Poin

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

    

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

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

  Next i

 

  '*** end procedure

  Age506x.IO.Close

End Sub

 

Sample Program in HT Basic (read_asc.htb)

10 REAL Fdata(1:1601,1:2),Freq(1:1601)

20 DIM Img$[30]

30 INTEGER Nop,I

40 !

50 ASSIGN @Agte506x TO 717

60 !

70 OUTPUT @Agte506x;":CALC1:PAR1:SEL"

80 OUTPUT @Agte506x;":INIT1:CONT OFF"

90 OUTPUT @Agte506x;":ABOR"

100 OUTPUT @Agte506x;":SENS1:SWE:POIN?"

110 ENTER @Agte506x;Nop

120 REDIM Fdata(1:Nop,1:2),Freq(1:Nop)

130 !

140 ! Reading out in ASCII transfer format

150 !

160 OUTPUT @Agte506x;":FORM:DATA ASC"

170 !

180 OUTPUT @Agte506x;":CALC1:DATA:FDAT?"

190 ENTER @Agte506x;Fdata(*)

200 OUTPUT @Agte506x;":SENS1:FREQ:DATA?"

210 ENTER @Agte506x;Freq(*)

220 !

230 ! Displaying

240 !

250 OUTPUT @Agte506x;":CALC1:FORM?"

260 ENTER @Agte506x;Fmt$

270 SELECT Fmt$

280 CASE "MLOG","PHAS","GDEL","MLIN","SWR","REAL","IMAG","UPH"

290 Img$="MD.4DE,2X,MD.6DE"

300 PRINT " Frequency Data"

310 FOR I=1 TO Nop

320 PRINT USING Img$;Freq(I),Fdata(I,1)

330 NEXT I

340 CASE ELSE

350 Img$="MD.4DE,2X,MD.6DE,2X,MD.6DE"

360 PRINT " Frequency Data1 Data2"

370 FOR I=1 TO Nop

380 PRINT USING Img$;Freq(I),Fdata(I,1),Fdata(I,2)

390 NEXT I

400 END SELECT

410 !

420 END