LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to structure code to control multiple instruments

Solved!
Go to solution

Hello,

 

I'm a somewhat novice but not inexperienced labview programmer. I'm in the process of writing a labview code to control an optical physics experiement. This involves writing a GUI which then interfaces with a variety of instruments (such as motorized stages, lock-in amplifiers, power supplies, DAQs, etc...) all connected through various means to the computer. All of the instruments ship with their own labview drivers for carrying out their most important functions. For the most part, the instruments will be operated independently but occasionally, a set of steps involving multiple instruments will be done (such as move, take a measurment, move again, ...)

 

My question is what is the best way to structure the top-level VI where all the GUI controls are located? I currently have the code structured so that every instrument has an associated event structure which handles button presses and controls for it. Simple events such as movement are handled in the event structures themselves while queues and occurences are then used to handle more complicated events in external loops. Is this an appropriate way to handle this scenario or is there a more commonly used architecture?

 

Thank you for the help

0 Kudos
Message 1 of 7
(4,556 Views)
Solution
Accepted by DaveMiller3

You're playing with fire when using multiple event structures. My preferred method for running an instrument that has a "stream" mode (example: a spectrometer where you want to continuously see the spectrum), is to give that it's own loop, with a dequeue element. The "element" can have a message (or state) portion in the form of an enum or string, as well as some data in the form of a variant. Say you want to set a parameter, you could send a cluster containing the "Set Parameter" enum as well as the value of the parameter in the form of a variant. The default case would be to obtain a spectrum and update a graph (or send yet another message to a UI handling loop that updates the graph).

 

You can open up the QMH Project Template that ships with LabVIEW to see how one queue might work, and then you can add multiple queues for different instruments. I keep the new loops in their own SubVIs and the queue reference in a functional global to clean up the main block diagram.

 

Here is an example of what your module stream case might look like (the empty string constant seen as double quotes is default from the dequeue message timing out)

 

module main.png

Message 2 of 7
(4,538 Views)

First!  EXCELLANT question!

 

You stated that you have multiple event loops in the top level vi.  This may be unwise. I'm not looking at your specification documents so, I won't state it as a surity however, generarally it is a poor choice to involve multiple event structures interfacing with a single user.Smiley Wink

 

Have you looked into the Actor Framework?  I typically avoid it because my clients are uncomfortable with it yet, from what you describe, it may be a good choice for you.

 

Another option you may wish to consider is "Simplifying" the GUI.  Some Actions may be combined into a "Do this Sequence" rather than take "These independant Steps" and the USER can assist you greatly in telling the story of how the ideal interface should behave.


"Should be" isn't "Is" -Jay
Message 4 of 7
(4,523 Views)

I would also agree that the Queued Message Handler is the way to go here.  It is very similar to a Producer/Consumer.  But the idea is that you have a loop and a queue for each instrument.  You then just send messages to the insturment handler with the corresponding queue whenever you want something done with that instrument.  Keep each instrument in its own space will make things a lot simpler for you.


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
0 Kudos
Message 5 of 7
(4,509 Views)

Thank you for the helpful replies everyone. The queued message handler definitely seems like the best way to go for this application once I learn how to use it. 

0 Kudos
Message 6 of 7
(4,503 Views)
Also have a look at the DQMH approach: http://sine.ni.com/nips/cds/view/p/lang/hu/nid/213286
Using User Events is very cool, some benefits over a pure Queue solution...
0 Kudos
Message 7 of 7
(4,445 Views)