/// <summary> /// 返回数值 /// </summary> /// <param name="command"></param> /// <returns></returns> public virtual double VisaRead_double(string command) { double dtmp; _ViError = AgVisa32.viPrintf(_Session, command + "\n"); if (_ViError != 0) { OnchildThreadException("error:" + _InstrNick + _InstrAddr); } string res = ""; try { AgVisa32.viRead(_Session, out res, 15); //string[] resa = res.Split(','); //res = resa[0]; dtmp = double.Parse(res); return(dtmp); } catch (Exception) { OnchildThreadException("error:" + _InstrNick + ":数据采集失败"); return(0); } }
/// <summary> /// Get the specified attribute /// </summary> /// <param name="attribute"></param> /// <returns></returns> public int GetSessionAttribute(int attribute) { int value; CheckStatus(AgVisa32.viGetAttribute(mSession, attribute, out value)); return(value); }
/// <summary> /// This operation reads an 16-bit value from the address location specified in addr. The address /// must be a valid memory address in the current process mapped by a previous MapAddress() call. /// </summary> /// <param name="addr">Specifies the source address to read the value.</param> /// <returns></returns> public short Peek16(IntPtr addr) { short value; AgVisa32.viPeek16(mSession, addr, out value); return(value); }
/// <summary> /// This operation reads an 32-bit value from the address location specified in addr. The address /// must be a valid memory address in the current process mapped by a previous MapAddress() call. /// </summary> /// <param name="addr">Specifies the source address to read the value.</param> /// <returns></returns> public long Peek64(IntPtr addr) { long value; AgVisa32.viPeek64(mSession, addr, out value); return(value); }
/// <summary> /// This operation reads an 32-bit value from the address location specified in addr. The address /// must be a valid memory address in the current process mapped by a previous MapAddress() call. /// </summary> /// <param name="addr">Specifies the source address to read the value.</param> /// <returns></returns> public int Peek32(IntPtr addr) { int value; AgVisa32.viPeek32(mSession, addr, out value); return(value); }
public override double[] VisaReads(string command) { double[] dtmp; _ViError = AgVisa32.viPrintf(_Session, command + "\n"); if (_ViError != 0) { OnchildThreadException("error:" + _InstrNick + _InstrAddr); } string res = ""; AgVisa32.viRead(_Session, out res, 100000); string[] tmp = res.Split(','); dtmp = new double[tmp.Length]; try { for (int i = 0; i < tmp.Length; i++) { dtmp[i] = double.Parse(tmp[i]); } } catch { Console.WriteLine(); } return(dtmp); }
/// <summary> /// Lock the underlying driver. /// /// If the underlying driver requires a "key" (such as VISA's viLock()), use the /// value returned by LockSession() of the first session locked. If this is the /// first call to LockSession for this shared session, the value is the suggested /// value for the key (but the implementation may ignore this and return a /// different value). /// </summary> /// <param name="exclusive">true (VI_EXCLUSIVE_LOCK), false (VI_SHARED_LOCK)</param> /// <param name="timeout">timeout in ms ... not all drivers/sessions use this</param> /// <param name="key">"authorization" to lock this visa session.</param> /// <returns>authorization for other calls to LockSession of a shared session</returns> public string LockSession(bool exclusive, int timeout, string key) { // If not open, report an error... if (mSession == 0) { throw new IOException("Cannot lock a closed VisaSession."); } const int VI_ERROR_TMO = -1073807339; // = 0xBFFF0015 const int VI_ERROR_RSRC_LOCKED = -1073807345; // = 0xBFFF000F StringBuilder buffer = new StringBuilder(256); int error = AgVisa32.viLock(mSession, (exclusive) ? AgVisa32.VI_EXCLUSIVE_LOCK : AgVisa32.VI_SHARED_LOCK, timeout, key, buffer); if (error < 0) { // If someone else has this locked, we get a timeout ... "translate" // that error into "resource locked" if (error == VI_ERROR_TMO) { error = VI_ERROR_RSRC_LOCKED; } AgVisa32Exception.Throw(error); } IsSessionLocked = true; return(buffer.ToString()); }
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> /// 返回数组 /// </summary> /// <param name="command"></param> /// <returns></returns> public virtual double[] VisaReads(string command) { double[] dtmp; _ViError = AgVisa32.viPrintf(_Session, command + "\n"); string res = ""; AgVisa32.viRead(_Session, out res, 1000000); string[] tmp = res.Split(','); dtmp = new double[tmp.Length]; try { for (int i = 0; i < tmp.Length; i++) { dtmp[i] = double.Parse(tmp[i]); } } catch { Console.WriteLine(); } return(dtmp); }
/// <summary> /// 返回数组 /// </summary> /// <param name="command"></param> /// <returns></returns> public virtual double[] VisaReads(string command) { double[] dtmp; _ViError = AgVisa32.viPrintf(_Session, command + "\n"); if (_ViError != 0) { OnchildThreadException("error:" + _InstrNick + _InstrAddr); } string res = ""; AgVisa32.viRead(_Session, out res, 8020); string[] tmp = res.Split(','); dtmp = new double[tmp.Length]; for (int i = 0; i < tmp.Length; i++) { dtmp[i] = double.Parse(tmp[i]); } return(dtmp); }
/// <summary> /// This operation reads an 8-bit value from the address location specified in addr. The address /// must be a valid memory address in the current process mapped by a previous MapAddress() call. /// </summary> /// <param name="addr">Specifies the source address to read the value.</param> /// <returns></returns> public byte Peek8(IntPtr addr) { byte value; AgVisa32.viPeek8(mSession, addr, out value); return(value); }
/// <summary> /// 返回字符串结果 /// </summary> /// <param name="command"></param> /// <returns></returns> public virtual string VisaRead(string command) { _ViError = AgVisa32.viPrintf(_Session, command + "\r\n"); if (_ViError != 0) { OnchildThreadException("error:" + _InstrNick + _InstrAddr); } string res = ""; Thread.Sleep(100); try { AgVisa32.viRead(_Session, out res, 15); //string[] resa = res.Split(','); //res = resa[0]; double dtmp = double.Parse(res); return(dtmp.ToString("f2")); } catch (Exception) { OnchildThreadException("error:" + _InstrNick + ":数据采集失败"); return(""); } }
public string VisaRead_STR(string command) { viError = AgVisa32.viPrintf(session, command + "\n"); string res = ""; AgVisa32.viRead(session, out res, 100); return(res); }
public void VisaWrite(string command) { viError = AgVisa32.viPrintf(session, command + "\n"); if (viError != 0) { throw new Exception("仪表连接错误!"); } }
/// <summary> /// 发送SCPI指令 /// </summary> /// <param name="command"></param> public virtual void VisaWrite(string command) { _ViError = AgVisa32.viPrintf(_Session, command + "\n"); if (_ViError != 0) { throw new Exception("仪表连接错误!"); } }
/// <summary> /// 发送SCPI指令 /// </summary> /// <param name="command"></param> public virtual void VisaWrite(string command) { _ViError = AgVisa32.viPrintf(_Session, command + "\n"); if (_ViError != 0) { OnchildThreadException("error:" + _InstrNick + _InstrAddr); } }
public void Out64(short bar, long barOffset, Int64 writeValue) { int error = AgVisa32.viOut64(mSession, bar, (int)barOffset, writeValue); if (error < 0) { AgVisa32Exception.Throw(error); } }
/// <summary> /// This operation maps in a specified memory space. The memory space that is mapped is dependent on the /// mapSpace (refer to the following table) parameter. The address parameter returns the address in your /// process space where memory is mapped. /// /// Value Description /// ------------ ------------------------- /// VI_A16_SPACE Map the A16 address space of VXI/MXI bus. /// VI_A24_SPACE Map the A24 address space of VXI/MXI bus. /// VI_A32_SPACE Map the A32 address space of VXI/MXI bus. /// VI_A64_SPACE Map the A64 address space of VXI/MXI bus. /// VI_PXI_CFG_SPACE Address the PCI configuration space. /// VI_PXI_BAR0_SPACE – VI_PXI_BAR5_SPACE Address the specified PCI memory or I/O space. /// VI_PXI_ALLOC_SPACE Access physical locally allocated memory /// </summary> /// <param name="mapSpace">Specifies the address space to map. </param> /// <param name="mapOffset">Offset (in bytes) of the memory to be mapped.</param> /// <param name="mapSize">Amount of memory to map (in bytes).</param> /// <param name="accMode">VI_FALSE</param> /// <param name="suggested">If suggested parameter is not VI_NULL, the operating system attempts to map /// the memory to the address specified in suggested. There is no guarantee, /// however, that the memory will be mapped to that address. This operation /// may map the memory into an address region different from suggested.</param> /// <param name="address">Address in your process space where the memory was mapped.</param> public void MapAddress(short mapSpace, int mapOffset, int mapSize, short accMode, IntPtr suggested, out IntPtr address) { CheckStatus(AgVisa32.viMapAddress(mSession, mapSpace, mapOffset, mapSize, accMode, suggested, out address)); }
public void EnableEvent(VisaEvents eventType, EventMechanism mechanism) { //error = AgVisa32.viEnableEvent(mSession, (short)eventType, (short)mechanism, 0); //error = AgVisa32.viEnableEvent(mSession, AgVisa32.VI_EVENT_PXI_INTR, // AgVisa32.VI_HNDLR, 0); //error = AgVisa32.viEnableEvent(mSession, AgVisa32.VI_EVENT_PXI_INTR, // (short)mechanism, 0); CheckStatus(AgVisa32.viEnableEvent(mSession, (int)eventType, (short)mechanism, 0)); }
/// <summary> /// 发送多条SCPI指令 /// </summary> /// <param name="command"></param> public virtual void VisaAllWrite(string[] commands) { for (int i = 0; i < commands.Length; i++) { _ViError = AgVisa32.viPrintf(_Session, commands[i] + "\n"); if (_ViError != 0) { throw new Exception("仪表连接错误!"); } } }
/// <summary> /// 发送多条SCPI指令 /// </summary> /// <param name="command"></param> public virtual void VisaAllWrite(string[] commands) { for (int i = 0; i < commands.Length; i++) { _ViError = AgVisa32.viPrintf(_Session, commands[i] + "\n"); if (_ViError != 0) { OnchildThreadException("error:" + _InstrNick + _InstrAddr); } } }
public void WaitOnEvent(VisaEvents eventType, int timeout) { int outeventtype = 0; int outeventcontext = 0; CheckStatus(AgVisa32.viWaitOnEvent(mSession, (int)eventType, timeout, ref outeventtype, ref outeventcontext)); }
/// <summary> /// Perform an output /// </summary> /// <param name="BAR"></param> /// <param name="offset"></param> /// <param name="value"></param> public void Out32(short BAR, int offset, Int32 value) { if (IsSimulated) { // For now, trivial implementation of simulation ... simply cache the value mSimulatedRegisters[offset] = value; return; } CheckStatus(AgVisa32.viOut32(mSession, BAR, offset, value)); }
/// <summary> /// 返回绝对值结果 /// </summary> /// <param name="command"></param> /// <returns></returns> public virtual string VisaRead_Abs(string command) { _ViError = AgVisa32.viPrintf(_Session, command + "\n"); string res = ""; AgVisa32.viRead(_Session, out res, 10000); string[] resa = res.Split(','); res = resa[0]; double dtmp = Math.Abs(double.Parse(res)); return(dtmp.ToString("f1")); }
public override string VisaRead(string command) { string res = ""; _ViError = AgVisa32.viPrintf(_Session, command + "\n"); AgVisa32.viRead(_Session, out res, 1000); double dtmp = double.Parse(res) * 1000; return(dtmp.ToString("f0")); }
/// <summary> /// Open the underlying driver (VISA, Eiger, whatever) /// /// If you need a shared session (VI_SHARED_LOCK), call Open() with exclusive==false then call LockSession. /// </summary> /// <param name="resource">the VISA resource descriptor. Ignored if simulated is true</param> /// <param name="timeout">I/O timeout in ms ... not all drivers/sessions use this</param> /// <param name="simulated">if true, no connection to hardware will be made</param> /// <param name="exclusive">if true opens session exclusively (VI_EXCLUSIVE_LOCK). if false opens session with no lock (VI_NO_LOCK)</param> public void Open(string resource, int timeout, bool simulated, bool exclusive) { // If already open, report an error... if (IsSimulated || mSession != 0) { throw new IOException("VisaSession is already open"); } mViDesc = resource; mTimeout = timeout; // Cache the resource descriptor -- may be used to open additional sessions to the same resource ResourceDescriptor = resource; Timeout = timeout; mDefaultTimeout = timeout; if (simulated) { // NOTE: if you want control of these values, use MockSession IsSimulated = true; mSlot = 1; mModelCode = 0x1234; mModelName = resource; mSession = resource.GetHashCode(); return; } // Make sure cached values are cleared mSlot = -1; mModelCode = -1; mModelName = string.Empty; CheckStatus(AgVisa32.viOpen( mResourceManager, resource, (exclusive) ? AgVisa32.VI_EXCLUSIVE_LOCK : AgVisa32.VI_NO_LOCK, timeout, out mSession)); // Cache the locked status IsSessionLocked = exclusive; // Use the supplied timeout as the default timeout for I/O operations CheckStatus(AgVisa32.viSetAttribute(mSession, AgVisa32.VI_ATTR_TMO_VALUE, timeout)); // NOTE: DMA default settings ... For Agilent IOLS 16.3.16603 these are // VI_ATTR_DMA_ALLOW_EN 0 // VI_ATTR_SRC_INCREMENT 1 // VI_ATTR_DEST_INCREMENT 1 // VI_AGATTR_DMA_WRITE_THRESHOLD 512 // VI_AGATTR_DMA_READ_THRESHOLD 48 // VI_AGATTR_DMA_CHANNEL -1 }
public Int64 In64(short bar, long barOffset) { Int64 readval; int error = AgVisa32.viIn64(mSession, bar, (int)barOffset, out readval); if (error < 0) { AgVisa32Exception.Throw(error); } return(readval); }
public override void VisaAllWrite(string[] commands) { for (int i = 0; i < commands.Length; i++) { //增加10毫秒延迟 Thread.Sleep(10); base._ViError = AgVisa32.viPrintf(base._Session, commands[i] + "\n"); if (base._ViError != 0) { throw new Exception("仪表连接错误!"); } } }
public void MoveOut8(short bar, long barOffset, int length, Byte[] dataArray) { int error = AgVisa32.viMoveOut8(mSession, bar, (int)barOffset, length, dataArray); if (error < 0) { AgVisa32Exception.Throw(error); } }
public void MoveIn32(short bar, long barOffset, Int32[] data, int numToRead) { int error = AgVisa32.viMoveIn32(mSession, bar, (int)barOffset, numToRead, data); if (error < 0) { AgVisa32Exception.Throw(error); } }