public static double ReadDB(string addr, string window, string m1) { int resourceManager = 0, viError; int session = 0; viError = AgVisa32.viOpenDefaultRM(out resourceManager); viError = AgVisa32.viOpen(resourceManager, addr.ToString(), AgVisa32.VI_NO_LOCK, AgVisa32.VI_TMO_IMMEDIATE, out session); System.Threading.Thread.Sleep(100); viError = AgVisa32.viPrintf(session, "CALC:PAR:SEL '" + window + "'" + "\n"); viError = AgVisa32.viPrintf(session, "CALC:" + m1 + ":Y?" + "\n"); string res = ""; AgVisa32.viRead(session, out res, 100); System.Threading.Thread.Sleep(100); AgVisa32.viClose(session); AgVisa32.viClose(resourceManager); double dtmp = double.Parse(res.ToString().Split(',')[0]); return(dtmp); }
/// <summary> /// Construct a VISA session with the specified slot number "fallback register". /// NOTE: the "fallback register" is only used if reading VISA attribute VI_ATTR_SLOT fails /// </summary> /// <param name="slotNumberAddressSpace"></param> /// <param name="slotNumberRegisterAddress"></param> public VisaSession(AddressSpace slotNumberAddressSpace, short slotNumberRegisterAddress) { SlotNumberAddressSpace = slotNumberAddressSpace; SlotNumberRegisterAddress = slotNumberRegisterAddress; lock ( mResourceManagerLock ) { if (mResourceManager == 0) { CheckStatus(AgVisa32.viOpenDefaultRM(out mResourceManager)); } mResourceManagerCount++; } }
/// <summary> /// 建立连接 /// </summary> public virtual void VisaOpen() { _ViError = AgVisa32.viOpenDefaultRM(out _ResourceManager); if (_ViError != 0) { throw new Exception("error:" + _InstrAddr); } _ViError = AgVisa32.viOpen(_ResourceManager, _InstrAddr, AgVisa32.VI_NO_LOCK, AgVisa32.VI_TMO_IMMEDIATE, out _Session); if (_ViError != 0) { throw new Exception("error:" + _InstrAddr); } }
public void VisaOpen(string addr) { viError = AgVisa32.viOpenDefaultRM(out resourceManager); if (viError != 0) { throw new Exception("error:" + addr); } viError = AgVisa32.viOpen(resourceManager, addr, AgVisa32.VI_NO_LOCK, AgVisa32.VI_TMO_IMMEDIATE, out session); if (viError != 0) { throw new Exception("error:" + addr); } }
public static void VisaWrite(string ip, string command) { StringBuilder gpib = new StringBuilder(); gpib = gpib.AppendFormat("TCPIP0::{0}::inst0::INSTR", ip); int resourceManager = 0, viError; int session = 0; viError = AgVisa32.viOpenDefaultRM(out resourceManager); viError = AgVisa32.viOpen(resourceManager, gpib.ToString(), AgVisa32.VI_NO_LOCK, AgVisa32.VI_TMO_IMMEDIATE, out session); System.Threading.Thread.Sleep(100); viError = visa32.viPrintf(session, command + "\n"); System.Threading.Thread.Sleep(100); AgVisa32.viClose(session); AgVisa32.viClose(resourceManager); }
public static void SetMark(string p, string m1, double value) { StringBuilder gpib = new StringBuilder(); gpib = gpib.AppendFormat("TCPIP0::{0}::inst0::INSTR", p); int resourceManager = 0, viError; int session = 0; viError = AgVisa32.viOpenDefaultRM(out resourceManager); viError = AgVisa32.viOpen(resourceManager, gpib.ToString(), AgVisa32.VI_NO_LOCK, AgVisa32.VI_TMO_IMMEDIATE, out session); System.Threading.Thread.Sleep(100); viError = visa32.viPrintf(session, "CALC:" + m1 + ":X " + value + "MHz" + "\n"); System.Threading.Thread.Sleep(100); AgVisa32.viClose(session); AgVisa32.viClose(resourceManager); }
public static void OpenPWR(string p, int dbm) { StringBuilder gpib = new StringBuilder(); gpib = gpib.AppendFormat("TCPIP0::{0}::inst0::INSTR", p); int resourceManager = 0, viError; int session = 0; viError = AgVisa32.viOpenDefaultRM(out resourceManager); viError = AgVisa32.viOpen(resourceManager, gpib.ToString(), AgVisa32.VI_NO_LOCK, AgVisa32.VI_TMO_IMMEDIATE, out session); System.Threading.Thread.Sleep(100); viError = visa32.viPrintf(session, ":OUTPut ON" + "\n"); viError = visa32.viPrintf(session, ":POWer " + dbm + " dBm" + "\n"); System.Threading.Thread.Sleep(100); AgVisa32.viClose(session); AgVisa32.viClose(resourceManager); }
public static bool MmemLoad(string addr, string filename) { try { int resourceManager = 0, viError; int session = 0; viError = AgVisa32.viOpenDefaultRM(out resourceManager); viError = AgVisa32.viOpen(resourceManager, addr.ToString(), AgVisa32.VI_NO_LOCK, AgVisa32.VI_TMO_IMMEDIATE, out session); System.Threading.Thread.Sleep(100); viError = visa32.viPrintf(session, "MMEM:LOAD '" + filename + "'" + "\n"); System.Threading.Thread.Sleep(100); AgVisa32.viClose(session); AgVisa32.viClose(resourceManager); return(true); } catch { return(false); } }