读出ASCII格式的数据

E5071C

读出ASCII格式的数据

有关样本程序的其他主题

概述

这个样本程序说明如何获取ASCII交换格式的格式化数据序列。

这个程序保持通道1上的扫描,然后获取并显示通道1的激励与迹线1的格式化数据序列。

参见这个程序的检索测量结果

在Excel VBA中的样本程序

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

在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 @Agte507x TO 717

60 !

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

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

90 OUTPUT @Agte507x;":ABOR"

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

110 ENTER @Agte507x;Nop

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

130 !

140 ! Reading out in ASCII transfer format

150 !

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

170 !

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

190 ENTER @Agte507x;Fdata(*)

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

210 ENTER @Agte507x;Freq(*)

220 !

230 ! Displaying

240 !

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

260 ENTER @Agte507x;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