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(); */ } }
static void Main(string[] args) { // Create a Stopwatch object and capture the program start time from the system. Stopwatch myStpWtch = new Stopwatch(); myStpWtch.Start(); /* * First step: Open the resource manager and assigns it to an object variable */ ResourceManager resource_manager = new ResourceManager(); /* * Second step: Create a FormattedIO488 object to represent the instrument * you intend to communicate with, and connect to it. */ FormattedIO488 my_instrument = new Ivi.Visa.Interop.FormattedIO488(); string instrument_id_string = "GPIB0::18::INSTR"; Int16 timeout = 20000; // define the timeout in terms of milliseconds // Instrument ID String examples... // LAN -> TCPIP0::134.63.71.209::inst0::INSTR // USB -> USB0::0x05E6::0x2450::01419962::INSTR // GPIB -> GPIB0::16::INSTR // Serial -> ASRL4::INSTR Connect_To_Instrument(ref resource_manager, ref my_instrument, instrument_id_string, timeout); /* * Third step: Issue commands to the instrument and receive responses to * be printed to the program console window. */ for (int i = 0; i < 10; i++) { Console.WriteLine(Instrument_Query(my_instrument, "*IDN?")); } /* * Fourth step: Close the instrument object and release it for use * by other programs. */ Disconnect_From_Instrument(ref my_instrument); // Capture the program stop time from the system. myStpWtch.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = myStpWtch.Elapsed; // Format and display the TimeSpan value. string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}:{3:00}.{4:000}", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine("RunTime " + elapsedTime); // Implement a keypress capture so that the user can see the output of their program. Console.WriteLine("Press any key to continue..."); char k = Console.ReadKey().KeyChar; }
private void CApplyBurst_Load(object sender, System.EventArgs e) { DisableControls(); ioArbFG = new FormattedIO488Class(); this.m_functionComboBox.SelectedIndex = 0; this.m_burstnoComboBox.SelectedIndex = 0; }
/* * * 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 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); }
private void GPIB_Meas_Config_Load(object sender, System.EventArgs e) { try { //create the formatted io object ioDmm = new FormattedIO488Class(); } catch (SystemException ex) { MessageBox.Show("FormattedIO488Class object creation failure. " + ex.Source + " " + ex.Message, "GPIBMeasConfig", MessageBoxButtons.OK, MessageBoxIcon.Error); } SetAccessForClosed(); }
public MainFrom() { InitializeComponent(); try { m_ioArbFG = new FormattedIO488(); m_rm = new Ivi.Visa.Interop.ResourceManager(); } catch { MessageBox.Show("请先安装安捷伦IO驱动", "ERROR"); } }
public GpibResponse CreateIO488Object() { try { ioDmm = new FormattedIO488Class(); GpibResponse gr = new GpibResponse("00", "OK", null); return(gr); } catch (SystemException ex) { GpibResponse gr = new GpibResponse("EX", "FormattedIO488Class object creation failure. " + ex.Source + " " + ex.Message, ex); return(gr); } }
private void FormCalibrationPowerLevellTable_Load(object sender, System.EventArgs e) { ioSpectrumAnalyzer = new Ivi.Visa.Interop.FormattedIO488(); button_CP_TBL.Enabled = false; /* * for (int i = 17; i > 0; i--) * { * comboBox_Range.Items.Add(i.ToString()); * } */ cb_region.SelectedIndex = 0; }
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) { } }
public static void SetCV(String a, 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("VOLT " + a, 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 IOPort(string IO_Type, string Addr) { try { //semaphore = new Semaphore(0, 1); Str_IO_interface = IO_Type; switch (IO_Type) { case "GPIB": 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(Addr, 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); break; case "USB": OpenDevice(Convert.ToByte(Addr)); break; case "RJ45": // 网口 break; case "RS232": // 网口 break; default: break; } Connect_flag = true; } catch (Exception me) { //MessageBox.Show(me.Message); log.AdapterLogString(3, me.Message); Connect_flag = false; throw me; } }
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); }
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 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(); } }
static Boolean echoCmd = false; // Set to "true" to echo commands send to the // instrument(s) static void Main(string[] args) { ResourceManager ioMgr = new ResourceManager(); // To list all connected instrument resources, uncomment // the following four lines /*string[] resources = ioMgr.FindRsrc("?*"); * foreach (string n in resources) * { * Console.Write("{0}\n", n); * * }*/ FormattedIO488 myInstr = new Ivi.Visa.Interop.FormattedIO488(); myInstr.IO = (IMessage)ioMgr.Open("TCPIP0::192.168.1.165::inst0::INSTR", AccessMode.NO_LOCK, 20000); // Instrument ID String examples... // LAN -> TCPIP0::134.63.71.209::inst0::INSTR // USB -> USB0::0x05E6::0x2450::01419962::INSTR // GPIB -> GPIB0::16::INSTR // Serial -> ASRL4::INSTR myInstr.IO.Clear(); int myTO = myInstr.IO.Timeout; myInstr.IO.Timeout = 20000; myTO = myInstr.IO.Timeout; myInstr.IO.TerminationCharacterEnabled = true; myInstr.IO.TerminationCharacter = 0x0A; Stopwatch myStpWtch = new Stopwatch(); myStpWtch.Start(); instrWrite(myInstr, "reset()"); // Set to defaults // Enable common-side ohms instrWrite(myInstr, "channel.setcommonside(\"slot1\", channel.ON)"); // Set for 4-wire resistance instrWrite(myInstr, "channel.setdmm(\"101:105\", dmm.ATTR_MEAS_FUNCTION," + " dmm.FUNC_4W_RESISTANCE)"); // Enable offset compensation instrWrite(myInstr, "channel.setdmm(\"101:105\", " + "dmm.ATTR_MEAS_OFFCOMP_ENABLE, dmm.OCOMP_ON)"); // Set a fixed range instrWrite(myInstr, "channel.setdmm(\"101:105\", " + "dmm.ATTR_MEAS_RANGE, 10)"); // Enable averaging instrWrite(myInstr, "channel.setdmm(\"101:105\", " + "dmm.ATTR_MEAS_FILTER_ENABLE, dmm.ON)"); // Set the average count instrWrite(myInstr, "channel.setdmm(\"101:105\", " + "dmm.ATTR_MEAS_FILTER_COUNT, 20)"); // Create the scan instrWrite(myInstr, "scan.add(\"101:105\")"); // Define the scan iterations instrWrite(myInstr, "scan.scancount = 10"); // Define which channels are shown on the instrument front panel instrWrite(myInstr, "display.watchchannels = \"101:105\""); // Start the scan instrWrite(myInstr, "trigger.model.initiate()"); // The following loop determines if a scan iteration has completed // then outputs the readings and channel numbers. Int16 rdgsCnt = 0, extractSize = 5; String sndBuffer = "", rcvBuffer = ""; Int16 startIndex = 1, endIndex = extractSize; do { rdgsCnt = Convert.ToInt16(instrQuery(myInstr, "print(defbuffer1.n)")); if (rdgsCnt >= endIndex) { sndBuffer = String.Format("printbuffer({0}, {1}, defbuffer1, " + "defbuffer1.readings, defbuffer1.channels)", startIndex, endIndex); rcvBuffer = instrQuery(myInstr, sndBuffer); Console.Write("{0}", rcvBuffer); startIndex += extractSize; endIndex += extractSize; } else { Thread.Sleep(500); } } while (endIndex <= 50); // Upon scan completion, report the average and pk-to-pk information // for each channel. Int32 tmpInt = 0; String rcvBuffer2 = ""; for (Int32 j = 1; j <= 5; j++) { tmpInt = j + 100; instrWrite(myInstr, String.Format("myStats = buffer.getstats(defbuffer1, " + "\"{0}\")", tmpInt)); sndBuffer = String.Format("print(myStats.mean)"); rcvBuffer = instrQuery(myInstr, sndBuffer); sndBuffer = String.Format("print(myStats.max.reading - myStats.min.reading)"); rcvBuffer2 = instrQuery(myInstr, sndBuffer); Console.WriteLine("Channel {0} Avg = {1}, Pk2Pk = {2}", tmpInt, rcvBuffer.TrimEnd('\n'), rcvBuffer2.TrimEnd('\n')); } myInstr.IO.Close(); myStpWtch.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = myStpWtch.Elapsed; // Format and display the TimeSpan value. string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}:{3:00}.{4:000}", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine("RunTime " + elapsedTime); Console.WriteLine("Press any key to continue..."); char k = Console.ReadKey().KeyChar; }
private void EZSample_Load(object sender, System.EventArgs e) { ioDmm = new FormattedIO488Class(); SetAccessForClosed(); }
private void CAMmodulation_Load(object sender, System.EventArgs e) { DisableControls(); ioArbFG = new FormattedIO488Class(); this.m_stagelocationComboBox.SelectedIndex = 0; }
static void Main(string[] args) { ResourceManager ioMgr = new ResourceManager(); string[] resources = ioMgr.FindRsrc("?*"); foreach (string n in resources) { Console.Write("{0}\n", n); } FormattedIO488 myInstr = new Ivi.Visa.Interop.FormattedIO488(); ///////////////////////////////////////////////////////////////////////////////////////////////// myInstr.IO = (IMessage)ioMgr.Open("TCPIP0::192.168.1.165::inst0::INSTR", AccessMode.NO_LOCK, 20000); // Instrument ID String examples... // LAN -> TCPIP0::134.63.71.209::inst0::INSTR // USB -> USB0::0x05E6::0x2450::01419962::INSTR // GPIB -> GPIB0::16::INSTR // Serial -> ASRL4::INSTR ///////////////////////////////////////////////////////////////////////////////////////////////// myInstr.IO.Clear(); int myTO = myInstr.IO.Timeout; myInstr.IO.Timeout = 20000; myTO = myInstr.IO.Timeout; myInstr.IO.TerminationCharacterEnabled = true; myInstr.IO.TerminationCharacter = 0x0A; Stopwatch myStpWtch = new Stopwatch(); Stopwatch CHANTIME = new Stopwatch(); myStpWtch.Start(); // Clear any script local to the DAQ6510 which has the name "loadfuncs" instrWrite(myInstr, "if loadfuncs ~= nil then script.delete('loadfuncs') end\n"); // Build the new "loadfuncs" script by defining it then extractin all the functions defined // within the test script file local to this program executable. instrWrite(myInstr, "loadscript loadfuncs\n"); string line; // Load the script file from the path where the Program.cs file resides System.IO.StreamReader file = new System.IO.StreamReader("..\\..\\myTestFunctions.tsp"); while ((line = file.ReadLine()) != null) { instrWrite(myInstr, line); } file.Close(); instrWrite(myInstr, "endscript\n"); // To ensure all the functions written to the instrument become active, we // call the "loadfuncs" script which holds the definitions. Console.WriteLine(instrQuery(myInstr, "loadfuncs()\n")); // Configure the DAQ6510 channel measure attributes DCV and Temperature. Note that we will // calculate current after the scan is complete. String sndBuffer = String.Format("DAQ_ChanConfig(\"{0}\", \"{1}\", \"{2}\")", "101:103", "104:106", "110"); instrWrite(myInstr, sndBuffer); // Configure the DAQ6510 scan attributes. Int16 scanCount = 1300; sndBuffer = String.Format("DAQ_ScanConfig(\"{0}\", {1})", "101:106,110", scanCount); instrWrite(myInstr, sndBuffer); // Tell the DAQ6510 to make a LAN connection to the power supply and configure // it to set the output on and supplying 9V at 1.5A. sndBuffer = String.Format("PSU_Configure(\'{0}\', {1}, {2}, {3})", "192.168.1.28", 9.0, 1.5, 1); instrWrite(myInstr, sndBuffer); //start timer for scan time CHANTIME.Start(); // Trigger the scanning to start. instrWrite(myInstr, "DAQ_Trig()"); // Turn the power supply output off. instrWrite(myInstr, "PSU_Off()"); // Loop until the scan has successfully completed. CheckScanProgress(myInstr); // Scanning timer ending CHANTIME.Stop(); // Ensure that the supply is turned off and the socket connection // is closed. instrWrite(myInstr, "PSU_Disable()"); // Split the main buffer (defbufer1) into separate buffer items where the // individual channel measurments are warehoused. sndBuffer = String.Format("DAQ_ParseReadingBuffer({0})", scanCount); instrWrite(myInstr, sndBuffer); // Extract each buffer's contents and make them local to the controlling PC. Note // that the values for the current channels will hold the current values calculated // local to the DAQ6510. Console.WriteLine(instrQuery(myInstr, "printbuffer(1, voltBuff1.n, voltBuff1)")); Console.WriteLine(instrQuery(myInstr, "printbuffer(1, voltBuff2.n, voltBuff2)")); Console.WriteLine(instrQuery(myInstr, "printbuffer(1, voltBuff3.n, voltBuff3)")); Console.WriteLine(instrQuery(myInstr, "printbuffer(1, currBuff1.n, currBuff1)")); Console.WriteLine(instrQuery(myInstr, "printbuffer(1, currBuff2.n, currBuff2)")); Console.WriteLine(instrQuery(myInstr, "printbuffer(1, currBuff3.n, currBuff3)")); Console.WriteLine(instrQuery(myInstr, "printbuffer(1, tempBuff.n, tempBuff)")); // Output block for the time it took to run just the scan (not including the // output of the buffer) TimeSpan dt = CHANTIME.Elapsed; double dts = dt.Seconds; double dtms = dt.Milliseconds; dtms = dtms / 1000; double totalt = dts + dtms; Console.WriteLine("Scan time elapsed: " + totalt + " Second"); double chanpersec = (7 * 1300) / totalt; // number of channels times number of scans, // then divide by scan time Console.WriteLine("Channels scanned per second: " + chanpersec); myInstr.IO.Close(); myStpWtch.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = myStpWtch.Elapsed; // Format and display the TimeSpan value. string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}:{3:00}.{4:000}", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine("Total Test Run Time " + elapsedTime); Console.WriteLine("Press any key to continue..."); char k = Console.ReadKey().KeyChar; }
private void CArbPulse_Load(object sender, System.EventArgs e) { DisableControls(); ioArbFG = new FormattedIO488Class(); }
// ioDmm = new FormattedIO488Class(); public Instrument() { ioDmm = new FormattedIO488Class(); }
public Form1() { InitializeComponent(); ioDmm = new FormattedIO488(); SetAccessForClosed(); }