Other topics about Sample Programs
The sample program demonstrates to Write Formatted Data Arrays in Using the ASCII Transfer Format
See Entering Data into a Trace for this programming.
The sample programs of Excel VBA (using VISA/VISA-COM) does not create the Ch2, and the measurement point is not set. It is necessary to create Ch2 and to set the measurement point to a prescribed measurement point before the program is executed.
Private Sub Write_ASC_Click()
'*** Before this program is executed, create the channel 2,
'*** and match the number of points and data format
'*** of channel 2 to the transmitted data.
Dim defrm As Long
Dim Age506x As Long
Dim Poin As Integer
Dim Buf As String * 16
Dim WriteData() As Double
Dim AryPtr As Long
Dim WrtFmt As String
Call viOpenDefaultRM(defrm)
'*** Open the instrument, and set times 10sec for timeout.
Call viOpen(defrm, "GPIB0::17::INSTR", 0, 0, Age506x)
Call viSetAttribute(Age506x, VI_ATTR_TMO_VALUE, 10000)
'*** Abort sweeping of channel2/trace1.
Call viVPrintf(Age506x, ":CALC2:PAR1:SEL" + vbLf, 0)
Call viVPrintf(Age506x, ":INIT2:CONT OFF" + vbLf, 0)
Call viVPrintf(Age506x, ":ABOR" + vbLf, 0)
'*** Set the ascii format.
Call viVPrintf(Age506x, ":FORM:DATA ASC" + vbLf, 0)
'*** Get num of point.
Call viVPrintf(Age506x, ":SENS1:SWE:POIN?" + vbLf, 0)
Call viVScanf(Age506x, "%t", Buf)
Poin = CInt(Buf)
ReDim WriteData(Poin * 2 - 1)
'*** Set data for array variable, and send data for E506x.
For i = 1 To Poin
WriteData(i * 2 - 2) = ActiveSheet.Cells(i + 5, 4).Value
WriteData(i * 2 - 1) = ActiveSheet.Cells(i + 5, 5).Value
Next i
AryPtr = VarPtr(WriteData(0))
Call viVPrintf(Age506x, ":CALC2:DATA:FDAT ", 0)
WrtFmt = "%," & Poin * 2 & "lf"
Call viVPrintf(Age506x, WrtFmt, AryPtr)
Call viVPrintf(Age506x, vbLf, 0)
'*** end procedure
Call viClose(Age506x)
Call viClose(defrm)
End Sub
Private Sub Write_ASC_Click()
'*** Before this program executes, create the channel 2,
'*** and match the number of points and data format
'*** of channel 2 to the transmitted data.
Dim WriteData() As Double
Dim Poin As Integer
'*** 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 channel2/trace1.
Age506x.WriteString ":CALC2:PAR1:SEL", True
Age506x.WriteString ":INIT2:CONT OFF", True
Age506x.WriteString ":ABOR", True
'*** Set the ascii format.
Age506x.WriteString ":FORM:DATA ASC", True
'*** Get num of point.
Age506x.WriteString ":SENS1:SWE:POIN?", True
Poin = Age506x.ReadNumber
ReDim WriteData(Poin * 2 - 1) As Double
'*** Set data for array variable, and send data for E506x.
For i = 1 To Poin
WriteData(i * 2 - 2) = ActiveSheet.Cells(i + 5, 4).Value
WriteData(i * 2 - 1) = ActiveSheet.Cells(i + 5, 5).Value
Next i
Age506x.WriteString "CALC2:DATA:FDAT ", False
Age506x.WriteList WriteData, ASCIIType_R8, ",", True
'*** end procedure
Age506x.IO.Close
End Sub
10 REAL Freq,Fdata(1:1601,1:2)
20 DIM File$[300]
30 INTEGER Nop
40 !
50 ASSIGN @Agte506x TO 717
60 !
70 CALL Inp_file_name(File$)
80 !
90 OUTPUT @Agte506x;":CALC1:PAR1:SEL"
100 OUTPUT @Agte506x;":INIT1:CONT OFF"
110 OUTPUT @Agte506x;":ABOR"
120 !
130 OUTPUT @Agte506x;":SENS1:SWE:POIN?"
140 ENTER @Agte506x;Nop
150 REDIM Fdata(1:Nop,1:2)
160 !
170 ON ERROR GOTO File_error
180 ASSIGN @File TO File$
190 ENTER @File USING "K";Buff$
200 ENTER @File USING "K";Buff$
210 ENTER @File USING "K";Buff$
220 FOR I=1 TO Nop
230 ENTER @File USING "19D,2X,19D,2X,19D";Freq,Fdata(I,1),Fdata (I,2)
240 NEXT I
250 ASSIGN @File TO *
260 OFF ERROR
270 !
280 OUTPUT @Agte506x;":FORM:DATA ASC"
290 !
300 OUTPUT @Agte506x;":CALC1:DATA:FDAT ";Fdata(*)
310 !
320 GOTO Prog_end
330 !
340 File_error: OFF ERROR
350 PRINT "############ ERROR ############"
360 PRINT File$&" is NOT exist."
370 PRINT " or"
380 PRINT File$&" has UNSUITABLE data."
390 !
400 Prog_end: END
410 !=============================================
420 ! File Name Input Function
430 !=============================================
440 SUB Inp_file_name(Inp_name$)
450 DIM Inp_char$[9]
460 ON ERROR GOTO Inp_start
470 Inp_start: !
480 PRINT "Input File Name!"
490 INPUT "Name?",Inp_name$
500 PRINT "Input Name: "&Inp_name$
510 INPUT "OK? [Y/N]",Inp_char$
520 IF UPC$(Inp_char$)<>"Y" THEN Inp_start
530 OFF ERROR
540 SUBEND
Line 50
Assigns a GPIB address to the I/O pass.
Line 70
Passes control to a subprogram named Inp_file_name, which lets the user input a file name, and then stores the returned file name into the File$ variable. For more information on the Inp_file_name subprogram, refer to the description in Using the Binary Transfer Format to write Formatted Data Arrays.
Lines 90 to 110
These lines set channel 1's active trace to trace 1 and hold the sweep.
Lines 130 to 140
These lines retrieve the number of points in channel 1 and stores that number into the Nop variable.
Line 150
Resizes the Fdata array based on the value of the Nop variable (the number of points).
Line 170
This line points to the statement block to be executed if an error occurs in retrieving data from the file (for example, if no file matches File$).
Lines 180 to 260
These lines retrieve the formatted data from the file identified by File$, and store the data into the Fdata array.
Line 280
Sets the data transfer format to ASCII.
Line 300
Writes Fdata into the formatted data array for the active trace (trace 1) in channel 1.
Lines 340 to 380
This statement block is executed if an error occurs in retrieving data from the file.