Other topics about Controlling E5061B
This section describes how to process the E5061B's internal data. You can use these internal data arrays: corrected data arrays, corrected memory arrays, formatted data arrays, formatted memory arrays, and stimulus data arrays. For more information on the internal data arrays, see Internal Data Processing.
To read/write a formatted data array, formatted memory array, corrected data array, or corrected memory array use the following objects:
To read a stimulus data array, use the following objects:
The E5061B VBA allows you to deal with multiple pieces of data through variables of Variant type. Variant variables can contain any type of data, allowing you to deal with array data without being aware of the number of elements. For example, a formatted data array that includes 5 measurement points is stored as shown in the following figure. Note that a formatted data array always contains 2 data items per measurement point, whichever data format is used. For more information on contained data, see Internal Data Processing. you can find a table that describes the relationship between contained data items and data formats.
Example storing data into a Variant variable
When you use one of the objects listed above, the base index number of the array is always 0 even if the declaration section contains the "Option Base 1" statement, which specifies the use of the base array index of 1.
For example, you may wish to read the formatted data array for a particular trace in its entirety (including all measurement points), display the data in the echo window, and then write the data into another trace. How to implement such a process can be better understood with the aid of a sample program.
Sample program is available for download from the Keysight Support page, named "read_write.vba", that demonstrates how to read and write measurement data. This VBA program consists of the following modules:
Object name |
Module type |
Content |
frmReadWrite |
UserForm |
Reads, displays, and writes a formatted data array. |
mdlReadWrite |
Standard module |
Invokes a UserForm. |
This sample program runs correctly when the maximum number of chanĀnels/traces is set to 4 channels/4 traces.
When you run this VBA program, a following window appears.
UserForm of read_write.vba program
The program lets the user specify the channel to be controlled.
The program lets the user specify which trace's formatted data array to read (source trace).
The program reads the formatted data array for the trace specified by the user, display the measurement results in the echo window, and write the data into the trace specified by the user. For detail, see the description of the code window.
The program lets the user specify which trace's formatted data array to overwrite (target trace).
The program exits, and the window disappears.
In Visual Basic Editor, open the UserForm (object name: frmReadWrite), and double-click the entire UserForm or the Copy -> or Exit button to bring up the code window. The following is the description of the subprograms associated with the respective buttons.
Reading/displaying/writing a formatted data array (read_write.frm)
''''
' Procedure called when the user clicks the Copy button on the UserForm.
''''
'
Private Sub cmdCopy_Click()
Dim X As Integer, Y As Integer, Z As Integer, I As Integer
Dim ActCh As Long, TrGet As Long, TrPut As Long
Dim TrCont As Long, Nop As Long
Dim FmtData As Variant, Freq As Variant
Dim Fmt As String
'
' These lines identify the selected items in each list and store them into
' the variables TrGet, TrPut, and ActCh.
'
X = cboCh.ListIndex
ActCh = X + 1
Y = cboGet.ListIndex
TrGet = Y + 1
Z = cboPut.ListIndex
TrPut = Z + 1
'
' If the specified target trace is not displayed, these lines display that trace.
'
TrCont = SCPI.CALCulate(ActCh).PARameter.Count
If TrCont < TrPut Then
SCPI.CALCulate(ActCh).PARameter.Count = TrPut
End If
'
' These lines make active the specified trace (TrGet: source trace) in
' the specified channel(ActCh) and hold the sweep.
'
SCPI.CALCulate(ActCh).PARameter(TrGet).SELect
SCPI.INITiate(ActCh).CONTinuous = False
SCPI.ABORt
'
' Reads the number of measurement points for the specified channel (ActCh)
' and stores that number into the Nop variable.
'
Nop = SCPI.SENSe(ActCh).SWEep.POINts
'
' Reads the formatted data array for the active trace (source trace)
' and store the data into the FmtData variable.
'
FmtData = SCPI.CALCulate(ActCh).SELected.Data.FDATa
'
' Reads the stimulus array for the specified channel (ActCh)
' and stores the data into the Freq variable.
'
Freq = SCPI.SENSe(ActCh).FREQuency.Data
'
' Reads the data format for the active trace (source trace) and
' store it into the Fmt variable.
'
Fmt = SCPI.CALCulate(ActCh).SELected.Format
'
' These lines display the echo window in the lower part of
' the LCD screen.
'
SCPI.DISPlay.TABLe.TYPE = "ECHO"
SCPI.DISPlay.TABLe.STATe = True
'
' The lines display, in the echo window, each point along with
' one measured value (the odd part of the index is always 0) and
' a frequency if the Fmt is "MLOG", "PHAS", "GDEL", "MLIN", "SWR", "REAL",
' "IMAG", or "UPH"; or along with two measured values and a frequency
' if Fmt returns any other string.
'
Select Case Fmt
Case "MLOG", "PHAS", "GDEL", "MLIN", "SWR", "REAL", "IMAG", "UPH"
ECHO "Nop", "Frequency(GHz)", "Data"
For I = 0 To Nop - 1
ECHO I + 1, Freq(I) / 1000000000#, FmtData(2 * I)
Next I
Case Else
ECHO "Nop", "Frequency(GHz)", "Data1", "Data2"
For I = 0 To Nop - 1
ECHO I + 1, Freq(I) / 1000000000#, FmtData(2 * I), FmtData(2 * I + 1)
Next I
End Select
'
' Makes active the specified trace (TrPut: target trace) in the specified
' channel(ActCh).
'
SCPI.CALCulate(ActCh).PARameter(TrPut).SELect
'
' Writes the formatted data array (FmtData) into the active trace (target trace).
'
SCPI.CALCulate(ActCh).SELected.Data.FDATa = FmtData
'
End Sub
'
'
''''
' Procedure called when the user clicks the Exit button on the UserForm.
''''
Private Sub cmdExit_Click()
'
' Unloads the UserForm from the memory, and terminates the program.
'
Unload Me
'
End Sub
'
'
''''
' Procedure that initializes the UserForm
''''
Private Sub UserForm_Initialize()
'
' When the program is launched, these lines add each list item and set the default value
' for each list.
'
With cboCh
.AddItem "CH1"
.AddItem "CH2"
.AddItem "CH3"
.AddItem "CH4"
End With
'
With cboGet
.AddItem "Trace 1"
.AddItem "Trace 2"
.AddItem "Trace 3"
.AddItem "Trace 4"
End With
'
With cboPut
.AddItem "Trace 1"
.AddItem "Trace 2"
.AddItem "Trace 3"
.AddItem "Trace 4"
End With
'
cboCh.ListIndex = 0
cboGet.ListIndex = 0
cboPut.ListIndex = 0
'
End Sub