03-16-2012 01:45 PM - edited 03-16-2012 01:45 PM
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!!
Solved! Go to Solution.
03-16-2012 02:37 PM
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.
03-17-2012 04:41 PM
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.
04-03-2012 12:17 PM
Ravens Fan: thanks for the general tip. I have done this in the past.