Other topics about Sample Programs
This sample program is useful when you trigger the instrument without using an external controller or when you need to perform a particular task between triggering and retrieval.
The program demonstrates the use of the :FETC? command which returns the measurement data from the most recently performed measurement.
See these topics for this programming:
Sub FETC()
'*** The variables of the resource manager and the instrument I/O are declared
Dim ioMgr As VisaComLib.ResourceManager
Dim Age4982x As VisaComLib.FormattedIO488
'*** The memory area of the resource manager and the instrument I/O are acquired
Set ioMgr = New VisaComLib.ResourceManager
Set Age4982x = New VisaComLib.FormattedIO488
'*** Open the instrument & Sets the GPIB address
Set Age4982x.IO = ioMgr.Open("GPIB0::17::INSTR")
Age4982x.IO.timeout = 30000 ' Timeout time should be greater than the measurement time.
MsgBox ("4982X is Open!"), vbOKOnly
'*** Variable declaration
Dim Title(7), Buff, OutputFile, Ofile As String
Dim Res() As Double
Dim Stode As Integer
Dim Stat(7), Bin_stat, List_stat, Star_no, Stop_no, Data_size, i, J, Loc As Integer
Stode = 7
'* Create and store output file in the root directory
OutputFile = "c:\work\output_fetc.txt"
'* Set and open output file
Ofile = FreeFile()
'* Sets the data transfer format to ASCII.
Age4982x.WriteString ":FORM ASC", True
'*Retrieves the display on/off (0/1) setting and parameter names for measurement parameters 1 through 4
'* and stores the settings and names into the variables Stat(1) through Stat(4) and Title(1) through Title(4).
For i = 1 To 4
Age4982x.WriteString ":DISP:TEXT1:CALC" & Val(i) & "?", True
Stat(i) = Age4982x.ReadNumber
Age4982x.WriteString ":CALC:PAR" & Val(i) & ":FORM?", True
Title(i) = Age4982x.ReadString
Next i
'* Retrieves the display on/off (0/1) setting for the result of test signal current level monitoring
'* and stores the setting into the Stat(5) variable; stores the title (Imon) for current level monitoring
'* into the Title(5) variable.
Age4982x.WriteString ":DISP:TEXT1:CALC11?", True
Stat(5) = Age4982x.ReadNumber
Title(5) = "Imon"
'* Retrieves the display on/off (0/1) setting for the result of test signal current level monitoring
'* and stores the setting into the Stat(6) variable; stores the title (Imon) for current level monitoring
'* into the Title(6) variable.
Age4982x.WriteString ":DISP:TEXT1:CALC12?", True
Stat(6) = Age4982x.ReadNumber
Title(6) = "Vmon"
'* Retrieves the display on/off (0/1) setting for the result of test signal current level monitoring
'* and stores the setting into the Stat(7) variable; stores the title (Imon) for current level monitoring
'* into the Title(7) variable.
Age4982x.WriteString ":SOUR:LIST:RDC?", True
Stat(7) = Age4982x.ReadNumber
Title(7) = "Rdc"
'* Retrieves the on/off (0/1) setting of bin sorting and stores the setting into the Bin_stat variable.
Age4982x.WriteString ":CALC:COMP?", True
Bin_stat = Age4982x.ReadNumber
'* Retrieves the list/single-point (0/1) measurement setting and stores the setting into the List_stat variables.
Age4982x.WriteString ":SOUR:LIST:STAT?", True
List_stat = Age4982x.ReadNumber
'* If list measurement is specified (List_stat variable = 1), the program retrieves the number of measurement points
'* and stores the data into the Stop_no variable while storing “1” into the Star_no variable.
'* If single-point measurement is specified (List_stat is not equal to 1), the program retrieves the identification number
'* of the specific measurement point and stores the data into the Stop_no and Star_no variables.
If List_stat = 1 Then
Age4982x.WriteString ":SOUR:LIST:SIZE?", True
Stop_no = Age4982x.ReadNumber
Star_no = 1
Else
Age4982x.WriteString ":SOUR:LIST:POIN?", True
Stop_no = Age4982x.ReadNumber
Star_no = Stop_no
End If
'* Calculates the data size and resizes the Res array.
Data_size = (1 + Stat(1) + Stat(2) + Stat(3) + Stat(4) + Stat(5) + Stat(6) + Stat(7)) * (Stop_no - Star_no + 1) + Bin_stat
ReDim Res(Data_size)
'* After measurement is stopped (the trigger system is stopped), the program sets
'* the trigger source to Manual trigger and turns on the continuous activation of the trigger system.
Age4982x.WriteString ":ABOR", True
Age4982x.WriteString ":TRIG:SOUR MAN", True
Age4982x.WriteString ":INIT:CONT ON", True
'* Status register setting (For SRQ). Instructs the instrument to generate an SRQ
'* upon completion of measurement and clears the status byte register and operation status event register.
Age4982x.WriteString ":STAT:OPER:PTR 0", True
Age4982x.WriteString ":STAT:OPER:NTR 16", True
Age4982x.WriteString ":STAT:OPER:ENAB 16", True
Age4982x.WriteString "*SRE 128", True
Age4982x.WriteString "*CLS", True
Age4982x.WriteString "*OPC?", True
Buff = Age4982x.ReadString
'*** Triggering and data read
'* Prompts the user to press the [Trigger] key. The program waits until the user presses the [Trigger] key.
MsgBox "### PUSH THE TRIGGER KEY ###", vbOKOnly
'* Retrieves the measurement results and stores them into the Res array.
Age4982x.WriteString ":FETC?", True
Res() = Age4982x.ReadList(ASCIIType_R8, ",")
'*** Display results
'* Displays the title portions of the retrieved measurement results.
Open OutputFile For Output As Ofile
Print #Ofile, "### Result ###"
Print #Ofile, " No.", "Parameter"
For J = 1 To 7
If Stat(J) = 1 Then
Print #Ofile, J, Title(J)
End If
Next J
Print #Ofile, ""
Loc = 0
For i = Star_no To Stop_no '* Displays the measurement status and proceeds to the next data position.
Print #Ofile, "Point="; i, "Status="; Res(Loc)
Loc = Loc + 1
'* Displays the results for measurement parameters 1 through 4, test signal current/voltage level monitoring, and
'* Rdc measurement if the corresponding array element, Stat(*), is 1; then proceeds to the next data position.
For J = 1 To 7
If Stat(J) = 1 Then
Print #Ofile, "Parameter No="; J; " Result= "; Res(Loc)
Loc = Loc + 1
End If
Next J
Print #Ofile, ""
Next i
'If Bin_stat is 1 and bin sorting is on, the program displays the results of bin sorting.
If Bin_stat = 1 Then
Print #Ofile, "BIN Sort: " & Res(Loc)
End If
'* Close output file
Close #Ofile
MsgBox ("End of ""Retrieving Results Using :FETC?"" program"), vbOKOnly
End Sub