private void Form1_Load(object sender, EventArgs e) { HandleRef Instrument_Handle = new HandleRef(); TLPM searchDevice = new TLPM(Instrument_Handle.Handle); uint count = 0; string firstPowermeterFound = ""; try { int pInvokeResult = searchDevice.findRsrc(out count); if (count > 0) { StringBuilder descr = new StringBuilder(1024); searchDevice.getRsrcName(0, descr); firstPowermeterFound = descr.ToString(); } } catch (Exception ex) { } if (count == 0) { searchDevice.Dispose(); return; } tlpm = new TLPM(firstPowermeterFound, false, false); //tlpm = new TLPM("USB0::0x1313::0x8072::P2010125::INSTR", false, false); // For valid Ressource_Name see NI-Visa documentation. double powerValue; int err = tlpm.measPower(out powerValue); }
public bool MyInit(string keywords) { try { HandleRef Instrument_Handle = new HandleRef(); TLPM searchDevice = new TLPM(Instrument_Handle.Handle); uint count = 0; int pInvokeResult = searchDevice.findRsrc(out count); if (count == 0) { searchDevice.Dispose(); return(false); } for (uint i = 0; i < count; i++) { StringBuilder descr = new StringBuilder(1024); searchDevice.getRsrcName(i, descr); if (descr.ToString().Contains(keywords)) { tlpm = new TLPM(descr.ToString(), false, false); return(tlpm != null); } } return(false); } catch (Exception ex) { return(false); } }
public override bool Init() { try { HardwareCfgManager hardwareCfg = ConfigMgr.HardwareCfgMgr; if (Config.ConnectMode.ToUpper() == @"COMPORT") { foreach (var it in hardwareCfg.Comports) { if (it.PortName == Config.PortName) { comportCfg = it; } } comPort = new System.IO.Ports.SerialPort(); if (comPort != null && comportCfg != null) { GetPortProfileData(comportCfg); comPort.PortName = comportData.Port; comPort.BaudRate = comportData.BaudRate; comPort.Parity = comportData.parity; comPort.StopBits = comportData.stopbits; comPort.DataBits = comportData.DataBits; comPort.ReadTimeout = comportData.Timeout; comPort.WriteTimeout = comportData.Timeout; if (comPort.IsOpen) { comPort.Close(); } comPort.Open(); return(comPort.IsOpen); } return(false); } else if (Config.ConnectMode.ToUpper() == @"NIVISA") { HandleRef Instrument_Handle = new HandleRef(); TLPM searchDevice = new TLPM(Instrument_Handle.Handle); uint count = 0; int pInvokeResult = searchDevice.findRsrc(out count); if (count == 0) { searchDevice.Dispose(); return(false); } foreach (var it in hardwareCfg.NIVisas) { for (uint i = 0; i < count; i++) { StringBuilder descr = new StringBuilder(1024); searchDevice.getRsrcName(i, descr); if (descr.ToString().Contains(it.KeyWord1)) { tlpm = new TLPM(descr.ToString(), false, false); return(tlpm != null); } } } } return(false); } catch (Exception ex) { return(false); } }