LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA lock vs. Semaphore

Solved!
Go to solution

I have an RS485 converter attached to a serial port a PC.  Different parts of my code need to have access to different devices on the RS485 bus at different times, each running asynchronously.  This necessitates locking the serial port when in use.  I have seen the VISA Lock instruction, but then there are the Semaphore instructions as well.  My question is why would you use the VISA Lock instead of the Semaphore (size=1) and vice versa? 

 

Thanks!!

0 Kudos
Message 1 of 4
(2,751 Views)
Solution
Accepted by topic author NI-hilator

Hello NI-hilator,

 

You can do similar things woth both.

 

VISA Lock will however only lock your actual resource, so that other VISA functions in parallel will not be able to access the same resource.

Semaphore VI's also allow you to synchronize/lock bigger parts of your code. So it will allow you to broaden your "lock".

 

You can also take a look at the following documents:

http://zone.ni.com/reference/en-XX/help/371361H-01/lvinstio/visa_lock_async/

http://zone.ni.com/reference/en-XX/help/371361H-01/glang/semaphore_vis/

http://zone.ni.com/devzone/cda/tut/p/id/7517

 

 

Short: The first one locks the resource itself. The second one will in your case lock a piece of code, but not the resource itself.

 

I hope it makes more sense for you now.

 

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
Message 2 of 4
(2,744 Views)

Whenever I have different parts of code needing to access the same serial port, I set up a separate loop to handle serial port communication.  The different parts of the code will send messages to the serial port loop via a queue.  That way the serial port loop will handle all the messages in turn.  If need the parts of the code to wait for a message to come back, then I will send a notifier reference in the message, and the serial port loop will package up the return data and send it back using the notifier.

Message 3 of 4
(2,726 Views)

Ravens Fan:  thanks for the general tip.  I have done this in the past.

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