Calibration

Other topics about Sample Programs

Overview

The sample program performs calibration with the specified calibration type.

See Calibration for this programming.

Sample Program in Excel VBA using VISA

Sub Calibration()

    Dim defrm As Long           'Session to Default Resource Manager

    Dim vi As Long              'Session to instrument

    Dim Ch As String

    Dim CalKit As Integer

    Dim Port(2) As String

    

    Const TimeOutTime = 40000   'timeout time.

    Const Cal85032F = 4         'cal kit number.

    

    Ch = Cells(5, 5)            'Select channel

    Port(1) = Cells(3, 6)       'Sets the select port 1.

    Port(2) = Cells(3, 7)       'Sets the select port 2.

    CalKit = Cal85032F          'Sets cal kit (85032F)

        

    Call viOpenDefaultRM(defrm)    'Initializes the VISA system.

    Call viOpen(defrm, "GPIB0::17::INSTR", 0, 0, vi)    'Opens the session to the specified instrument.

    Call viSetAttribute(vi, VI_ATTR_TMO_VALUE, TimeOutTime)   'The state of an attribute for the specified session.

    

    Call viVPrintf(vi, "*RST" & vbLf, 0)   'Presets the setting state of the ENA.

    Call viVPrintf(vi, "*CLS" & vbLf, 0)   'Clears the all status register.

    

    Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:CKIT " & CalKit & vbLf, 0)  'Select the calibration kit

    

    Select Case Cells(3, 5)

        Case "Response (Open)"   'Perform response calibration (OPEN).

            Call Cal_Resp(vi, Ch, "OPEN", Port(1))

        Case "Response (Short)"   'Perform response calibration (SHORT).

            Call Cal_Resp(vi, Ch, "Short", Port(1))

        Case "Response (Thru)"    'Perform response calibration (Thru).

            Call Cal_RespThru(vi, Ch, "Thru", Port(1), Port(2))

        Case "Full 1 Port"    'Perform 1-port calibration.

            Call Cal_Slot(vi, Ch, 1, Port)

        Case "Full 2 Port"     'Perform full 2-port calibration.

            Call Cal_Slot(vi, Ch, 2, Port)

   End Select

    

    Call viClose(vi)  'Closes the resource manager session.

    Call viClose(defrm)  'Breaks the communication and terminates the VISA system.

    

    End                                                                             'End

End Sub

 

Sub Cal_Resp(vi As Long, Ch As String, CalType As String, Port As String)

    Dim Dummy As Variant   'Variant to receive the result

    

    Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:METH:" & CalType & " " & Port & vbLf, 0)  'Sets the calibration type.

    

    MsgBox ("Set " & CalType & " to Port " & Port & ". then click [OK] button")  'Display the message box.

    

    Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:" & CalType & " " & Port & vbLf, 0) 'Measurement the calibration data.

    Call viVQueryf(vi, "*OPC?" & vbLf, "%t", Dummy)    'Reads the *OPC? result.

    Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:SAVE" & vbLf, 0)      'Calculating the calibration coefficients.

    

    Call ErrorCheck(vi)      'Checking the error.

    

End Sub

 

Sub Cal_RespThru(vi As Long, Ch As String, CalType As String, Port1 As String, Port2 As String)

    Dim Dummy As Variant   'Variant to receive the result.

    

    If Port1 <> Port2 Then

        Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:METH:" & CalType & " " & Port1 & "," & Port2 & vbLf, 0)   'Sets the calibration type

    

        MsgBox ("Set " & CalType & " to Port " & Port1 & "&" & Port2 & ". then click [OK] button")   'Display the message box.

    

        Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:" & CalType & " " & Port1 & "," & Port2 & vbLf, 0)  'Measurement the calibration data.

        Call viVQueryf(vi, "*OPC?" & vbLf, "%t", Dummy)      'Reads the *OPC? result.

        Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:SAVE" & vbLf, 0)     'Calculating the calibration coefficients.

        

        Call ErrorCheck(vi)     'Checking the error.

    Else

        MsgBox ("Thru calibration select port error!")   'Displaying the error message when selected same ports.

        Exit Sub

    End If

    

End Sub

