/// <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 }
/// <summary> /// Set the specified attribute /// </summary> /// <param name="attribute"></param> /// <param name="value"></param> /// <returns></returns> public void SetSessionAttribute(int attribute, int value) { CheckStatus(AgVisa32.viSetAttribute(mSession, attribute, value)); }