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 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); }
public MainFrom() { InitializeComponent(); try { m_ioArbFG = new FormattedIO488(); m_rm = new Ivi.Visa.Interop.ResourceManager(); } catch { MessageBox.Show("请先安装安捷伦IO驱动", "ERROR"); } }
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); } }
private void m_setioButton_Click(object sender, System.EventArgs e) { this.rm = new ResourceManager(); try { this.msg = (rm.Open(this.m_gpibAddrTextBox.Text, Ivi.Visa.Interop.AccessMode.NO_LOCK, 2000, "")) as IMessage; ioArbFG.IO = msg; } catch (SystemException ex) { MessageBox.Show("Open failed on " + this.m_gpibAddrTextBox.Text + " " + ex.Source + " " + ex.Message, "AM Modulation", MessageBoxButtons.OK, MessageBoxIcon.Error); DisableControls(); ioArbFG.IO = null; return; } //Get the ID string of the instrument connected. m_idLabel.Text = GetInstrumentID(); }
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); }
public bool Open(out string message) { message = ""; try { // create the resource manager Ivi.Visa.Interop.ResourceManager mgr = new Ivi.Visa.Interop.ResourceManager(); // create the formatted io object myN1010A = new FormattedIO488Class(); //Nếu bị báo lỗi FormattedIO488Class này thì phải vào Property của Reference Ivi.Visa.Interop -> Set "Embed Interop Type" = False; // open IO driver session myN1010A.IO = (IMessage)mgr.Open(this._visaAddress); //set timeout myN1010A.IO.Timeout = 20000; //set termination character to CHR(10) (i.e. "\n") //enable terminate reads on termination character myN1010A.IO.TerminationCharacter = 10; myN1010A.IO.TerminationCharacterEnabled = true; // return(true); } catch { return(false); } }
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); } }
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 void Gpib_connect(object sender, RoutedEventArgs e) { rm = new ResourceManager(); try { msg = (rm.Open(GPIB_Address_Input.Text, AccessMode.NO_LOCK, 2000, "")) as Ivi.Visa.Interop.IMessage; ioArbFG.IO = msg; } catch (SystemException ex) { MessageBox.Show("Open failed on " + GPIB_Address_Input.Text + " " + ex.Source + " " + ex.Message, "ApplyBurst"); ioArbFG.IO = null; } Status_Output.Content = GetInstrumentID(); }
//check and open(close) session private void CheckSession(string addr,Label instrtag, ResourceManager rm, ref IMessage sesn) { instrtag.Visible = true; try { if (rm == null) { rm = new Ivi.Visa.Interop.ResourceManager(); sesn = (IMessage)rm.Open(addr, AccessMode.NO_LOCK, 0); sesn.Timeout = 2000; instrtag.BackColor = Color.SpringGreen; } } catch (System.Runtime.InteropServices.COMException exp) { instrtag.BackColor = Color.Pink; } }