Sub Cal_Slot(vi As Long, Ch As String, NumPort As String, Port() As String)

    Dim Dummy

    Dim i As Integer, j As Integer

    

    Select Case NumPort

        Case 1

            Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:METH:SOLT" & NumPort & " " & Port(1) & vbLf, 0)   'Set the 1-port calibration type.

        Case 2

            Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:METH:SOLT" & NumPort & " " & Port(1) & "," & Port(2) & vbLf, 0)   'Set the full 2-port calibration type.

  End Select

    'Reflection

    For i = 1 To NumPort

        MsgBox ("Set Open to Port " & Port(i) & ". then click [OK] button")   'Display the message box.

        Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:OPEN " & Port(i) & vbLf, 0)    'Measurement the OPEN calibration.

        Call viVQueryf(vi, "*OPC?" & vbLf, "%t", Dummy)    'Reads the *OPC? result.

        

        MsgBox ("Set Short to Port " & Port(i) & ". then click [OK] button")    'Display the message box.

        Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:SHORT " & Port(i) & vbLf, 0)  'Measurement the SHORT calibration.

        Call viVQueryf(vi, "*OPC?" & vbLf, "%t", Dummy)    'Reads the *OPC? result.

        

        MsgBox ("Set Load to Port " & Port(i) & ". then click [OK] button")   'Display the message box.

        Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:LOAD " & Port(i) & vbLf, 0)    'Measurement the LOAD calibration.

        Call viVQueryf(vi, "*OPC?" & vbLf, "%t", Dummy)     'Reads the *OPC? result.

    Next i

    'Transmission

    For i = 1 To NumPort - 1

        For j = i + 1 To NumPort

            MsgBox ("Set Thru to Port " & Port(i) & "&" & Port(j) & ". then click [OK] button")   'Display the message box.

            Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:THRU " & Port(i) & "," & Port(j) & vbLf, 0)    'Measurement the THRU calibration.

            Call viVQueryf(vi, "*OPC?" & vbLf, "%t", Dummy)    'Reads the *OPC result.

            Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:THRU " & Port(j) & "," & Port(i) & vbLf, 0)    'Measurement the THRU calibration.

            Call viVQueryf(vi, "*OPC?" & vbLf, "%t", Dummy)    'Reads the *OPC result.

        Next j

    Next i

    Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:SAVE" & vbLf, 0)  'Calculating the calibration coefficients.

    

    Call ErrorCheck(vi)    'Checking the error.

    

End Sub

Sub ErrorCheck(vi As Long)

    Dim err As String * 50, ErrNo As Variant, Response

    

    Call viVQueryf(vi, ":SYST:ERR?" & vbLf, "%t", err)    'Reads error message.

    ErrNo = Split(err, ",")    'Gets the error code.

    

    If Val(ErrNo(0)) <> 0 Then

        Response = MsgBox(CStr(ErrNo(1)), vbOKOnly)    'Display the message box.

    End If

End Sub

Sample Program in Excel VBA using VISA-COM

 '*** The variables of the resource manager and the instrument I/O are declared

    Dim ioMgr As VisaComLib.ResourceManager

    Dim age507x As VisaComLib.FormattedIO488

    

Sub Calibration()

 

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

    Set ioMgr = New VisaComLib.ResourceManager

    Set age507x = New VisaComLib.FormattedIO488

    '*** Open the instrument

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

    age507x.IO.timeout = 30000

    

    Dim Ch As String

    Dim CalKit As Integer

    Dim Port(2) As String

    

    Const Cal85033E = 4         'cal kit number.

    

    Ch = Cells(5, 5)            'Select channel

    Port(1) = Cells(3, 6)       'Sets the select port 1.

    Port(2) = Cells(3, 7)       'Sets the select port 2.

    CalKit = Cal85033E          'Sets cal kit (85032F)

        

    ' Presets the setting state & clears all the status register

    age507x.WriteString "*RST" & vbLf, True

    age507x.WriteString "*CLS" & vbLf, True

    

    'Select the calibration kit

    age507x.WriteString ":SENS" & Ch & ":CORR:COLL:CKIT " & CalKit & vbLf, True

    

    Select Case Cells(3, 5)

        Case "Response (Open)"   'Perform response calibration (OPEN)

            Call Cal_Resp(Ch, "OPEN", Port(1))

        Case "Response (Short)"    'Perform response calibration (SHORT)

            Call Cal_Resp(Ch, "SHORT", Port(1))

        Case "Response (Thru)"    'Perform response calibration (Thru)

            Call Cal_RespThru(Ch, "Thru", Port(1), Port(2))

        Case "Full 1 Port"    'Perform 1-port calibration

            Call Cal_Slot(Ch, "1", Port)

        Case "Full 2 Port"   'Perform full 2-port calibration

            Call Cal_Slot(Ch, "2", Port)

    End Select

    

     ' End of Procedure. Closes the resource manager session.

    age507x.IO.Close

End Sub

Sub Cal_Resp(Ch As String, CalType As String, Port As String)

