LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA - Concurrency on viRead viWrite

I am a newcomer to LabWindows and have been given the task of synching up access to a buffer by two concurrent programs.
 
The basic problem is this:
 
Both programs are performing queries on an instrument using VISA which require the two steps of viWrite followed by viRead.  The obvious problem being that if they are running concurrently, a read by ProgramB could read the result of ProgramA.  I've looked into viLock and viUnlock, but I don't want to have to create a busy-waiting scenario for all VISA function calls.
 
I'm not looking for a solution so much as a point in a general direction.
 
Any ideas?
 
Thanks,
 
Bryan
0 Kudos
Message 1 of 4
(4,686 Views)

If you have the FDS version of CVI then you could use the Critical Section approach in the SDK.

JR

0 Kudos
Message 2 of 4
(4,678 Views)

Windows Critical Section is only effective for multiple threads in a process, not for multiple processes.  It shall be Mutex to synchronise multiple processes.  As for VISA resource-based synchronisation, you can use VISA LOCK feature instead of Windows synchronisation objects.  The following two programs, which query different items (meas:curr? & meas:volt?) with the same instrument, will work correctly without conflict.

// Program [A]
vs = viLock( vi, VI_EXCLUSIVE_LOCK, 2000, NULL, NULL);
vs = viWrite( vi, ":MEAS:CURR?\n", ...snip...);
vs = viRead( vi, buffer, ...snip...);
vs = viUnlock( vi);


// Program [B]
vs = viLock( vi, VI_EXCLUSIVE_LOCK, 2000, NULL, NULL);
vs = viWrite( vi, ":MEAS:VOLT?\n", ...snip...);
vs = viRead( vi, buffer, ...snip...);
vs = viUnlock( vi);

Hope this helps,

Makoto

0 Kudos
Message 3 of 4
(4,664 Views)
Oops, I have now noticed you already considered viLock/viUnlock....
 
In general, an instrument can't process two different queries at the same time.  A good example is ":MEAS:CURR?"  query.  Once the instrument has received this query, no other commands will be accepted until the measurement result completes or aborts.  The only solution is, use INITiate command, if your instrument is SCPI-based and the INITiate command is supported.  Unlike MEASure:XXX? query, in this example, INITiate command initiates the instrument process (or measurement) that may take long time in a back ground operation.  After sending INITiate, your other program can send other query and receive its response, as long as the query/command does not interfere the back ground operation.  To check the completion of INITiate action, you can quickly check *ESR register for OPC bit.  (Though it requires that *OPC command is also sent as like "INITiate;*OPC" )
 
I recommend you to check if your query command also supports background operation that can be initiated by INITiate. 
0 Kudos
Message 4 of 4
(4,663 Views)