static void Main(string[] args) { FunctionsExample DmmClass = new FunctionsExample(); //Create an instance of this class so we can call functions from Main //For more information on getting started using VISA COM I/O operations see the app note located at: //http://cp.literature.agilent.com/litweb/pdf/5989-6338EN.pdf Ivi.Visa.Interop.ResourceManager rm = new Ivi.Visa.Interop.ResourceManager(); //Open up a new resource manager Ivi.Visa.Interop.FormattedIO488 myDmm = new Ivi.Visa.Interop.FormattedIO488(); //Open a new Formatted IO 488 session /* AGILENT_33220A = "USB0::0x0957::0x0407::MY44021621::0::INSTR" AGILENT_33522A = "USB0::0x0957::0x2307::MY50003961::0::INSTR" */ try { string AGILENT_33220A = "USB0::0x0957::0x0407::MY44021621::0::INSTR"; string AGILENT_33522A = "USB0::0x0957::0x2307::MY50003961::0::INSTR"; myDmm.IO = (IMessage)rm.Open(AGILENT_33220A, AccessMode.NO_LOCK, 2000, ""); //Open up a handle to the DMM with a 2 second timeout myDmm.IO.Timeout = 3000; //You can also set your timeout by doing this command, sets to 3 seconds //First start off with a reset state myDmm.IO.Clear(); //Send a device clear first to stop any measurements in process myDmm.WriteString("*RST", true); //Reset the device myDmm.WriteString("*IDN?", true); //Get the IDN string string IDN = myDmm.ReadString(); Console.WriteLine(IDN); //report the DMM's identity myDmm.WriteString(":OUTP:STAT 0", true); // Disable Output myDmm.WriteString(":SOUR:FREQ:CW 1.1512 MHZ", true); DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors myDmm.WriteString(":SOUR:VOLT:LEV:IMM:AMPL 0.1 VPP", true); DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors myDmm.WriteString(":SOUR:BURS:PHAS 0", true); DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors System.Threading.Thread.Sleep(5000); myDmm.WriteString(":SOUR:BURS:NCYC 50000", true); DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors myDmm.WriteString(":SOUR:BURS:INT:PER 0.1 S", true); DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors myDmm.WriteString(":SOUR:FREQ?", true); string FreqRes = myDmm.ReadString(); myDmm.WriteString(":SOUR:BURS:INT:PER?", true); string PeriodRes = myDmm.ReadString(); myDmm.WriteString(":SOUR:VOLT:LEV:IMM:AMPL?", true); string AmplitudeRes = myDmm.ReadString(); myDmm.WriteString(":SOUR:BURS:PHAS?", true); string PhasResult = myDmm.ReadString(); myDmm.WriteString(":SOUR:BURS:NCYC?", true); string NumCycRes = myDmm.ReadString(); DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors Console.WriteLine("Current Values are:" + "Period:" + PeriodRes + "Frequency:" + FreqRes + "Amplitude" + AmplitudeRes + "Phase" + PhasResult + "Cycles" + NumCycRes); myDmm.WriteString(":SOUR:BURS:STAT 1", true); DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors myDmm.WriteString(":OUTP:STAT 1", true); // Enable Output DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors } catch (Exception e) { Console.WriteLine("Error occured: " + e.Message); } finally { //Close out your resources try { myDmm.IO.Close(); } catch{} try{ System.Runtime.InteropServices.Marshal.ReleaseComObject(myDmm);} catch {} try{ System.Runtime.InteropServices.Marshal.ReleaseComObject(rm); } catch {} /* Console.WriteLine("Press any key to continue..."); Console.ReadKey(); */ } }
/* * * WT210一次性读取出三个值 * 函数已经将读取出的值分开[0][1][2]三个端口测量结果 */ public static float[] ReadValue(String IOadress13) { string[] conn = { "", "", "" }; float[] rus = new float[3]; try { Ivi.Visa.Interop.ResourceManager rm = new Ivi.Visa.Interop.ResourceManager(); Ivi.Visa.Interop.FormattedIO488 myDmm = new Ivi.Visa.Interop.FormattedIO488(); string WT210 = "GPIB0::" + IOadress13 + "::INSTR"; myDmm.IO = (IMessage)rm.Open(WT210, AccessMode.NO_LOCK, 2000, ""); myDmm.IO.Clear(); myDmm.WriteString("MEAS:NORM:VAL?", true); String aa = myDmm.ReadString(); conn = aa.Split(','); rus[0] = Convert.ToSingle(conn[0]); rus[1] = Convert.ToSingle(conn[1]); rus[2] = Convert.ToSingle(conn[2]); if (rus[0] > 400 || rus[1] > 10 || rus[2] > 100) { delay.Delay1(2); myDmm.WriteString("MEAS:NORM:VAL?", true); aa = myDmm.ReadString(); conn = aa.Split(','); rus[0] = Convert.ToSingle(conn[0]); rus[1] = Convert.ToSingle(conn[1]); rus[2] = Convert.ToSingle(conn[2]); } } catch (System.Runtime.InteropServices.COMException) { MessageBox.Show("WT210读数出错", "出错提示", MessageBoxButtons.OKCancel); } return(rus); }
public void SetCentreq(int Freq) { //throw new System.NotImplementedException(); ioDmm.WriteString(":FREQ:CENT " + Convert.ToString(Freq) + " MHz", true); // ioDmm.WriteString(":BWID 1MHz", true); }
public bool WriteString(string Str_Write) { try { switch (Str_IO_interface) { case "GPIB": myDmm.WriteString(Str_Write, true); break; case "USB": break; case "RJ45": // 网口 break; case "RS232": // 网口 break; } return(true); } catch (Exception error) { // MessageBox.Show(error.Message); log.AdapterLogString(3, error.Message); return(false); } }
public static String[] ReadHramVal(String IOadress13) { string[] conn = new string[102]; try { Ivi.Visa.Interop.ResourceManager rm = new Ivi.Visa.Interop.ResourceManager(); Ivi.Visa.Interop.FormattedIO488 myDmm = new Ivi.Visa.Interop.FormattedIO488(); string WT210 = "GPIB0::" + IOadress13 + "::INSTR"; myDmm.IO = (IMessage)rm.Open(WT210, AccessMode.NO_LOCK, 2000, ""); myDmm.IO.Clear(); myDmm.WriteString("*RST", true); delay.Delay1(1); myDmm.WriteString("HARM:STAT ON", true); delay.Delay1(4); myDmm.WriteString("MEAS:HARM:ITEM:PRES APAT", true); delay.Delay1(3); myDmm.WriteString("MEAS:HARM:VAL? ", true); String aa = myDmm.ReadString(); conn = aa.Split(','); myDmm.WriteString("HARM:STAT OFF", true); myDmm.WriteString("MEAS:NORM:ITEM:A OFF", true); myDmm.WriteString("MEAS:NORM:ITEM:PF ON", true); } catch (System.Runtime.InteropServices.COMException) { MessageBox.Show("WT210读数出错", "出错提示", MessageBoxButtons.OKCancel); } return(conn); }
/// <summary> /// Method to get the ID string of instrument /// </summary> private string GetInstrumentID() { string m_strReturn; ioArbFG.WriteString("*IDN?", true); m_strReturn = ioArbFG.ReadString(); if (m_strReturn != null) { EnableControls(); return(m_strReturn); } else { DisableControls(); return("Error : Could not read the ID of instrument"); } }
/* * * 设置SOURCE * 将需要设置的参数作为输入 * 简化需要操作的语言 */ public static void InitSetCV(String IOadress5) { try { Ivi.Visa.Interop.ResourceManager rm = new Ivi.Visa.Interop.ResourceManager(); Ivi.Visa.Interop.FormattedIO488 myDmm = new Ivi.Visa.Interop.FormattedIO488(); string Agilent6063B = "GPIB0::" + IOadress5 + "::INSTR"; myDmm.IO = (IMessage)rm.Open(Agilent6063B, AccessMode.NO_LOCK, 2000, ""); myDmm.IO.Clear(); myDmm.WriteString("INPUT OFF", true); myDmm.WriteString("MODE:VOLT", true); myDmm.WriteString("INPUT ON", true); } catch (System.Runtime.InteropServices.COMException) { MessageBox.Show("Agilent6063B设置出错", "出错提示", MessageBoxButtons.OKCancel); } }
/* * *设置机器函数 * 输入设置命令,不需要返回 */ public static void SetReadPF(String IOadress13) { try { Ivi.Visa.Interop.ResourceManager rm = new Ivi.Visa.Interop.ResourceManager(); Ivi.Visa.Interop.FormattedIO488 myDmm = new Ivi.Visa.Interop.FormattedIO488(); string WT210 = "GPIB0::" + IOadress13 + "::INSTR"; myDmm.IO = (IMessage)rm.Open(WT210, AccessMode.NO_LOCK, 2000, ""); myDmm.IO.Clear(); myDmm.WriteString("*RST", true); myDmm.WriteString("MEAS:NORM:ITEM:A OFF", true); myDmm.WriteString("MEAS:NORM:ITEM:PF ON", true); } catch (System.Runtime.InteropServices.COMException) { MessageBox.Show("WT210读数出错", "出错提示", MessageBoxButtons.OKCancel); } }
public bool InitInstrument() { OpenInstrument(); if (ErrorCode == 0) { ioDmm.WriteString(Reset_Cmd, true); ioDmm.WriteString(SetInputRF1_Cmd, true); return(true); } return(false); }
public static bool Link(String IOadress16) { bool conn = false; try { Ivi.Visa.Interop.ResourceManager rm = new Ivi.Visa.Interop.ResourceManager(); Ivi.Visa.Interop.FormattedIO488 myDmm = new Ivi.Visa.Interop.FormattedIO488(); string Agilent6812B = "GPIB0::" + IOadress16 + "::INSTR"; myDmm.IO = (IMessage)rm.Open(Agilent6812B, AccessMode.NO_LOCK, 2000, ""); myDmm.IO.Clear(); myDmm.WriteString("*RST", true); myDmm.WriteString("*IDN?", true); conn = true; } catch (System.Runtime.InteropServices.COMException) { conn = false; } return(conn); }
/* * * 此函数连接Agilent 34401A * 输入命令接收仪器返回值 * 如果失败则捕获异常并返回error字符串 */ public static String Comm(String ToMul, String IOadress22) { String MulRe = "error"; try { Ivi.Visa.Interop.ResourceManager rm = new Ivi.Visa.Interop.ResourceManager(); Ivi.Visa.Interop.FormattedIO488 myDmm = new Ivi.Visa.Interop.FormattedIO488(); String AGILENT_34401A = "GPIB0::" + IOadress22 + "::INSTR"; myDmm.IO = (IMessage)rm.Open(AGILENT_34401A, AccessMode.NO_LOCK, 2000, ""); myDmm.IO.Clear(); myDmm.WriteString("*RST", true); myDmm.WriteString(ToMul, true); MulRe = myDmm.ReadString(); Console.WriteLine(MulRe); return(MulRe); } catch (System.Runtime.InteropServices.COMException) { return(MulRe); } }
/* * * 万用表 连接测试方法 * 用try将连接代码包括起来判断是否正常连接 */ public static bool Link(String IOadress22) { bool conn = false; try { Ivi.Visa.Interop.ResourceManager rm = new Ivi.Visa.Interop.ResourceManager(); Ivi.Visa.Interop.FormattedIO488 myDmm = new Ivi.Visa.Interop.FormattedIO488(); String AGILENT_34401A = "GPIB0::" + IOadress22 + "::INSTR"; myDmm.IO = (IMessage)rm.Open(AGILENT_34401A, AccessMode.NO_LOCK, 2000, ""); myDmm.IO.Clear(); myDmm.WriteString("*RST", true); myDmm.WriteString("*IDN?", true); Console.WriteLine(myDmm.ReadString()); //report the DMM's identity conn = true; return(conn); } catch (System.Runtime.InteropServices.COMException) { conn = false; return(conn); } }
public static bool SetPut(String VOLT, String FREQ, String ACDC, String IOadress12) { bool conn = false; try { Ivi.Visa.Interop.ResourceManager rm = new Ivi.Visa.Interop.ResourceManager(); Ivi.Visa.Interop.FormattedIO488 myDmm = new Ivi.Visa.Interop.FormattedIO488(); string Agilent6812B = "GPIB0::" + IOadress12 + "::INSTR"; myDmm.IO = (IMessage)rm.Open(Agilent6812B, AccessMode.NO_LOCK, 2000, ""); myDmm.IO.Clear(); myDmm.WriteString("VOLT " + VOLT, true); myDmm.WriteString("FREQ " + FREQ, true); myDmm.WriteString("OUTP:COUP " + ACDC, true); myDmm.WriteString("OUTPUT ON", true); conn = true; } catch (System.Runtime.InteropServices.COMException) { conn = false; } return(conn); }
public static void Close(String IOadress12) { try { Ivi.Visa.Interop.ResourceManager rm = new Ivi.Visa.Interop.ResourceManager(); Ivi.Visa.Interop.FormattedIO488 myDmm = new Ivi.Visa.Interop.FormattedIO488(); string Agilent6812B = "GPIB0::" + IOadress12 + "::INSTR"; myDmm.IO = (IMessage)rm.Open(Agilent6812B, AccessMode.NO_LOCK, 2000, ""); myDmm.IO.Clear(); myDmm.WriteString("OUTPUT OFF", true); } catch (System.Runtime.InteropServices.COMException) { } }
/*The following example uses Measure? command to make a single * ac current measurement. This is the easiest way to program the * multimeter for measurements. However, MEASure? does not offer * much flexibility. * Be sure to set the instrument address and Initialize before * calling this method. */ private void btnMeasure_Click(object sender, System.EventArgs e) { double dbResult; try { System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; btnConfigure.Enabled = false; btnMeasure.Enabled = false; //Reset the dmm ioDmm.WriteString("*RST", true); //Clear the dmm registers ioDmm.WriteString("*CLS", true); // Set meter to 1 amp ac range ioDmm.WriteString("Measure:Current:AC? 1A,0.001MA", true); dbResult = (double)ioDmm.ReadNumber(IEEEASCIIType.ASCIIType_R4, true); txtResult.Text = dbResult + " amps AC"; btnConfigure.Enabled = true; btnMeasure.Enabled = true; System.Windows.Forms.Cursor.Current = Cursors.Default; } catch (SystemException ex) { btnConfigure.Enabled = true; btnMeasure.Enabled = true; MessageBox.Show("Measure command failed. " + ex.Source + " " + ex.Message, "GPIB_Meas_Config", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private string WriteReadString_GPIB(string ioaddr, string str_Write, ReadWrite operation, int count = 0) { string buf = Status.Failed.ToString(); try { lock (syncRoot_GPIB) { if (rm == null || myDmm == null || myDmm.IO == null) { rm = new Ivi.Visa.Interop.ResourceManager(); //Open up a new resource manager myDmm = new Ivi.Visa.Interop.FormattedIO488(); //Open a new Formatted IO 488 session myDmm.IO = (IMessage)rm.Open(ioaddr, AccessMode.NO_LOCK, 5000, ""); //Open up a handle to the DMM with a 2 second timeout myDmm.IO.Timeout = 5000; //You can also set your timeout by doing this command, sets to 3 seconds //myDmm.IO.Clear(); //Send a device clear first to stop any measurements in process //myDmm.WriteString("*RST", true); dicMyDmm = new Dictionary <string, IMessage>(); dicMyDmm.Add(ioaddr, myDmm.IO); } if (myDmm.IO != null && dicMyDmm.ContainsKey(ioaddr)) { myDmm.IO = dicMyDmm[ioaddr]; } else { Thread.Sleep(100); myDmm.IO = (IMessage)rm.Open(ioaddr, AccessMode.NO_LOCK, 5000, ""); //Open up a handle to the DMM with a 2 second timeout myDmm.IO.Timeout = 5000; //You can also set your timeout by doing this command, sets to 3 seconds dicMyDmm.Add(ioaddr, myDmm.IO); } //if (myDmm.IO != null && myDmm.IO.ResourceName != ioaddr + "::INSTR") //{ // Thread.Sleep(100); // myDmm.IO = (IMessage)rm.Open(ioaddr, AccessMode.NO_LOCK, 5000, ""); //Open up a handle to the DMM with a 2 second timeout // myDmm.IO.Timeout = 5000; //You can also set your timeout by doing this command, sets to 3 seconds // Thread.Sleep(100); //} //myDmm.IO.Clear(); //Send a device clear first to stop any measurements in process //myDmm.WriteString("*RST", true); if (operation == ReadWrite.Write) { myDmm.WriteString(str_Write, true); buf = Status.Pass.ToString(); } else if (count == 0) { buf = myDmm.ReadString(); //myDmm.IO.Clear(); //Send a device clear first to stop any measurements in process } else { byte[] arr = new byte[count]; arr = myDmm.IO.Read(count); buf = System.Text.Encoding.Default.GetString(arr); } Thread.Sleep(50); return(buf); } } catch { //Log.SaveLogToTxt(ex.Message + "\r\n" + "failed to operate GPIB"); return(buf); } }
public bool OpenRS232Port(int ComPortNum) //""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" // This function opens a port (the communication between the instrument and // computer). // YJW: 函数,打开232通讯口并且验证安捷伦和计算机的连接是否正常,读取安捷伦设备的身份字符串 //""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" { string addr, //通讯地址 msg, //消息 option_string; //通讯设定字符串 try // YJW: 放在TRY模块里,可以捕获异常并且处理 { //create the formatted io object //YJW: 声明488通讯类实例 data_logger = new FormattedIO488Class(); //create the resource manager //YJW: 声明Ivi.Visa.Interop中的ResourceManger类实例 ResourceManager mgr = new ResourceManager(); // Get address and type (ASRL), and do an initial check //YJW: 使用232通讯,即ASRL addr = "ASRL" + Convert.ToString(ComPortNum); Globls.addrtype = "ASRL"; // If address is Serial, we have 34970 and must set some things //YJW: 设定232通讯 //YJW: 设定串口通讯的COM口号 addr = "ASRL" + Convert.ToString(ComPortNum) + "::INSTR"; // Use the optionstring to setup the RS-232 parameters //YJW: 设定串口通讯的参数 //option_string = "Timeout = 10000 ; SendEndEnabled = TRUE ; TerminationCharacter = 10 ; TerminationCharacterEnabled = TRUE ; BaudRate = 9600 ; DataBits = 8 ; EndIn = ASRL_END_TERMCHAR ; EndOut = ASRL_END_NONE ; FlowControl = ASRL_FLOW_DTR_DSR ; Parity = ASRL_PAR_NONE ; StopBits = ASRL_STOP_ONE "; option_string = "Timeout = 10000 ; BaudRate = 9600 ; DataBits = 8 ; FlowControl = ASRL_FLOW_DTR_DSR ; Parity = ASRL_PAR_NONE ; StopBits = ASRL_STOP_ONE "; // Open the I/O session with the driver //YJW: 打开通讯口 data_logger.IO = (IMessage)mgr.Open(addr, AccessMode.NO_LOCK, 4000, option_string); Thread.Sleep(500); // Set the instrument to remote //YJW: 通过通讯口发送COMMAND STRING,要求远程控制 data_logger.WriteString("SYSTem:REMote", true); // Check and make sure the correct instrument is addressed //YJW: 设别连接设别的身份,确认是正确的设备 data_logger.WriteString("*IDN?", true); msg = data_logger.ReadString(); // if not 34970 or 34972 then error and return //YJW: 如果不是正确的设备,抛出错误 if ((msg.IndexOf("34972A") < 0) && (msg.IndexOf("34970A") < 0)) { MessageBox.Show("Incorrect instrument addressed; use the correct address.", "VISACom"); //ioType.Text = "GPIB0::9"; //ioType.Refresh(); Globls.connected = false; return(false); } // Remove cr and or lf character //YJW: 除去身份识别字符串最后的结尾字符串 msg = msg.Remove((msg.Length - 1), 1); // Check and make sure the 34901A Module is installed in slot 100; //YJW: 确认安装在机内的模块是34901A,否则抛出错误 data_logger.WriteString("SYSTem:CTYPe? 100", true); msg = data_logger.ReadString(); if (msg.IndexOf("34901A") < 0) { MessageBox.Show("Incorrect Module Installed in slot 100!", "VISACom"); } // Check if the DMM is installed; convert returned ASCII string to number. //YJW: 检查主机是否安装了DMM,即数字万用表,否则抛出错误 data_logger.WriteString("INSTrument:DMM:INSTalled?", true); msg = data_logger.ReadString(); if (Convert.ToInt16(msg) == 0) { MessageBox.Show("DMM not installed; unable to make measurements.", "VISACom"); } // Check if the DMM is enabled;; convert returned ASCII string to number. // Enable the DMM, if not enabled //YJW: 检查主机的DMM是否启用,否则启动DMM data_logger.WriteString("INSTrument:DMM?", true); msg = data_logger.ReadString(); if (Convert.ToInt16(msg) == 0) { data_logger.WriteString("INSTrument:DMM ON", true); } //YJW: 至此主机和PC的通讯已正常建立 Globls.connected = true; return(true); } catch (Exception)//YJW: 异常捕获处理代码块 { //MessageBox.Show(e.Message + "\nin function: OpenPort. Likely due to bad IO address. \nVerify address field and press Select I/O button.", // "VISACom"); return(false); } }
public double Config34970A(List <string[]> GlobalConfigStrList, List <string[]> ChannelConfigStrList) //""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" // This function performs the instrument setup. //YJW: 函数 配置安捷伦 //""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" { double DelayVal, TrigTime; string rdg; string msg; string NormalMsg = ""; // Check for exceptions //YJW: 使用TRY捕获异常 try { // Reset instrument to turn-on condition // YJW: reset设备 data_logger.WriteString("*RST", true); Thread.Sleep(750); //----------YJW CODE BEGIN---------- //拼出通道设定字符串 for (int k = 0; k < ChannelConfigStrList.Count; k++) { for (int i = 1; i < ChannelConfigStrList[k].Length; i = i + 2) { NormalMsg = ChannelConfigStrList[k][0] + ChannelConfigStrList[k][i] + ", " + ChannelConfigStrList[k][i + 1]; //Console.WriteLine(NormalMsg);//若调试字符串取消此注释控制台输出 data_logger.WriteString(NormalMsg, true);//每拼出一条字符串,就送主机执行 } } NormalMsg = "";//清空 //拼出全局设定字符串 for (int k = 0; k < GlobalConfigStrList.Count; k++) { for (int i = 1; i < GlobalConfigStrList[k].Length; i++) { NormalMsg = GlobalConfigStrList[k][0] + GlobalConfigStrList[k][i]; //Console.WriteLine(NormalMsg);//若调试字符串取消此注释控制台输出 data_logger.WriteString(NormalMsg, true);//每拼出一条字符串,就送主机执行 } } //----------YJW CODE END---------- // Wait for instrument to setup //YJW: 确认上述设置已经完成 data_logger.WriteString("*OPC?", true); rdg = data_logger.ReadString(); // Gets the number of channels to be scanned and is used to determine // the number of readings. //YJW: 从主机读回扫描的通道总数,传全局变量 data_logger.WriteString("ROUTe:SCAN:SIZE?", true); Globls.NumChan = (double)data_logger.ReadNumber(IEEEASCIIType.ASCIIType_R8, true); // Gets the number of triggers; 34970A/34972A returns a floating-point number. //YJW: 从主机读回扫描触发的次数,传全局变量 data_logger.WriteString("TRIGger:COUNt?", true); Globls.TrigCount = (double)data_logger.ReadNumber(IEEEASCIIType.ASCIIType_R8, true); // Get the delay; for future use; 34970A/34972A returns a floating-point number //YJW: 从主机读回通道间隔 data_logger.WriteString("ROUTe:CHANnel:DELay? (@101)", true); DelayVal = (double)data_logger.ReadNumber(IEEEASCIIType.ASCIIType_R8, true); // Get the trigger time; 34970A/34972A returns a floating-point number //YJW: 从主机读回扫描触发间隔 data_logger.WriteString("TRIGger:TIMer?", true); TrigTime = (double)data_logger.ReadNumber(IEEEASCIIType.ASCIIType_R8, true); // Calculate total number of readings //YJW: 计算正在扫描的总时间 Globls.NumRdgs = Globls.NumChan * Globls.TrigCount; // Calculate total time //YJW: 计算整个测量的总时间 Globls.TotTime = (TrigTime * Globls.TrigCount) - TrigTime + (Globls.NumChan * DelayVal); // Check and make sure the correct instrument is addressed //YJW: 再次确认主机身份 data_logger.WriteString("*IDN?", true); msg = data_logger.ReadString(); //Check for errors //YJW: 设定查错句柄,因为原来函数名称为Setup,所以传变量是"Setup" Check_Error("Setup"); return(Globls.TotTime); } catch (Exception e) { MessageBox.Show(e.Message + "\nin function: Setup", "VISACom"); return(0); } }
public void SetCmw500DtvRssiTransmition(String frequency, String amplitude) { string strCommand = string.Empty; string strReturn = string.Empty; ioTestSet = new FormattedIO488(); //CMW500 try { ResourceManager grm = new ResourceManager(); ioTestSet.IO = (IMessage)grm.Open("RS_CMW500", AccessMode.NO_LOCK, 2000, ""); } catch { ioTestSet.IO = null; } if ((ioTestSet != null) && (!bDTVON)) { if ((amplitude == String.Empty) || (Convert.ToDouble(amplitude) > -10)) { throw new DtvGenException("Amplitude must be between -10 to -65 dBm"); return; } if ((frequency == "") || (Convert.ToDouble(frequency) > 803.143) || (Convert.ToDouble(frequency) < 473.143)) { throw new DtvGenException("Frequency must be between 473.143 to 803.143 Mhz."); return; } ioTestSet.WriteString("*IDN?", true); Thread.Sleep(3000); //Verify if DTV wave form can be found ioTestSet.WriteString("MMEM:CAT? 'D:\\Rohde-Schwarz\\CMW\\Data\\waveform\\'", true); strReturn = ioTestSet.ReadString(); if (strReturn.Contains("ISDB-Tb_Digital_TV_withPR.wv") == false) { throw new DtvGenException("Wave Form Error. Wave Form: \r\n D:\\Rohde-Schwarz\\CMW\\Data\\waveform\\ISDB-Tb_Digital_TV_withPR.wv \r\n Not found !!!"); return; } ioTestSet.WriteString("SOUR:GPRF:GEN:ARB:FILE 'D:\\Rohde-Schwarz\\CMW\\Data\\waveform\\ISDB-Tb_Digital_TV_withPR.wv';*OPC?", true); ioTestSet.WriteString("SOUR:GPRF:GEN:ARB:FILE?", true); ioTestSet.WriteString("SOUR:GPRF:GEN:BBM ARB;:SOUR:GPRF:GEN:ARB:REP CONT;:SOUR:GPRF:GEN:LIST OPEN;:TRIG:GPRF:GEN:ARB:RETR ON;:TRIG:GPRF:GEN:ARB:AUT ON;*OPC?", true); ioTestSet.WriteString("SYST:ERR?", true); ioTestSet.WriteString("*CLS", true); ioTestSet.WriteString("CONFigure:FDCorrection:USAGe? RF1C", true); //Set frequency strCommand = "SOUR:GPRF:GEN1:RFS:FREQ " + frequency + " MHz;*OPC?"; ioTestSet.WriteString(strCommand, true); ioTestSet.WriteString("SOUR:GPRF:GEN1:STAT ON;*OPC?", true); Thread.Sleep(5000); do { ioTestSet.WriteString("SOUR:GPRF:GEN1:STAT?", true); strReturn = ioTestSet.ReadString(); }while (strReturn.Contains("OPEN") == true); //Set amplitude strCommand = "SOUR:GPRF:GEN1:RFS:LEV " + amplitude + " dBm;*OPC?"; ioTestSet.WriteString(strCommand, true); bDTVON = true; } else { ioTestSet.WriteString("SOUR:GPRF:GEN1:STAT OPEN;*OPC?", true); bDTVON = false; } }
public void SetAgilExmDtvRssiTransmition(String frequency, String amplitude) { string strCommand = string.Empty; string strReturn = string.Empty; ioTestSet = new FormattedIO488(); //EXM try { ResourceManager grm = new ResourceManager(); ioTestSet.IO = (IMessage)grm.Open("AGILENT_EXT", AccessMode.NO_LOCK, 2000, ""); } catch { ioTestSet.IO = null; } if ((ioTestSet != null) && (!bDTVON)) { if ((amplitude == String.Empty) || (Convert.ToDouble(amplitude) > -10)) { throw new DtvGenException("Amplitude must be between -10 to -65 dBm"); return; } if ((frequency == "") || (Convert.ToDouble(frequency) > 803.143) || (Convert.ToDouble(frequency) < 473.143)) { throw new DtvGenException("Frequency must be between 473.143 to 803.143 Mhz."); return; } ioTestSet.WriteString("*IDN?", true); ioTestSet.WriteString("FEED:RF:PORT:OUTP RFIO2;*OPC?", true); Thread.Sleep(100); ioTestSet.WriteString("FEED:RF:PORT:INPUT RFIO2;*OPC?", true); Thread.Sleep(100); ioTestSet.WriteString("SOUR:AM:STAT OPEN;:SOUR:FM:STAT OPEN;:SOUR:PM:STAT OPEN;:OUTP:MOD ON;*OPC?", true); Thread.Sleep(100); ioTestSet.WriteString("*CLS", true); Thread.Sleep(100); ioTestSet.WriteString("SYST:ERR?", true); ioTestSet.WriteString("SOUR:RAD:ARB:STAT OPEN;*OPC?", true); Thread.Sleep(100); ioTestSet.WriteString("SOUR:RAD:ARB:CAT?", true); Thread.Sleep(100); ioTestSet.WriteString("SOUR:RAD:ARB:WAV 'ISDB-Tb_Digital_TV_HD.wfm';*OPC?", true); Thread.Sleep(100); ioTestSet.WriteString("SYST:ERR?", true); ioTestSet.WriteString("SOUR:RAD:ARB:TRIG:TYPE CONT", true); Thread.Sleep(100); ioTestSet.WriteString("SOUR:RAD:ARB:TRIG:TYPE:CONT FREE", true); Thread.Sleep(100); ioTestSet.WriteString("SOUR:RAD:ARB:STAT ON;*OPC?", true); Thread.Sleep(100); ioTestSet.WriteString("SYST:ERR?", true); ioTestSet.WriteString("CORR:CSET4:DESC?", true); Thread.Sleep(100); ioTestSet.WriteString("CORR:CSET4:DEL;*OPC?", true); Thread.Sleep(100); ioTestSet.WriteString("CORR:CSET4:DESC 'Rx RF IO2'", true); Thread.Sleep(100); ioTestSet.WriteString("CORR:CSET4:STAT ON;*OPC?", true); Thread.Sleep(100); ioTestSet.WriteString("CORR:CSET4:DATA:MERGE 587142857,1.75;*OPC?", true); Thread.Sleep(100); ioTestSet.WriteString("CORR:CSET4:COMM 'UUT_RF_CONN2_TO_TESTSET_ALT1_RF';*OPC?", true); Thread.Sleep(100); //Set frequency strCommand = "SOUR:FREQ " + frequency + " MHz;*OPC?"; ioTestSet.WriteString(strCommand, true); Thread.Sleep(100); ioTestSet.WriteString("SOUR:GPRF:GEN1:STAT ON;*OPC?", true); Thread.Sleep(100); do { ioTestSet.WriteString("OUTP?", true); strReturn = ioTestSet.ReadString(); }while (strReturn.Contains("OPEN") == true); strCommand = "SOUR:POW " + amplitude + " dBm;*OPC?"; ioTestSet.WriteString(strCommand, true); bDTVON = true; } else { ioTestSet.WriteString("OUTP OPEN;*OPC?", true); bDTVON = false; } }
static void Main(string[] args) { FunctionsExample DmmClass = new FunctionsExample(); //Create an instance of this class so we can call functions from Main //For more information on getting started using VISA COM I/O operations see the app note located at: //http://cp.literature.agilent.com/litweb/pdf/5989-6338EN.pdf Ivi.Visa.Interop.ResourceManager rm = new Ivi.Visa.Interop.ResourceManager(); //Open up a new resource manager Ivi.Visa.Interop.FormattedIO488 myDmm = new Ivi.Visa.Interop.FormattedIO488(); //Open a new Formatted IO 488 session /* * AGILENT_33220A = "USB0::0x0957::0x0407::MY44021621::0::INSTR" * AGILENT_33522A = "USB0::0x0957::0x2307::MY50003961::0::INSTR" */ try { string AGILENT_33220A = "USB0::0x0957::0x0407::MY44021621::0::INSTR"; string AGILENT_33522A = "USB0::0x0957::0x2307::MY50003961::0::INSTR"; myDmm.IO = (IMessage)rm.Open(AGILENT_33220A, AccessMode.NO_LOCK, 2000, ""); //Open up a handle to the DMM with a 2 second timeout myDmm.IO.Timeout = 500; //You can also set your timeout by doing this command, sets to 3 seconds //First start off with a reset state myDmm.IO.Clear(); //Send a device clear first to stop any measurements in process myDmm.WriteString("*RST", true); //Reset the device myDmm.WriteString("*IDN?", true); //Get the IDN string string IDN = myDmm.ReadString(); Console.WriteLine(IDN); //report the DMM's identity myDmm.WriteString(":OUTP:STAT 0", true); // Disable Output myDmm.WriteString(":SOUR:FREQ:CW 1.1512 MHZ", true); DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors myDmm.WriteString(":SOUR:VOLT:LEV:IMM:AMPL 0.1 VPP", true); DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors myDmm.WriteString(":SOUR:BURS:PHAS 0", true); DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors System.Threading.Thread.Sleep(5000); if (true) { myDmm.WriteString(":SOUR1:BURS:STAT 0", true); DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors } myDmm.WriteString(":SOUR:BURS:NCYC 50000", true); DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors myDmm.WriteString(":SOUR:BURS:INT:PER 0.1 S", true); DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors myDmm.WriteString(":SOUR:FREQ?", true); string FreqRes = myDmm.ReadString(); myDmm.WriteString(":SOUR:BURS:INT:PER?", true); string PeriodRes = myDmm.ReadString(); myDmm.WriteString(":SOUR:VOLT:LEV:IMM:AMPL?", true); string AmplitudeRes = myDmm.ReadString(); myDmm.WriteString(":SOUR:BURS:PHAS?", true); string PhasResult = myDmm.ReadString(); myDmm.WriteString(":SOUR:BURS:NCYC?", true); string NumCycRes = myDmm.ReadString(); DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors Console.WriteLine("Current Values are:" + "Period:" + PeriodRes + "Frequency:" + FreqRes + "Amplitude" + AmplitudeRes + "Phase" + PhasResult + "Cycles" + NumCycRes); myDmm.WriteString(":SOUR1:BURS:STAT 1", true); // Enable Output DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors myDmm.WriteString(":OUTP:STAT 1", true); // Enable Output DmmClass.CheckDMMError(myDmm); //Check if the DMM has any errors } catch (Exception e) { Console.WriteLine("Error occured: " + e.Message); } finally { //Close out your resources try { myDmm.IO.Close(); } catch { } try { System.Runtime.InteropServices.Marshal.ReleaseComObject(myDmm); } catch { } try { System.Runtime.InteropServices.Marshal.ReleaseComObject(rm); } catch { } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } }
private string MeasureFun() { try { ioDmm.WriteString("SYSTem:REMote", true); ioDmm.WriteString("CONF:FRES", true); ioDmm.WriteString("SENS:FRES:OCOM ON", true); ioDmm.WriteString("SENS:FRES:NPLC 10", true); if (checkBoxNull.Checked) { ioDmm.WriteString("FRES:NULL:STAT ON", true); } else { ioDmm.WriteString("FRES:NULL:STAT OFF", true); } ioDmm.WriteString("READ?", true); Pause(3000); return(ioDmm.ReadNumber(IEEEASCIIType.ASCIIType_R4, true).ToString()); } catch { return("Ошибка"); } }
private void btnGetID_Click(object sender, System.EventArgs e) { ioDmm.WriteString("*IDN?", true); this.txtIDString.Text = ioDmm.ReadString(); }
/// <summary> /// 万用表写测量指令 /// </summary> /// <param name="Instructions"></param> public void MultimetersSend(string Instructions) { //m_ioArbFG.WriteString(Instructions + ";*WAI", true); m_ioArbFG.WriteString(Instructions, true); }