Dim Dummy As Variant ' variant to receive the result

age507x.WriteString ":SENS" & Ch & ":CORR:COLL:METH:" & CalType & " " & Port & vbLf, True 'Set the calibration type

MsgBox "Set " & CalType & " to Port " & Port & ". Then click [OK] button" 'Display the message box

age507x.WriteString ":SENS" & Ch & ":CORR:COLL:" & CalType & " " & Port & vbLf, True 'Measuring calibration data

age507x.WriteString "*OPC?" & vbLf, True 'Reads the *OPC? result

Dummy = age507x.ReadString

age507x.WriteString ":SENS" & Ch & ":CORR:COLL:SAVE" & vbLf, True 'Calculating the calibration coefficients

Call ErrorCheck   'Checking the error.

End Sub

 

Sub Cal_RespThru(Ch As String, CalType As String, Port1 As String, Port2 As String)

    Dim Dummy As Variant   'Variant to receive the result.

    

    If Port1 <> Port2 Then

        age507x.WriteString ":SENS" & Ch & ":CORR:COLL:METH:" & CalType & " " & Port1 & "," & Port2 & vbLf, True  'Sets the calibration type

  

        MsgBox ("Set " & CalType & " to Port " & Port1 & "&" & Port2 & ". then click [OK] button")   'Display the message box.

          

        age507x.WriteString ":SENS" & Ch & ":CORR:COLL:" & CalType & " " & Port & vbLf, True    'Measuring the calibration data.

        age507x.WriteString "*OPC?" & vbLf, True 'Reads the *OPC? result

        Dummy = age507x.ReadString

        age507x.WriteString ":SENS" & Ch & ":CORR:COLL:SAVE" & vbLf, True 'Calculating the calibration coeeficients

    

        Call ErrorCheck    'Checking the error

    Else

        MsgBox ("Thru calibration select port error!")   'Displaying the error message when selected same ports.

        Exit Sub

    End If

    

End Sub

Sub Cal_Slot(Ch As String, NumPort As String, Port() As String)

    Dim Dummy As Variant

    Dim i As Integer, j As Integer

    

    Select Case NumPort

        Case 1

            Age507x.WriteString ":SENS" & Ch & ":CORR:COLL:METH:SOLT" & NumPort & " " & Port(1) & vbLf, True      'Set the 1-port calibration type

        Case 2

            age507x.WriteString ":SENS" & Ch & ":CORR:COLL:METH:SOLT" & NumPort & " " & Port(1) & "," & Port(2) & vbLf, True    'Set the full 2-port calibration type

    End Select

    'Reflection

    For i = 1 To NumPort

        MsgBox ("Set Open to Port " & Port(i) & ". then click [OK] button")   'Display the message box.

        age507x.WriteString ":SENS" & Ch & ":CORR:COLL:OPEN " & Port(i) & vbLf, True   'Measurement the OPEN calibration.

        age507x.WriteString "*OPC?" & vbLf, True 'Reads the *OPC? result

        Dummy = age507x.ReadString

                

        MsgBox ("Set Short to Port " & Port(i) & ". then click [OK] button")    'Display the message box.

        age507x.WriteString ":SENS" & Ch & ":CORR:COLL:SHORT " & Port(i) & vbLf, True   'Measurement the SHORT calibration.

        age507x.WriteString "*OPC?" & vbLf, True 'Reads the *OPC? result

        Dummy = age507x.ReadString

        

        MsgBox ("Set Load to Port " & Port(i) & ". then click [OK] button")   'Display the message box.

        age507x.WriteString ":SENS" & Ch & ":CORR:COLL:LOAD " & Port(i) & vbLf, True   'Measurement the LOAD calibration.

        age507x.WriteString "*OPC?" & vbLf, True 'Reads the *OPC? result

        Dummy = age507x.ReadString

    Next i

    'Transmission

    For i = 1 To NumPort - 1

        For j = i + 1 To NumPort

            MsgBox ("Set Thru to Port " & Port(i) & "&" & Port(j) & ". then click [OK] button")   'Display the message box.

            age507x.WriteString ":SENS" & Ch & ":CORR:COLL:THRU " & Port(i) & "," & Port(j) & vbLf, True  'Measurement the THRU calibration.

            age507x.WriteString "*OPC?" & vbLf, True 'Reads the *OPC? result

            Dummy = age507x.ReadString

            age507x.WriteString ":SENS" & Ch & ":CORR:COLL:THRU " & Port(j) & "," & Port(i) & vbLf, True  'Measurement the THRU calibration.

            age507x.WriteString "*OPC?" & vbLf, True 'Reads the *OPC? result

            Dummy = age507x.ReadString

        Next j

    Next i

    age507x.WriteString ":SENS" & Ch & ":CORR:COLL:SAVE" & vbLf, True   'Calculating the calibration coeeficients

    

    Call ErrorCheck      'Checking the error.

    

