Upload and Download a Segment List
This VBScript program creates two segments, then uploads the segment data to the PNA.
The second part downloads the segment list from the PNA.
The SCPI commands in this example are sent over a COM interface using the SCPIStringParser object. You do NOT need a GPIB connection to run this example.
This VBScript (*.vbs) program can be run as a macro in the PNA. To do this, copy the following code into a text editor file such as Notepad and save it on the PNA hard drive as Unguided.vbs. Learn how to setup and run the macro.
See all Segment SCPI commands.
Create and Upload a Segment List
Option Explicit Dim app Set app = CreateObject("AgilentPNA835x.Application") ' Preset the PNA app.Preset Dim scpi Set scpi = app.ScpiStringParser ' In case of a measurement receiver PNA like N5264A ' which has no source ports, "SOURce:CATalog?" will ' return an empty list (just a pair of quotation marks) Dim srcPortNames srcPortNames = Split( scpi.Execute("SOURce:CATalog?"), ",") Dim numberOfSrcPorts If Left( srcPortNames(0), 2 ) = Chr(34) & Chr(34) Then numberOfSrcPorts = 0 Else numberOfSrcPorts = UBound(srcPortNames) + 1 End If ' Building up a string consisting of the sweep segment data ' we want to set up. This example will create two segments. Dim segData ' Set state of first segment to be ON (1 = ON, 0 = OFF), ' 101 points, start freq of 10 MHz, stop freq of 1 GHz segData = "1,101,10E6,1E9" ' If you want to include one or more of: IFbandwidth, Dwell Time ' or Port Power, remove the comments from these next two lines 'TurnOnOptions 1 'Call the subroutine 'segData = AddOptionalSettings(segData, numberOfSrcPorts) ' Set state of second segment to be ON, 201 points, ' start freq of 1 GHz, stop freq of 3 GHz segData = segData & ",1,201,1E9,3E9" ' Uncomment this line below only if you uncommented the ' AddOptionalSettings line above for the first segment. 'segData = AddOptionalSettings(segData, numberOfSrcPorts) Const numSegs = 2 ' Upload our segment list to the channel scpi.Execute "SENSe1:SEGMent:LIST SSTOP," & numSegs & "," & segData ' Set segment sweep type on Channel 1 scpi.Execute "SENSe1:SWEep:TYPE SEGment" ' Having the PNA display the segment sweep table for the channel scpi.Execute "DISPlay:WINDow1:TABLe SEGMent" Sub TurnOnOptions(ByVal chan) scpi.Execute "SENSe"&chan&":SEGMent:BWIDth:CONTrol ON" scpi.Execute "SENSe"&chan&":SEGMent:SWEep:TIME:CONTrol ON" scpi.Execute "SENSe"&chan&":SEGMent:POWer:CONTrol ON" ' Turning off coupling allows power to vary per each port scpi.Execute "SOURce"&chan&":POWer:COUPle OFF" End Sub Function AddOptionalSettings(ByVal inStr, ByVal numSrcPorts) ' Specifying 1 kHz IF bandwidth and Dwell Time of 0 inStr = inStr & ",1E3,0" ' -10 dBm power for each of the source ports Dim i For i = 0 To numSrcPorts - 1 inStr = inStr & ",-10" Next AddOptionalSettings = inStr End Function |
Download a Segment List
This example assumes that the active trace is in Window 1
Option Explicit Dim app Set app = CreateObject("AgilentPNA835x.Application") Dim scpi Set scpi = app.ScpiStringParser ' Set the display-active channel's sweep type to segment sweep ' (if the PNA's currently active measurement window doesn't ' contain any traces, this querying for active channel will ' result in a SCPI error which scpi.Parse will trap and throw) Dim chan chan = CLng( scpi.Parse("SYSTem:ACTive:CHANnel?") ) scpi.Execute "SENSe"&chan&":SWEep:TYPE SEGment" ' Having the PNA display the segment sweep table for the channel scpi.Execute "DISPlay:WINDow1:TABLe SEGMent" ' Get the total number of segments Dim numSegs numSegs = CLng( scpi.Execute("SENSe"&chan&":SEGMent:COUNt?") ) ' Read the segment listing Dim segDataStr segDataStr = scpi.Execute("SENSe"&chan&":SEGMent:LIST?") Dim segData segData = Split(segDataStr, ",") ' Get upper bound of the array of data values ' (lower bound of array resulting from VB 'Split' function is 0) Dim segArrayUB segArrayUB = UBound(segData) Dim numDataElementsPerSeg numDataElementsPerSeg = (segArrayUB + 1) / numSegs WScript.Echo "Number of segments = " & numSegs WScript.Echo "Number of data values per segment = " & numDataElementsPerSeg Dim segInfStr segInfStr = "Segment 1: state = " & CBool(segData(0)) segInfStr = segInfStr & ", num points = " & CLng(segData(1)) segInfStr = segInfStr & ", start freq = " & CDbl(segData(2)) segInfStr = segInfStr & ", stop freq = " & CDbl(segData(3)) segInfStr = segInfStr & ", IFBW = " & CDbl(segData(4)) segInfStr = segInfStr & ", dwell time = " & CDbl(segData(5)) ' In case of a measurement receiver PNA like N5264A ' which has no source ports, "SOURce:CATalog?" will ' return an empty list Dim srcPortNames srcPortNames = Split( scpi.Execute("SOURce"&chan&":CATalog?"), ",") Dim srcPortNamesUB srcPortNamesUB = UBound(srcPortNames) ' First source port name will be preceded by a quotation mark ' and the last name will be followed by one of those, so stripping ' those off now. srcPortNames(0) = Right( srcPortNames(0), Len(srcPortNames(0)) - 1 ) srcPortNames(srcPortNamesUB) = Left( srcPortNames(srcPortNamesUB), InStrRev(srcPortNames(srcPortNamesUB), Chr(34)) - 1 ) Dim firstPortIndex firstPortIndex = 6 Dim lastPortIndex lastPortIndex = numDataElementsPerSeg - 1 Dim j For j = firstPortIndex To lastPortIndex segInfStr = segInfStr & ", " & srcPortNames(j - firstPortIndex) & " power = " & CDbl(segData(j)) Next WScript.Echo segInfStr |