Other topics about Sample Programs
This sample program demonstrates how to perform limit tests.
The sample program creates a limit table as shown in the following two tables, turns on the Limit Test feature, performs one cycle of measurement, and then displays the test results.
Limit table of trace 1
No. |
Type |
Begin Stimulus |
End Stimulus |
Begin Response |
End Response |
1 |
MAX |
847.5 MHz |
905.0 MHz |
-55.0 dBm |
-55.0 dBm |
2 |
MIN |
935.0 MHz |
960.0 MHz |
-3.5 dBm |
-3.5 dBm |
3 |
MAX |
935.0 MHz |
960.0 MHz |
0 dBm |
0 dBm |
4 |
MAX |
980.0 MHz |
1047.5 MHz |
-25.0 dBm |
-25.0 dBm |
Limit table of trace 2
No. |
Type |
Begin Stimulus |
End Stimulus |
Begin Response |
End Response |
1 |
MAX |
847.5 MHz |
925.0 MHz |
0 dBm |
0 dBm |
2 |
MAX |
935.0 MHz |
960.0 MHz |
-9.5 dBm |
-9.5 dBm |
3 |
MAX |
970.0 MHz |
1047.5 MHz |
0 dBm |
0 dBm |
See Limit Test for this programming.
Example of excel sheet with limit test program
Private Sub Measure_Click()
Dim ioMgr As VisaComLib.ResourceManager
Dim Ena As VisaComLib.FormattedIO488
Dim Cent As Double, Span As Double
Dim Param(1) As String, Fmt(1) As String
Dim NumofSeg(1) As Integer
Dim LimTbl1 As LimitTbl1
Dim LimTbl2 As LimitTbl2
Dim Dummy As Integer
Dim ret As Integer
Dim Lim_Judge As Integer
Dim Tr1_Judge As Integer
Dim Tr2_Judge As Integer
Dim Fail_Point As Integer
Dim Fail_Data As Variant
Dim Fail_Point2 As Integer
Dim Fail_Data2 As Variant
'*** Open the instrument.
Set ioMgr = New VisaComLib.ResourceManager
Set Ena = New VisaComLib.FormattedIO488
'*** Open the instrument.
Set Ena.IO = ioMgr.Open("GPIB0::17::INSTR")
Ena.IO.timeout = 10000
Ena.WriteString ":SYST:PRES", True
'* Clear Fail Point Data on the sheet.
Range("E26:F100").Clear
'* Set variable of measurement condition.
Cent = CDbl(Cells(3, 3).Value)
Span = CDbl(Cells(4, 3).Value)
Param(0) = Trim(Cells(5, 3).Value)
Fmt(0) = Trim(Cells(6, 3).Value)
Param(1) = Trim(Cells(7, 3).Value)
Fmt(1) = Trim(Cells(8, 3).Value)
'
'* Set variable of limit tables.
NumofSeg(0) = 4
NumofSeg(1) = 3
'
For i = 0 To NumofSeg(0) - 1
With LimTbl1
If Trim(Cells(12 + i, 3).Value) = "MAX" Then
.Typ(i) = 1
Else
.Typ(i) = 2
End If
.BeginStim(i) = CDbl(Cells(12 + i, 4).Value)
.EndStim(i) = CDbl(Cells(12 + i, 5).Value)
.BeginResp(i) = CDbl(Cells(12 + i, 6).Value)
.EndResp(i) = CDbl(Cells(12 + i, 7).Value)
End With
Next i
'
For i = 0 To NumofSeg(1) - 1
With LimTbl2
If Trim(Cells(19 + i, 3).Value) = "MAX" Then
.Typ(i) = 1
Else
.Typ(i) = 2
End If
.BeginStim(i) = CDbl(Cells(19 + i, 4).Value)
.EndStim(i) = CDbl(Cells(19 + i, 5).Value)
.BeginResp(i) = CDbl(Cells(19 + i, 6).Value)
.EndResp(i) = CDbl(Cells(19 + i, 7).Value)
End With
Next i
'
'*** Send measurement condition to the ENA
Ena.WriteString ":SENS1:FREQ:CENT " + CStr(Cent), True
Ena.WriteString ":SENS1:FREQ:SPAN " + CStr(Span), True
Ena.WriteString ":CALC1:PAR1:COUN 2", True
Ena.WriteString ":DISP:WIND1:SPL D1_2", True
Ena.WriteString ":TRIG:SOUR BUS", True ' Triger souce: bus
Ena.WriteString ":INIT1:CONT ON", True ' Triger mode: Continuos
'
'* Send measurement parameter and format of trace 1 to the ENA.
Ena.WriteString ":CALC1:PAR1:SEL", True
Ena.WriteString ":CALC1:PAR1:DEF " + Param(0), True
Ena.WriteString ":CALC1:FORM " + Fmt(0), True
'
'* Send limit table of trace 1 to the ENA.
Ena.WriteString ":CALC1:LIM:DATA " + CStr(NumofSeg(0)), False
For i = 0 To NumofSeg(0) - 1
With LimTbl1
Ena.WriteString "," + CStr(.Typ(i)), False
Ena.WriteString "," + CStr(.BeginStim(i)), False
Ena.WriteString "," + CStr(.EndStim(i)), False
Ena.WriteString "," + CStr(.BeginResp(i)), False
If i = NumofSeg(0) - 1 Then
Ena.WriteString "," + CStr(.EndResp(i)), True
Else
Ena.WriteString "," + CStr(.EndResp(i)), False
End If
End With
Next i
Ena.WriteString ":CALC1:LIM:DISP ON", True
Ena.WriteString ":CALC1:LIM ON", True
'
'* Send measurement parameter and format of trace 2 to the ENA.
Ena.WriteString ":CALC1:PAR2:SEL", True
Ena.WriteString ":CALC1:PAR2:DEF " + Param(1), True
Ena.WriteString ":CALC1:FORM " + Fmt(1), True
'
'* Send limit table of trace 2 to the ENA.
Ena.WriteString ":CALC1:LIM:DATA " + CStr(NumofSeg(1)), False
For i = 0 To NumofSeg(1) - 1
With LimTbl2
Ena.WriteString "," + CStr(.Typ(i)), False
Ena.WriteString "," + CStr(.BeginStim(i)), False
Ena.WriteString "," + CStr(.EndStim(i)), False
Ena.WriteString "," + CStr(.BeginResp(i)), False
If i = NumofSeg(1) - 1 Then
Ena.WriteString "," + CStr(.EndResp(i)), True
Else
Ena.WriteString "," + CStr(.EndResp(i)), False
End If
End With
Next i
Ena.WriteString ":CALC1:LIM:DISP ON", True
Ena.WriteString ":CALC1:LIM ON", True
Ena.WriteString "*OPC?", True
Dummy = Ena.ReadNumber
'
'*** Setting status resister.
Ena.WriteString ":STAT:QUES:LIM:CHAN1:ENAB 6", True
Ena.WriteString ":STAT:QUES:LIM:CHAN1:PTR 6", True
Ena.WriteString ":STAT:QUES:LIM:CHAN1:NTR 0", True
Ena.WriteString ":STAT:QUES:LIM:PTR 2", True
Ena.WriteString ":STAT:QUES:LIM:NTR 0", True
Ena.WriteString "*CLS", True ' Clear status register.
Ena.WriteString "*OPC?", True ' Wait register clear end.
Dummy = Ena.ReadNumber
'
'* Trigger.
Ena.WriteString ":TRIG:SING", True ' Make a single trigger.
Ena.WriteString "*OPC?", True ' Wait measurement end.
Dummy = Ena.ReadNumber
'
'* Checking test results.
Ena.WriteString ":STAT:QUES:LIM?", True
ret = Ena.ReadNumber
Lim_Judge = ret And 2
Ena.WriteString ":STAT:QUES:LIM:CHAN1?", True
ret = Ena.ReadNumber
Tr1_Judge = ret And 2
Tr2_Judge = ret And 4
'
'*** Displaying test results.
If Lim_Judge = 0 Then
Cells(25, 3).Value = "PASS"
Else
Cells(25, 3).Value = "FAIL"
If Tr1_Judge = 0 Then
Cells(26, 3).Value = "PASS"
Else
Cells(26, 3).Value = "FAIL"
Ena.WriteString ":CALC1:PAR1:SEL", True
Ena.WriteString ":CALC1:LIM:REP:POIN?", True
Fail_Point = Ena.ReadNumber
ReDim Fail_Data(Fail_Point - 1)
ptr = VarPtr(Fail_Data(0))
Ena.WriteString ":CALC1:LIM:REP?", True
Fail_Data = Ena.ReadList(ASCIIType_R8, ",")
For i = 0 To Fail_Point - 1
Cells(26 + i, 5).Value = Fail_Data(i)
Next i
End If
If Tr2_Judge = 0 Then
Cells(27, 3).Value = "PASS"
Else
Cells(27, 3).Value = "FAIL"
Ena.WriteString ":CALC1:PAR2:SEL", True
Ena.WriteString ":CALC1:LIM:REP:POIN?", True
Fail_Point2 = Ena.ReadNumber
ReDim Fail_Data2(Fail_Point2 - 1)
Ena.WriteString ":CALC1:LIM:REP?", True
Fail_Data2 = Ena.ReadList(ASCIIType_R8, ",")
For i = 0 To Fail_Point2 - 1
Cells(26 + i, 6).Value = Fail_Data2(i)
Next i
End If
End If
Ena.IO.Close
End Sub