End Sub

Sub ErrorCheck()

    Dim err As String * 50, ErrNo As Variant, Response

    

    age507x.WriteString ":SYST:ERR?"   'Reads error message

    err = age507x.ReadString

    ErrNo = Split(err, ",")    'Gets the error code.

    

    If Val(ErrNo(0)) <> 0 Then

        Response = MsgBox(CStr(ErrNo(1)), vbOKOnly)    'Display the message box.

    End If

End Sub

Sample Program in HT Basic (cal.htb)

10 DIM File$[20],Ch$[9],Inp_char$[9]

20 INTEGER Cal_kit,Cal_type,Port(1:2)

30 !

40 ASSIGN @Agte507x TO 717

50 File$="Ex_4_1.sta"

60 Ch$="1"

70 !

80 Select_cal_kit(@Agte507x,Ch$)

90 !

100 CLEAR SCREEN

110 ON ERROR GOTO Type_select

120 Type_select: !

130 PRINT "## Calibration Type Selection ##"

140 PRINT " 1: Response (Open)"

150 PRINT " 2: Response (Short)"

160 PRINT " 3: Response (Thru)"

170 PRINT " 4: Full 1 Port"

180 PRINT " 5: Full 2 Port"

190 PRINT ""

200 PRINT "Input 1 to 7"

210 INPUT "Input number? (1 to 7)",Inp_char$

220 Cal_type=IVAL(Inp_char$,10)

230 IF Cal_type<1 OR Cal_type>7 THEN Type_select

240 OFF ERROR

250 !

260 SELECT Cal_type

270 CASE 1

280 Select_port(1,Port(*))

290 Cal_resp(@Agte507x,Ch$,"OPEN",Port(1))

300 CASE 2

310 Select_port(1,Port(*))

320 Cal_resp(@Agte507x,Ch$,"SHOR",Port(1))

330 CASE 3

340 Select_port(2,Port(*))

350 Cal_resp_thru(@Agte507x,Ch$,Port(1),Port(2))

360 CASE 4

370 Select_port(1,Port(*))

380 Cal_solt(@Agte507x,Ch$,1,Port(*))

390 CASE 5

400 Select_port(2,Port(*))

410 Cal_solt(@Agte507x,Ch$,2,Port(*))

420 END SELECT

430 !

440 OUTPUT @Agte507x;":MMEM:STOR:STYP CST"

