Setting the Limit Test Functions

Other topics about Processing Measurement Results

Overview

The program listed in the below section is written in VISA-COM with Excel VBA. It can be executed from the external PC controller. The program demonstrates how to set the limit test functions.

Setting the Limit Test Functions Sample Program in Excel VBA

Private Sub Measure_Click()

    Dim ioMgr As VisaComLib.ResourceManager

    Dim Ana As VisaComLib.FormattedIO488

    

    Dim Star As Double, Stp As Double

    Dim Param(1) As String, Fmt(1) As String, SwpFmt As String

    Dim NumofSeg(1) As Integer

    

    Dim LimTbl1 As LimitTbl1, LimTbl2 As LimitTbl2

    

    Dim Dummy As Integer, 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

    

   '*** The memory area of the resource manager and the instrument I/O are acquired.

    Set ioMgr = New VisaComLib.ResourceManager

    Set Ana = New VisaComLib.FormattedIO488

  

    '*** Open the instrument.

    Set Ana.IO = ioMgr.Open("GPIB0::17::INSTR")

    Ana.IO.timeout = 10000

    

    Ana.WriteString ":SYST:PRES", True

    Ana.WriteString ":SYST:BEEP:WARN:STAT OFF", True

 

    '* Clear Fail Point Data on the sheet.

    Range("E27:F100").Clear

    Range("C26:C28").ClearContents

 

    '* Set variable of measurement condition.

    Star = CDbl(Cells(3, 3).Value)

    Stp = CDbl(Cells(4, 3).Value)

    SwpFmt = Cells(5, 3).Value

    Param(0) = Trim(Cells(6, 3).Value)

    Fmt(0) = Trim(Cells(7, 3).Value)

    Param(1) = Trim(Cells(8, 3).Value)

    Fmt(1) = Trim(Cells(9, 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(13 + i, 3).Value) = "MAX" Then

                .Typ(i) = 1

            Else

                .Typ(i) = 2

            End If

            .BeginStim(i) = CDbl(Cells(13 + i, 4).Value)

            .EndStim(i) = CDbl(Cells(13 + i, 5).Value)

            .BeginResp(i) = CDbl(Cells(13 + i, 6).Value)

            .EndResp(i) = CDbl(Cells(13 + i, 7).Value)

        End With

    Next i

    '

    For i = 0 To NumofSeg(1) - 1

        With LimTbl2

            If Trim(Cells(20 + i, 3).Value) = "MAX" Then

                .Typ(i) = 1

            Else

                .Typ(i) = 2

            End If

            .BeginStim(i) = CDbl(Cells(20 + i, 4).Value)

            .EndStim(i) = CDbl(Cells(20 + i, 5).Value)

            .BeginResp(i) = CDbl(Cells(20 + i, 6).Value)

            .EndResp(i) = CDbl(Cells(20 + i, 7).Value)

        End With

    Next i

    '

    '*** Send measurement condition to the Ana

    Ana.WriteString ":SENS1:FREQ:STAR " + CStr(Star), True

    Ana.WriteString ":SENS1:FREQ:STOP " + CStr(Stp), True

    Ana.WriteString ":SENS1:SWE:TYPE " + SwpFmt, True

    Ana.WriteString ":CALC1:PAR1:COUN 2", True

    Ana.WriteString ":DISP:WIND1:SPL D1_2", True

    

    Ana.WriteString ":TRIG:SOUR BUS", True  ' Triger souce: bus

    Ana.WriteString ":INIT1:CONT ON", True  ' Triger mode: Continuos

    '

    '* Send measurement parameter and format of trace 1 to the Ana.

    Ana.WriteString ":CALC1:PAR1:SEL", True

    Ana.WriteString ":CALC1:PAR1:DEF " + Param(0), True

    Ana.WriteString ":DISP:WIND1:TRAC1:Y:SPAC " + Fmt(0), True   ' Set Y-Axis at Log format

 

    '* Send limit table of trace 1 to the Ana.

    Ana.WriteString ":CALC1:LIM:DATA " + CStr(NumofSeg(0)), False

    For i = 0 To NumofSeg(0) - 1

        With LimTbl1

            Ana.WriteString "," + CStr(.Typ(i)), False

            Ana.WriteString "," + CStr(.BeginStim(i)), False

            Ana.WriteString "," + CStr(.EndStim(i)), False

            Ana.WriteString "," + CStr(.BeginResp(i)), False

            If i = NumofSeg(0) - 1 Then

                Ana.WriteString "," + CStr(.EndResp(i)), True

            Else

                Ana.WriteString "," + CStr(.EndResp(i)), False

            End If

        End With

    Next i

    Ana.WriteString ":CALC1:LIM:DISP ON", True

    Ana.WriteString ":CALC1:LIM:DISP:CLIP OFF", True

    Ana.WriteString ":CALC1:LIM ON", True

    '

    '* Send measurement parameter and format of trace 2 to the Ana.

    Ana.WriteString ":CALC1:PAR2:SEL", True

    Ana.WriteString ":CALC1:PAR2:DEF " + Param(1), True

    Ana.WriteString ":DISP:WIND1:TRAC2:Y:SPAC " + Fmt(1)

    

    '* Send limit table of trace 2 to the Ana.

    Ana.WriteString ":CALC1:LIM:DATA " + CStr(NumofSeg(1)), False

    For i = 0 To NumofSeg(1) - 1

        With LimTbl2

            Ana.WriteString "," + CStr(.Typ(i)), False

            Ana.WriteString "," + CStr(.BeginStim(i)), False

            Ana.WriteString "," + CStr(.EndStim(i)), False

            Ana.WriteString "," + CStr(.BeginResp(i)), False

            If i = NumofSeg(1) - 1 Then

                Ana.WriteString "," + CStr(.EndResp(i)), True

            Else

                Ana.WriteString "," + CStr(.EndResp(i)), False

            End If

        End With

    Next i

    Ana.WriteString ":CALC1:LIM:DISP ON", True

    Ana.WriteString ":CALC1:LIM:DISP:CLIP OFF", True

    Ana.WriteString ":CALC1:LIM ON", True

    Ana.WriteString "*OPC?", True

    Dummy = Ana.ReadNumber

    '

    '*** Setting status resister.

    Ana.WriteString ":STAT:QUES:LIM:PTR 2", True

    Ana.WriteString ":STAT:QUES:LIM:NTR 0", True

    Ana.WriteString ":STAT:QUES:LIM:CHAN1:ENAB 6", True

    Ana.WriteString ":STAT:QUES:LIM:CHAN1:PTR 6", True

    Ana.WriteString ":STAT:QUES:LIM:CHAN1:NTR 0", True

 

    ' Clear status register

    Ana.WriteString "*CLS", True

  . ' Wait register clear end.

    Ana.WriteString "*OPC?", True

    Dummy = Ana.ReadNumber

    '

    '* Trigger

    ' Make a single trigger.

    Ana.WriteString ":TRIG:SING", True

    ' Wait measurement end.

    Ana.WriteString "*OPC?", True  

    Dummy = Ana.ReadNumber

    '

    '* Checking test results.

    Ana.WriteString ":STAT:QUES:LIM?", True

    ret = Ana.ReadNumber

    Lim_Judge = ret And 2

    Ana.WriteString ":STAT:QUES:LIM:CHAN1?", True

    ret = Ana.ReadNumber

    Tr1_Judge = ret And 2

    Tr2_Judge = ret And 4

    '

    '*** Displaying test results.

    If Lim_Judge = 0 Then

        Cells(26, 3).Value = "PASS"

    Else

        Cells(26, 3).Value = "FAIL"

    End If

    

    If Tr1_Judge = 0 Then

        Cells(27, 3).Value = "PASS"

    Else

        Cells(27, 3).Value = "FAIL"

        Ana.WriteString ":CALC1:PAR1:SEL", True

        Ana.WriteString ":CALC1:LIM:REP:POIN?", True

        Fail_Point = Ana.ReadNumber

        ReDim Fail_Data(Fail_Point - 1)

        ptr = VarPtr(Fail_Data(0))

        Ana.WriteString ":CALC1:LIM:REP?", True

        Fail_Data = Ana.ReadList(ASCIIType_R8, ",")

        For i = 0 To Fail_Point - 1

            Cells(27 + i, 5).Value = Fail_Data(i)

        Next i

    End If

 

    If Tr2_Judge = 0 Then

        Cells(28, 3).Value = "PASS"

    Else

        Cells(28, 3).Value = "FAIL"

        Ana.WriteString ":CALC1:PAR2:SEL", True

        Ana.WriteString ":CALC1:LIM:REP:POIN?", True

        Fail_Point2 = Ana.ReadNumber

        ReDim Fail_Data2(Fail_Point2 - 1)

        Ana.WriteString ":CALC1:LIM:REP?", True

        Fail_Data2 = Ana.ReadList(ASCIIType_R8, ",")

        For i = 0 To Fail_Point2 - 1

            Cells(27 + i, 6).Value = Fail_Data2(i)

        Next i

    End If

   

    Ana.IO.Close

    

End Sub