LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sharing a VISA refnum between two while loops.

Solved!
Go to solution

Hi my fellow labVIEW folks,

 

I am trying to create a measurement VI with a Queued message handler, with an addition of an acquisition loop  I have two simultanious measurements to conduct:

1. A pressure measurement (1 pressure meter, 1 control valve)

2. A flow measurement (8 pressure meters, 8 flow meters, 8 control valves). 
These will all be connected to 1 bus system (RS-232). 

So I want to have one  main vi in which I can start and stop both measurements separately. I was thinking about sharing the bus system VISA refnum between two parallel while loops, one while loop for the pressure measurement and one for the flow measurement. 

Or should I try to put them both in one while loop and enable the measurements with a case structure around the VISA Read/write?

 

Any help will be greatly appreciated 🙂

2 while loops2 while loops

 

0 Kudos
Message 1 of 26
(4,340 Views)

Are you sure it's a RS-232 bus? RS-232 is point to point and cannot be used to talk to different instruments. May it be a RS-485 instead?

In any case, the serial bus is really serial: you cannot run communications in parallel this way. Do all queries in a single loop.

Second: you do not need the shift register, just wire the VISA resource constant to the VISA functions.

Your example code is very crude (you probably already know this): you don't write anything to the bus and probably you are not initializing shift registers properly (it seems that the resource constant is wired to a tunnel and not to the shift register).

Finally: you probably need to initialize the serial port and close it after the loop is stopped.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 2 of 26
(4,327 Views)

I agree, you should keep this in one loop.  You can run into weird conditions where the reply of one query could end up in the other's read.  There are other ways around this, but keeping it all in a single loop is a lot simpler.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 26
(4,316 Views)

Theoretically you could use this architecture safely, if you add VISA lock/unlock or semaphores around your write-read pairs so that they wouldn't collide with each other.

Message 4 of 26
(4,313 Views)

@arteitle wrote:

Theoretically you could use this architecture safely, if you add VISA lock/unlock or semaphores around your write-read pairs so that they wouldn't collide with each other.


But now it's starting to get Rube-ish.  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 5 of 26
(4,311 Views)

Yes, it is indeed RS-485 communication. I know that you can only send a request and receive 1 datapoint at a time, using hexadecimal commands and the visa write and read function. The problem is that I have around 20 sensors and valves in total. If it were to be in one loop, this would be a very long train of vi's. Of course I could put them in a sub-VI, but there is one problem. 

Ideally I would like to have a separate state machine for measurement type 1, and a separate state machine for measurement type 2, running at the same time in the same vi. This way you can separately start/stop measurements. I understand this could be done using semaphores. 

But if all the VISA commands are in one while loop (as suggested), how do I separate the measurement types if I am to start and stop the measurements at different moments? 

0 Kudos
Message 6 of 26
(4,281 Views)

Yes, it is indeed RS-485 communication. I know that you can only send a request and receive 1 datapoint at a time, using hexadecimal commands and the visa write and read function. The problem is that I have around 20 sensors and valves in total. If it were to be in one loop, this would be a very long train of vi's. Of course I could put them in a sub-VI, but there is one problem. 

Ideally I would like to have a separate state machine for measurement type 1, and a separate state machine for measurement type 2, running at the same time in the same vi. This way you can separately start/stop measurements. I understand this could be done using semaphores. 

But if all the VISA commands are in one while loop (as suggested), how do I separate the measurement types if I am to start and stop the measurements at different moments? 

0 Kudos
Message 7 of 26
(4,281 Views)

Everything is very simple and without any synchronization. Make a request (read and write) in the form of a SubVI. And you can easily call them from different cycles. The function will not be called until the previous call ends.

Labview 4.0, 5.0, 6.1, 8.6, 2009, 2011, 2012, 2014
If you do not know something, ask me.
Message 8 of 26
(4,276 Views)

So I have an example of VISA lock/unlock and the semaphores. Would one of these work?

0 Kudos
Message 9 of 26
(4,259 Views)
Solution
Accepted by topic author San_Punt

I would probably do something along these lines using a Queue and a Notifier

 

Not complete just the bones to start the scheme:

with Main

MAIN.png

Calling a get

GET.png

 

The Query is a simple W/R replae the to string and to data string functions with your device commands

Query.png

 


"Should be" isn't "Is" -Jay
Message 10 of 26
(4,253 Views)