Other topics about Sample Programs
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.
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
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