Other topics about Sample Programs
This sample program reads/writes the error coefficient.
This program sets measurement conditions with the segment table.
When you select "Read", it performs full 2-port calibration and read the error coefficient on the sheet of excel.
When you select "Write", it writes the error coefficient from the data on the sheet.
Dim ioMgr As VisaComLib.ResourceManager
Dim Ena As VisaComLib.FormattedIO488
Sub Err_Term_Click()
Dim Ch As String
Dim CalKit As Integer
Dim tNop As Long
Dim Respons As String
Dim Stimulus As String
Dim ErrTerm As String
Const Cal85032F = 4 'cal kit number
Ch = Cells(3, 6) 'Select channel
Respons = Cells(5, 6) 'Sets the respons port.
Stimulus = Cells(6, 6) 'Sets the stimulus port.
ErrTerm = Cells(7, 6) 'Sets the error term.
CalKit = Cal85032F 'Set cal kit (85032F)
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 "*RST", True 'Presets the setting state of the ENA.
Ena.WriteString "*CLS", True 'Clears the all status register.
Ena.WriteString ":SENS" & Ch & ":CORR:COLL:CKIT " & CalKit, True 'Select the calibration kit.
Call Set_sgm_tbl(Ch) 'Configures the segment table.
Select Case Cells(4, 6) 'Sets the read/write.
Case "Read"
Call SOLT(Ch, "2", "1", "No") 'Full 2-Port Calibration.
Case "Write"
Ena.WriteString ":SENS" & Ch & ":CORR:COEF:METH:SOLT2 1,2", True 'Sets the calibration type to the full 2-port calibration.
End Select
Ena.WriteString ":SENS" & Ch & ":SEGM:SWE:POIN?", True 'Reads out the total number of the measurement points of all segments.
tNop = Ena.ReadNumber
Call Exec_Error_Term(Ch, tNop, ErrTerm, Respons, Stimulus) 'Reads the error coefficient.
Ena.IO.Close
End
End Sub
Sub Exec_Error_Term(Ch As String, Nop As Long, ErrTerm As String, Respons As String, Stimulus As String)
Dim Error_Term_Data As Variant
Dim FreqData() As Double
Dim i As Integer, j As Integer
Dim SelMode As String
ReDim Error_Term_Data(Nop * 2 - 1) 'Defines the stock variables for the error coefficient as needed for NOP.
ReDim FreqData(Nop - 1) 'Defines the stock variables for the frequency needed for NOP.
SelMode = Cells(4, 6) 'Reads the read/write mode.
Select Case SelMode
Case "Read" 'Reads the error coefficient from the ena.
Ena.WriteString ":SENS" & Ch & ":CORR:COEF? " & ErrTerm & "," & Respons & "," & Stimulus, True 'Read the calibration coefficient data.
Error_Term_Data = Ena.ReadList(ASCIIType_R8, ",")
Call ErrorCheck 'Checking the error.
'
Ena.WriteString ":SENS1:FREQ:DATA?", True ' Read the stimulus data.
FreqData() = Ena.ReadList(ASCIIType_R8, ",")
For i = 0 To Nop - 1
Cells(10 + i, 1) = FreqData(i) 'Displays the frequency values to the excel sheet.
Cells(10 + i, 2) = Error_Term_Data(i * 2) 'Displays the real data from error coefficient items.
Cells(10 + i, 3) = Error_Term_Data(i * 2 + 1) 'Displays the imag data from error coefficient items.
Next i
Case "Write" 'Write the error coefficient to the ena.
Error_Term_Data = ErrTerm & "," & Respons & "," & Stimulus 'Sets the command parameter.
For i = 0 To Nop - 1
RealData = Cells(10 + i, 2) 'Retrieves the real data from the excel sheet.
ImagData = Cells(10 + i, 3) 'Retrieves the imag data from the excel sheet.
Error_Term_Data = Error_Term_Data & "," & RealData & "," & ImagData 'Sets the command parameter.
Next i
Ena.WriteString ":SENS" & Ch & ":CORR:COEF " & Error_Term_Data, True 'Write the calibration coefficient data.
Ena.WriteString ":SENS" & Ch & ":CORR:COEF:SAVE", True 'Calculates the calibration coefficients.
End Select
End Sub
Sub Set_sgm_tbl(Ch As String)
Dim Star1(2) As Double, Stop1(2) As Double, Pow1(2) As Double, If_bw1(2) As Double
Dim Segm As Integer, Nop1(2) As Integer, Num_of_tr1 As Integer
Dim i As Integer
Segm = 2
Star1(1) = Cells(4, 9) 'Sets the start frequency of segment 1 table.
Stop1(1) = Cells(4, 10) 'Sets the stop frequency of segment 1 table.
Pow1(1) = Cells(4, 11) 'Sets the power of segment 1 table.
If_bw1(1) = Cells(4, 12) 'Sets the ifbw of segment 1 table.
Nop1(1) = Cells(4, 13) 'Sets the nop of segment 1 table.
Star1(2) = Cells(5, 9) 'Sets the start frequency of segment 2 table.
Stop1(2) = Cells(5, 10) 'Sets the stop frequency of segment 2 table.
Pow1(2) = Cells(5, 11) 'Sets the power of segment 2 table.
If_bw1(2) = Cells(5, 12) 'Sets the ifbw of segment 2 table.
Nop1(2) = Cells(5, 13) 'Sets the nop of segment 2 table.
Ena.WriteString ":SENS" & Ch & ":SWE:TYPE SEGM", True 'Sets sweep type to segment.
Ena.WriteString ":SENS" & Ch & ":SEGM:DATA 5,0,1,1,0,0," & Segm & ",", False 'Sets the header of segment table.
Ena.WriteString Star1(1) & "," & Stop1(1) & "," & Nop1(1) & "," & If_bw1(1) & "," & Pow1(1) & ",", False 'Sets the 1st parameter.
Ena.WriteString Star1(2) & "," & Stop1(2) & "," & Nop1(2) & "," & If_bw1(2) & "," & Pow1(2), True 'Sets the 2nd parameter.
Call ErrorCheck 'Checking the error.
End Sub
Sub SOLT(Ch As String, NumPort As String, Port As String, Isolation As String)
Dim Dummy
Dim i As Integer, j As Integer
With Ena
Select Case NumPort
Case 1
.WriteString ":SENS" & Ch & ":CORR:COLL:METH:SOLT1 " & Port, True 'Set the 1-port calibration type.
Case 2
.WriteString ":SENS" & Ch & ":CORR:COLL:METH:SOLT2 1, 2", True 'Set the full 2-port calibration type.
End Select
' *** Reflection
If NumPort = 2 Then Port = 1
For i = 1 To NumPort
MsgBox ("Set Open to Port " & Port & ". then click [OK] button") 'Display the message box.
.WriteString ":SENS" & Ch & ":CORR:COLL:OPEN " & Port, True 'Measurement the OPEN calibration.
.WriteString "*OPC?", True 'Reads the *OPC? result to wait the calibration end
Dummy = .ReadNumber
MsgBox ("Set Short to Port " & Port & ". then click [OK] button") 'Display the message box.
.WriteString ":SENS" & Ch & ":CORR:COLL:SHORT " & Port, True 'Measurement the SHORT calibration.
.WriteString "*OPC?", True 'Reads the *OPC? result to wait the calibration end
Dummy = .ReadNumber
MsgBox ("Set Load to Port " & Port & ". then click [OK] button") 'Display the message box.
.WriteString ":SENS" & Ch & ":CORR:COLL:LOAD " & Port, True 'Measurement the LOAD calibration.
.WriteString "*OPC?", True 'Reads the *OPC? result to wait the calibration end
Dummy = .ReadNumber
Port = 2
Next i
' *** Transmission
If NumPort = 2 Then
MsgBox ("Set Thru to Ports 1 and 2. then click [OK] button") 'Display the message box.
.WriteString ":SENS" & Ch & ":CORR:COLL:THRU 1,2", True 'Measurement the THRU calibration.
.WriteString "*OPC?", True 'Reads the *OPC? result to wait the calibration end
Dummy = .ReadNumber
.WriteString ":SENS" & Ch & ":CORR:COLL:THRU 2,1", True 'Measurement the THRU calibration.
.WriteString "*OPC?", True 'Reads the *OPC? result to wait the calibration end
Dummy = .ReadNumber
End If
' *** Isolation Calibration
If Isolation = "Yes" And NumPort = 2 Then
MsgBox ("Set Loads on Ports 1 and 2. then click [OK] button") 'Display the message box.
.WriteString ":SENS" & Ch & ":CORR:COLL:METH:SOLT2 1,2", True
.WriteString ":SENS" & Ch & ":CORR:COLL:ISOL 1,2", True
.WriteString "*OPC?", True 'Reads the *OPC? result to wait the calibration end
Dummy = .ReadNumber
.WriteString ":SENS" & Ch & ":CORR:COLL:METH:SOLT2 2,1", True
.WriteString ":SENS" & Ch & ":CORR:COLL:ISOL 2,1", True
.WriteString "*OPC?", True 'Reads the *OPC? result to wait the calibration end
Dummy = .ReadNumber
End If
.WriteString ":SENS" & Ch & ":CORR:COLL:SAVE", True 'Calculating the calibration coefficients
End With
End Sub
Sub ErrorCheck()
Dim err As Variant
Ena.WriteString ":SYST:ERR?", True 'Reads error message.
err = Ena.ReadList
If err(0) <> 0 Then
Response = MsgBox(err(1), vbOKOnly) 'Display the message box.
End If
End Sub