Other topics about Sample Programs
The sample program performs 1-port or 2-port calibration using ECal.
See Calibration for this programming.
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.
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.
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.
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
'*** The variables of the resource manager and the instrument I/O are declared
Dim ioMgr As VisaComLib.ResourceManager
Dim Age507x As VisaComLib.FormattedIO488
Sub Ecal_vcom_click()
'*** 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 = 100000 ' TimeOut time
'*** Variable declaration
Dim Ch As String
Dim CalKit As Integer
Dim Port(4) As String
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.
Select Case Cells(3, 5)
Case "1 Port"
Call ECal_Exe(Ch, 1, Port) 'Perform 1-port calibration.
Case "2 Port"
Call ECal_Exe(Ch, 2, Port) 'Perform full 2-port calibration.
End Select
Age507x.IO.Close 'Closes the resource manager session.
End
End Sub
Sub ECal_Exe(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.
Age507x.WriteString ":SENS" & Ch & ":CORR:COLL:ECAL:SOLT" & NumPort & " " & Port(1) & vbLf, True 'Execute the 1-port calibration.
Case 2
MsgBox ("Connect Port " & Port(1) & " and Port " & Port(2) & ". then click [OK] button") 'Display the message box.
Age507x.WriteString ":SENS" & Ch & ":CORR:COLL:ECAL:SOLT" & NumPort & " " & Port(1) & "," & Port(2) & vbLf, True 'Execute the full 2-port calibration.
End Select
Call ErrorCheck 'Checking the error.
End Sub
Sub ErrorCheck()
Dim err As String * 50, ErrNo As Variant, Response
Age507x.WriteString ":SYST:ERR?" & vbLf, True
err = Age507x.ReadString '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
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 ""
150 PRINT "Input 1 to 2"
160 INPUT "Input number? (1 to 2)",Inp_char$
170 Cal_type=IVAL(Inp_char$,10)
180 IF Cal_type<1 OR Cal_type>2 THEN Type_select
190 OFF ERROR
200 !
210 Select_port(Cal_type,Port(*))
220 Ecal(@Agte507x,Ch$,Cal_type,Port(*))
230 !
240 OUTPUT @Agte507x;":MMEM:STOR:STYP CST"
250 OUTPUT @Agte507x;":MMEM:STOR """&File$&""""
260 END
270 !=============================================
280 ! Port Selection Function
290 !=============================================
300 SUB Select_port(INTEGER Num_of_ports,INTEGER Port(*))
310 DIM Inp_char$[9]
320 !
330 CLEAR SCREEN
340 IF Num_of_ports=2 THEN
350 Port(1)=1
360 Port(2)=2
370 ELSE
380 PRINT "## Test Ports Selection ##"
390 ON ERROR GOTO Port_select
400 FOR I=1 TO Num_of_ports
410 PRINT "Port("&VAL$(I)&"):";
420 Port_select: !
430 INPUT "Number?",Inp_char$
440 Port(I)=IVAL(Inp_char$,10)
450 IF Port(I)<1 OR Port(I)>2 THEN Port_select
460 FOR J=1 TO I-1
470 IF Port(I)=Port(J) THEN Port_select
480 NEXT J
490 PRINT Port(I)
500 NEXT I
510 OFF ERROR
520 END IF
530 SUBEND
540 !=============================================
550 ! Electronic Calibration Function
560 !=============================================
570 SUB Ecal(@Agte507x,Ch$,INTEGER Num_of_ports,INTEGER Port(*))
580 DIM Buff$[9],Err_msg$[100]
590 INTEGER Err_no,Port1
600 !
610 PRINT "## Full "&VAL$(Num_of_ports)&" Port ECal ##"
620 !
630 OUTPUT @Agte507x;"*CLS"
640 SELECT Num_of_ports
650 CASE 1
660 PRINT "Connect Port "&VAL$(Port(1))&" to ECal Module."
670 PRINT "Then push [Enter] key."
680 INPUT "",Buff$
690 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:ECAL:SOLT1 ";Port(1)
700 CASE 2
710 PRINT "Connect Port "&VAL$(Port(1));
720 PRINT " and Port "&VAL$(Port(2))&" to ECal Module."
730 PRINT "Then push [Enter] key."
740 INPUT "",Buff$
750 OUTPUT @Agte507x;":SENS"&Ch$&":CORR:COLL:ECAL:SOLT2 ";Port(1); ",";Port(2)
760 END SELECT
770 PRINT "Executing ..."
780 OUTPUT @Agte507x;":SYST:ERR?"
790 ENTER @Agte507x;Err_no,Err_msg$
800 IF Err_no<>0 THEN
810 PRINT "Error occurred!!"
820 PRINT " No:";Err_no,"Description: "&Err_msg$
830 PRINT "ECAL INTERRUPT!!"
840 ELSE
850 PRINT "Done"
860 END IF
870 SUBEND