/// <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 void Out64(short bar, long barOffset, Int64 writeValue) { int error = AgVisa32.viOut64(mSession, bar, (int)barOffset, writeValue); if (error < 0) { AgVisa32Exception.Throw(error); } }
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 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); } }
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 MoveIn8PageAligned(short bar, long barOffset, int numBytesToRead, byte[] inData, int offset) { IntPtr inArrayUnmanaged = (IntPtr)0; lock ( mVirtualMemoryLock ) { int num32BitWords = numBytesToRead / 4; if ((numBytesToRead & 0x3) != 0) { num32BitWords++; } if (mVirtualMemorySize < num32BitWords) { // Need more memory ... release the current memory if (mVirtualMemory != (IntPtr)0) { VirtualFree(mVirtualMemory, (UIntPtr)0, (uint)MemoryFreeType.MEM_RELEASE); } // NOTE: this allocation allocates memory in units of pages. It is // assumed that the pages are evenly divisible by 8 bytes. mVirtualMemory = VirtualAlloc((IntPtr)null, (UIntPtr)(num32BitWords * sizeof(int)), AllocationType.COMMIT, MemoryProtection.READWRITE); if (mVirtualMemory == (IntPtr)0) { mVirtualMemorySize = 0; AgVisa32Exception.Throw(AgVisa32.VI_ERROR_ALLOC); } mVirtualMemorySize = num32BitWords; } int error = AgVisa32.viMoveIn32(mSession, bar, (int)barOffset, num32BitWords, inArrayUnmanaged); if (error < 0) { AgVisa32Exception.Throw(error); } Marshal.Copy(inArrayUnmanaged, inData, offset, numBytesToRead); } }
public byte[] MoveIn8(short bar, long barOffset, int numBytesToRead) { byte[] buf8 = new byte[numBytesToRead]; int error = AgVisa32.viMoveIn8(mSession, bar, (int)barOffset, numBytesToRead, buf8); if (error < 0) { AgVisa32Exception.Throw(error); } return(buf8); }
public Int32[] MoveIn32(short bar, long barOffset, int numToRead) { Int32[] buf32 = new Int32[numToRead]; int error = AgVisa32.viMoveIn32(mSession, bar, (int)barOffset, numToRead, buf32); if (error < 0) { AgVisa32Exception.Throw(error); } return(buf32); }
public void Out32(short bar, long barOffset, Int32 writeValue) { if (IsSimulated) { // For now, trivial implementation of simulation ... simply cache the value mSimulatedRegisters[(int)barOffset] = writeValue; return; } int error = AgVisa32.viOut32(mSession, bar, (int)barOffset, writeValue); if (error < 0) { AgVisa32Exception.Throw(error); } }
public Int32[] MoveIn32PageAligned(short bar, long barOffset, int numToRead) { Int32[] inArray; lock ( mVirtualMemoryLock ) { if (mVirtualMemorySize < numToRead) { // Need more memory ... release the current memory if (mVirtualMemory != (IntPtr)0) { VirtualFree(mVirtualMemory, (UIntPtr)0, (uint)MemoryFreeType.MEM_RELEASE); } // NOTE: this allocation allocates memory in units of pages. It is // assumed that the pages are evenly divisible by 8 bytes. mVirtualMemory = VirtualAlloc((IntPtr)null, (UIntPtr)(numToRead * sizeof(int)), AllocationType.COMMIT, MemoryProtection.READWRITE); if (mVirtualMemory == (IntPtr)0) { mVirtualMemorySize = 0; AgVisa32Exception.Throw(AgVisa32.VI_ERROR_ALLOC); } mVirtualMemorySize = numToRead; } int error = AgVisa32.viMoveIn32(mSession, bar, (int)barOffset, numToRead, mVirtualMemory); if (error < 0) { AgVisa32Exception.Throw(error); } inArray = new Int32[numToRead]; Marshal.Copy(mVirtualMemory, inArray, 0, numToRead); } return(inArray); }
public void MoveOut32PageAligned(short bar, long barOffset, int length, Int32[] dataArray, int dataOffset = 0) { lock ( mVirtualMemoryLock ) { if (mVirtualMemorySize < length) { // Need more memory ... release the current memory if (mVirtualMemory != (IntPtr)0) { VirtualFree(mVirtualMemory, (UIntPtr)0, (uint)MemoryFreeType.MEM_RELEASE); } // NOTE: this allocation allocates memory in units of pages. It is // assumed that the pages are evenly divisible by 8 bytes. mVirtualMemory = VirtualAlloc((IntPtr)null, (UIntPtr)(length * sizeof(int)), AllocationType.COMMIT, MemoryProtection.READWRITE); if (mVirtualMemory == (IntPtr)0) { mVirtualMemorySize = 0; AgVisa32Exception.Throw(AgVisa32.VI_ERROR_ALLOC); } mVirtualMemorySize = length; } Marshal.Copy(dataArray, dataOffset, mVirtualMemory, length); int error = AgVisa32.viMoveOut32(mSession, bar, (int)barOffset, length, mVirtualMemory); if (error < 0) { AgVisa32Exception.Throw(error); } } }