LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Lock and Unlock with GPIB

I'm currently working with VISA Locks and Unlocks to control calls to two devices on a GPIB.  It's the first time we've implemented the Locks and Unlocks in a program and we still get conflicts which come up with general statements such as "lock can not be found", or "device already locked".

Our code consists of a VISA Open, a VISA Lock, a call to the instrument, a VISA Unlock, and finally a VISA Close each time either device is used.   This code is executed from different While loops which are all running concurrently.  Have I been too naive to think that any and all conflicts will be handled by the Lock and Unlock functions?  Any tricks of the trade to using the Lock and Unlock?

Any suggestions would be greatly appreciated. 

Nick Salemi
Teledyne Energy Systems, Inc.
nick.salemi@teledynees.com
410-891-2257
Nick Salemi
Teledyne Energy Systems, Inc.
nick.salemi@teledynees.com
410-891-2225
0 Kudos
Message 1 of 3
(3,102 Views)
It sounds like your implementation is the actual problem. If the code sequence you're describing is implemented in two independent while loops then I would expect those errors. Why? Because LabVIEW is going to switch back and forth between the two loops. Hence, it can call the VISA Lock and then the VISA Write in one loop, switch to the other loop and call the VISA Lock in the other, but give you an error since you're trying to lock a session that's already locked. You should encapsulate the sequence of Lock->Write->Unlock as a subVI and use the subVI. This will force the sequence to execute as a single operation, blocking the other loop from trying to access the VISA resource until the whole sequence is done.

Note: Why are you opening/closing the device each time? This is not necessary and just leads to overhead. You should open the VISA resource once at the beginning and close it at the end.
0 Kudos
Message 2 of 3
(3,098 Views)
And I wonder if you are applying the correct design pattern. I've only used locks when one or more processes needs to access the same instrument. If you have two separate loops working on two different instruments, then you may want to using one of the synchronization functions such as a notifier or semaphore.
0 Kudos
Message 3 of 3
(3,094 Views)