我們將用例項演示如何在C#環境中利用visa32.cs進行儀器控制及自動測試。希望對您的測試有幫助。
描述
- IO Libraries Suite下載和安裝: https://www. keysight.com/us/en/lib/ software-detail/computer-software/io-libraries-suite-downloads-2175637.html
2. 在IOconnect expert中添加儀器,可以用儀器的網絡IP地址,也可以用HOSTID:
3. 建立一個C#的表單程式,並在project中添加visa32.cs,作為和儀器建立通訊及控制的動態連結庫:
添加的visa.cs可以是以下地址中的任何一個:
C:\Program Files (x86)\IVI Foundation\VISA\WinNT\ktvisa\include\KtVisa32.cs
C:\Program Files (x86)\IVI Foundation\VISA\WinNT\ktvisa\include\visa32.cs
C:\Program Files (x86)\IVI Foundation\VISA\WinNT\agvisa\include\agvisa32.cs
4. 編寫程式碼,可以參照IO Libraries Suite中的檔VISA Help文件,了解VISA中的各種方法和介面。
5. 以下是一個帶通濾波器的設定及測試程式碼,使用的儀器是Keysight VNA E5080B:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Threading; namespace Csharp_program_with_VISA { class Program { // Simple example using KtVisa32.dll through KtVisa32.cs or visa32.cs or agvisa32.cs //C:\Program Files (x86)\IVI Foundation\VISA\WinNT\ktvisa\include\KtVisa32.cs //C:\Program Files (x86)\IVI Foundation\VISA\WinNT\ktvisa\include\visa32.cs //C:\Program Files (x86)\IVI Foundation\VISA\WinNT\agvisa\include\agvisa32.cs static void Main(string[] args) {
Console.WriteLine("Start Program with VISA method Demo:\n");
string VNA_VISA_Adress = "TCPIP0::k-e5080b-00951::hislip0::INSTR";
//Filter test demo-connection
int rM = 0;
int vI = 0;
int stringSize = 100;
string idnString = "", filter_data = "", opc = "";
int len = 0;
double BW, Center, Q, Loss;
KtVisa32.viOpenDefaultRM(out rM);
KtVisa32.viOpen(rM, VNA_VISA_Adress, KtVisa32.VI_NO_LOCK, KtVisa32.VI_TMO_IMMEDIATE, out vI);//預設accessMode和timeout參數:KtVisa32.VI_NULL ,KtVisa32.VI_NULL
KtVisa32.viPrintf(vI, "*RST\n");
KtVisa32.viPrintf(vI, "*OPC?\n");
KtVisa32.viRead(vI, out opc, stringSize);
KtVisa32.viPrintf(vI, "*IDN?\n");
KtVisa32.viRead(vI, out idnString, stringSize);
KtVisa32.viPrintf(vI, "*OPC?\n");
KtVisa32.viRead(vI, out opc, stringSize);
if (opc == "+1\n")
{
Console.WriteLine("Instrument Informtion: " + idnString + "\n");
}
else
{
Console.WriteLine("\n Instrument connect failed" + "Please check the instrument address and hardware connection!");
return;
}
//Filter test demo- setup and measure
KtVisa32.viPrintf(vI, "*RST\n");
KtVisa32.viPrintf(vI, "*OPC?\n");
KtVisa32.viRead(vI, out opc, stringSize);
KtVisa32.viPrintf(vI, "*WAI\n");
KtVisa32.viPrintf(vI, ":CALCulate1:MEASure1:PARameter \"S21\"\n");
KtVisa32.viPrintf(vI, ":SENSe1:BANDwidth:RESolution 10000\n");
KtVisa32.viPrintf(vI, ":SENSe1:FREQuency:CENTer 3780000000\n");
KtVisa32.viPrintf(vI, ":SENSe1:FREQuency:SPAN 6000000000\n");
KtVisa32.viPrintf(vI, ":SENSe1:SWEep:POINts 201\n");
KtVisa32.viPrintf(vI, ":SOURce1:POWer1:COUPle 1\n");
KtVisa32.viPrintf(vI, ":SOURce1:POWer4:LEVel:IMMediate:AMPLitude -10\n");
KtVisa32.viPrintf(vI, ":INITiate1:CONTinuous 1\n");
Thread.Sleep(1000);
KtVisa32.viPrintf(vI, ":FORMat:DATA REAL,32\n");
KtVisa32.viPrintf(vI, "*OPC?\n");
KtVisa32.viRead(vI, out opc, stringSize);
KtVisa32.viPrintf(vI, ":INITiate1:CONTinuous 0\n");
KtVisa32.viPrintf(vI, ":ABORt\n");
KtVisa32.viPrintf(vI, ":INITiate1:IMMediate\n");
KtVisa32.viPrintf(vI, "*OPC?\n");
KtVisa32.viRead(vI, out opc, stringSize);
KtVisa32.viPrintf(vI, ":DISPlay:WINDow1:Y:AUTO\n");
KtVisa32.viPrintf(vI, "*OPC?\n");
KtVisa32.viRead(vI, out opc, stringSize);
KtVisa32.viPrintf(vI, ":INITiate1:CONTinuous 0\n");
KtVisa32.viPrintf(vI, ":ABORt\n");
KtVisa32.viPrintf(vI, ":INITiate1:IMMediate\n");
KtVisa32.viPrintf(vI, "*OPC?\n");
KtVisa32.viRead(vI, out opc, stringSize);
KtVisa32.viPrintf(vI, ":CALCulate1:MEASure1:MARKer1:BWIDth:STATe 1\n");//測量濾波器參數
KtVisa32.viPrintf(vI, "*OPC?\n");
KtVisa32.viRead(vI, out opc, stringSize);
KtVisa32.viPrintf(vI, ":CALCulate1:MEASure1:MARKer1:BWIDth:DATA?\n");
KtVisa32.viRead(vI, out filter_data, stringSize);
KtVisa32.viPrintf(vI, "*OPC?\n");
KtVisa32.viRead(vI, out opc, stringSize);
char[] delimiterChars = { ',', '\n' };
string[] filter_data_array = filter_data.Split(delimiterChars);
len = filter_data_array.Length;
BW = Convert.ToDouble(filter_data_array[0]) / 1e9;
Center = Convert.ToDouble(filter_data_array[1]) / 1e9;
Q = Convert.ToDouble(filter_data_array[2]) / 1e9;
Loss = Convert.ToDouble(filter_data_array[3]) / 1e9;
Console.WriteLine("Filter parameter test results:\n");
Console.WriteLine("BW= " + BW + " GHz\n");
Console.WriteLine("Center=" + Center + " GHz\n");
Console.WriteLine("Q= " + Q + "\n");
Console.WriteLine("Loss= " + Loss + " dB\n");
Console.WriteLine("Filter parameter test completed!\n");
Console.ReadLine();
//關閉連線
KtVisa32.viClose(vI);
KtVisa32.viClose(rM);
}
}
}
6.測試後表單輸出連線情況及測試結果,主要包括濾波器的頻寬(BW),中心頻率(Center),品質因子(Q),帶內插損(Loss);
需要更多資訊,您可存取:
是德科技