• 易迪拓培训,专注于微波、射频、天线设计工程师的培养

电校准

录入:edatop.com    点击:
  • 概述

  • 在Excel VBA中的样本程序

  • 在HT Basic中的样本程序


概述

样本程序使用电校准进行1端口和2端口校准。

参见这个程序的校准。

在Excel VBA中的样本程序

Sub ECal_Click()

    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(4) As String

    Const TimeOutTime = 40000   'timeout time.

    

    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.

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

    Port(4) = Cells(3, 9)       'Sets the select port 4.

        

    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.

    

    Select Case Cells(3, 5)

        Case "1 Port"

            Call ECal(vi, Ch, 1, Port)   'Perform 1-port calibration.

        Case "2 Port"

            Call ECal(vi, Ch, 2, Port)   'Perform full 2-port calibration.

        Case "3 Port"

            Call ECal(vi, Ch, 3, Port)   'Perform full 3-port calibration.

        Case "4 Port"

            Call ECal(vi, Ch, 4, Port)   'Perform full 4-port calibration.

    End Select

    

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

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

    

    End  

End Sub

Sub ECal(vi As Long, 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

            MsgBox ("Connect Port " & Port(1) & ". then click [OK] button")  'Display the message box.

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

        Case 2

            MsgBox ("Connect Port " & Port(1) & " and Port " & Port(2) & ". then click [OK] button")   'Display the message box.

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

        Case 3

            MsgBox ("Connect Port " & Port(1) & "," & Port(2) & " and Port " & Port(3) & ". then click [OK] button")  'Display the message box.

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

        Case 4

            MsgBox ("Connect Port 1, 2, 3 and 4. then click [OK] button")    'Display the message box.

            Call viVPrintf(vi, ":SENS" & Ch & ":CORR:COLL:ECAL:SOLT4 1,2,3,4" & vbLf, 0) 'Execute the full 4-port calibration.

    End Select

    

    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

在HT Basic中的样本程序(ecal.htb)

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

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

30 !

40 ASSIGN @Agte507x TO 717

50 File$="Ex_4_2.sta"

60 Ch$="1"

70 !

80 CLEAR SCREEN

90 ON ERROR GOTO Type_select

100 Type_select: !

110 PRINT "## Calibration Type Selection ##"

120 PRINT " 1: Full 1 Port"

130 PRINT " 2: Full 2 Port"

140 PRINT " 3: Full 3 Port"

150 PRINT " 4: Full 4 Port"

160 PRINT ""

170 PRINT "Input 1 to 4"

180 INPUT "Input number? (1 to 4)",Inp_char$

190 Cal_type=IVAL(Inp_char$,10)

200 IF Cal_type<1 OR Cal_type>4 THEN Type_select

210 OFF ERROR

220 !

230 Select_port(Cal_type,Port(*))

240 Ecal(@Agte507x,Ch$,Cal_type,Port(*))

250 !

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

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

280 END

290 !=============================================

300 ! Port Selection Function

310 !=============================================

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

330 DIM Inp_char$[9]

340 !

350 CLEAR SCREEN

360 IF Num_of_ports=4 THEN

370 Port(1)=1

380 Port(2)=2

390 Port(3)=3

400 Port(4)=4

410 ELSE

420 PRINT "## Test Ports Selection ##"

430 ON ERROR GOTO Port_select

440 FOR I=1 TO Num_of_ports

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

460 Port_select: !

470 INPUT "Number?",Inp_char$

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

490 IF Port(I)<1 OR Port(I)>4 THEN Port_select

500 FOR J=1 TO I-1

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

520 NEXT J

530 PRINT Port(I)

540 NEXT I

550 OFF ERROR

560 END IF

570 SUBEND

580 !=============================================

590 ! Electronic Calibration Function

600 !=============================================

610 SUB Ecal(@Agte507x,Ch$,INTEGER Num_of_ports,INTEGER Port(*))

620 DIM Buff$[9],Err_msg$[100]

630 INTEGER Err_no,Port1

640 !

650 PRINT "## Full "&VAL$(Num_of_ports)&" Port ECal ##"

660 !

670 OUTPUT @Agte507x;"*CLS"

680 SELECT Num_of_ports

690 CASE 1

700 PRINT "Connect Port "&VAL$(Port(1))&" to ECal Module."

710 PRINT "Then push [Enter] key."

720 INPUT "",Buff$

730 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:ECAL:SOLT1 ";Port(1)

740 CASE 2

750 PRINT "Connect Port "&VAL$(Port(1));

760 PRINT " and Port "&VAL$(Port(2))&" to ECal Module."

770 PRINT "Then push [Enter] key."

780 INPUT "",Buff$

790 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:ECAL:SOLT2 ";Port(1); ",";Port(2)

800 CASE 3

810 PRINT "Connect Port "&VAL$(Port(1));

820 PRINT ", Port "&VAL$(Port(2));

830 PRINT " and Port "&VAL$(Port(3))&" to ECal Module."

840 PRINT "Then push [Enter] key."

850 INPUT "",Buff$

860 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:ECAL:SOLT3 ";Port(1); ",";Port(2);",";Port(3)

870 CASE 4

880 PRINT "Connect Port 1, Port 2, Port 3 and Port 4 to to ECal Mod ule."

890 PRINT "Then push [Enter] key."

900 INPUT "",Buff$

910 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:ECAL:SOLT4 1,2,3,4"

920 END SELECT

930 PRINT "Executing ..."

940 OUTPUT @Agte507x;":SYST:ERR?"

950 ENTER @Agte507x;Err_no,Err_msg$

960 IF Err_no<>0 THEN

970 PRINT "Error occurred!!"

980 PRINT " No:";Err_no,"Description: "&Err_msg$

990 PRINT "ECAL INTERRUPT!!"

1000 ELSE

1010 PRINT "Done"

1020 END IF

1030 SUBEND

 

矢量网络分析仪使用培训教程套装,让你快速掌握网分使用

上一篇:差错检测(SRQ)
下一篇:利用SICL-LAN服务器的控制

微波射频测量操作培训课程详情>>
射频和天线工程师培训课程详情>>

  网站地图