450 OUTPUT @Agte507x;":MMEM:STOR """&File$&""""

460 END

470 !=============================================

480 ! Calibration Kit Selection Function

490 !=============================================

500 SUB Select_cal_kit(@Agte507x,Ch$)

510 DIM Cal_kit_lbl$(1:10)[20],Inp_char$[9]

520 INTEGER Cal_kit,I

530 CLEAR SCREEN

540 !

550 FOR I=1 TO 10

560 OUTPUT @Agte507x;":SENS1:CORR:COLL:CKIT ";I

570 OUTPUT @Agte507x;":SENS1:CORR:COLL:CKIT:LAB?"

580 ENTER @Agte507x;Cal_kit_lbl$(I)

590 NEXT I

600 ON ERROR GOTO Kit_select

610 Kit_select: !

620 PRINT "## Calibration Kit Selection ##"

630 FOR I=1 TO 10

640 PRINT USING "X,2D,A,X,20A";I,":",Cal_kit_lbl$(I)

650 NEXT I

660 PRINT ""

670 PRINT "Input 1 to 10"

680 INPUT "Input number? (1 to 10)",Inp_char$

690 Cal_kit=IVAL(Inp_char$,10)

700 IF Cal_kit<1 OR Cal_kit>10 THEN Kit_select

710 OFF ERROR

720 !

730 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:CKIT ";Cal_kit

740 SUBEND

750 !=============================================

760 ! Port Selection Function

770 !=============================================

780 SUB Select_port(INTEGER Num_of_ports,INTEGER Port(*))

790 DIM Inp_char$[9]

800 !

810 CLEAR SCREEN

820IF Num_of_ports=2 THEN

830 Port(1)=1

840 Port(2)=2

850 ELSE

860 PRINT "## Test Ports Selection ##"

870 ON ERROR GOTO Port_select

880 FOR I=1 TO Num_of_ports

890 PRINT "Port("&VAL$(I)&"):";

900 Port_select:!

910 INPUT "Number?",Inp_char$

920 Port(I)=IVAL(Inp_char$,10)

930 IF Port(I)<1 OR Port(I)>2 THEN Port_select

940 FOR J=1 TO I-1

950 IF Port(I)=Port(J) THEN Port_select

960 NEXT J

970 PRINT Port(I)

980 NEXT I

990 OFF ERROR

1000 END IF

1010 SUBEND

1020 !=============================================

1030 ! Response (Open/Short) Calibration Function

1040 !=============================================

1050 SUB Cal_resp(@Agte507x,Ch$,Type$,INTEGER Port)

1060 DIM Buff$[9]

1070 !

1080 PRINT "## Response ("&Type$&") Calibration ##"

1090 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:METH:"&Type$&" ";Port

1100 PRINT "Set "&Type$&" to Port "&VAL$(Port)&". Then push [Enter] key."

1110 INPUT "",Buff$

1120 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:"&Type$&" ";Port

1130 OUTPUT @Agte507x;"*OPC?"

1140 ENTER @Agte507x;Buff$

1150 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:SAVE"

1160 PRINT "Done"

1170 SUBEND

1180 !=============================================

1190 ! Response (Thru) Calibration Function

1200 !=============================================

1210 SUB Cal_resp_thru(@Agte507x,Ch$,INTEGER Port1,Port2)

1220 DIM Buff$[9]

1230 !

1240 PRINT "## Response (Thru) Calibration ##"

1250 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:METH:THRU ";Port1;","; Port2

1260 PRINT "Set THRU between Port "&VAL$(Port1)&" and Port "&VAL$(Port2 )&". Then push [Enter] key."

1270 INPUT "",Buff$

1280 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:THRU ";Port1;",";Port2

1290 OUTPUT @Agte507x;"*OPC?"

1300 ENTER @Agte507x;Buff$

1310 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:SAVE"

1320 PRINT "Done"

1330 SUBEND

1340 !=============================================

1350 ! Full n Port Calibration Function

1360 !=============================================

1370 SUB Cal_solt(@Agte507x,Ch$,INTEGER Num_of_ports,INTEGER Port(*))

1380 DIM Buff$[9]

1390 INTEGER I,J

1400 !

1410 PRINT "## Full "&VAL$(Num_of_ports)&" Port Calibration ##"

1420 !

1430 ! Calibration Type Selection

1440 !

1450 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:METH:SOLT"&VAL$(Num_of_ ports)&" ";

1460 FOR I=1 TO Num_of_ports-1

1470 OUTPUT @Agte507x;Port(I);",";

1480 NEXT I

1490 OUTPUT @Agte507x;Port(Num_of_ports)

1500 !

1510 ! Reflection Measurement

1520 !

1530 FOR I=1 TO Num_of_ports

1540 PRINT "Set OPEN to Port "&VAL$(Port(I))&". Then push [Enter] key."

1550 INPUT "",Buff$

1560 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:OPEN ";Port(I)

1570 OUTPUT @Agte507x;"*OPC?"

1580 ENTER @Agte507x;Buff$

1590 PRINT "Set SHORT to Port "&VAL$(Port(I))&". Then push [Enter] key."

1600 INPUT "",Buff$

1610 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:SHOR ";Port(I)

1620 OUTPUT @Agte507x;"*OPC?"

1630 ENTER @Agte507x;Buff$

1640 PRINT "Set LOAD to Port "&VAL$(Port(I))&". Then push [Enter] key."

1650 INPUT "",Buff$

1660 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:LOAD ";Port(I)

1670 OUTPUT @Agte507x;"*OPC?"

1680 ENTER @Agte507x;Buff$

1690 NEXT I

1700 !

1710 ! Transmission Measurement

1720 !

1730 FOR I=1 TO Num_of_ports-1

1740 FOR J=I+1 TO Num_of_ports

1750 PRINT "Set THRU between Port "&VAL$(Port(I))&" and Port "& VAL$(Port(J))&". Then push [Enter] key."

1760 INPUT "",Buff$

1770 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:THRU ";Port(I);"," ;Port(J)

1780 OUTPUT @Agte507x;"*OPC?"

1790 ENTER @Agte507x;Buff$

1800 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:THRU ";Port(J);"," ;Port(I)

1810 OUTPUT @Agte507x;"*OPC?"

1820 ENTER @Agte507x;Buff$

1830 NEXT J

1840 NEXT I

1850 !

1860 ! Done

1870 !

1880 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:SAVE"

1890 PRINT "Done"

1900 SUBEND