LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best architecture to stream multiple instruments in the background?

Hi there,

 

I'm trying to build a test station with a couple of instruments being read in the background. Sometimes I don't want all of the instruments being read, and I am not sure what is the best way to turn on and turn off the data streaming. Right now I've made a separate queue and a separate loop for each. I can send commands to start streaming or pause each individual loop. It seems to work, but it gets a little cumbersome with 3, 4, or more instruments. Can you please suggest a more elegant way to do this, or is this a good way to do it?

 

queue pic.png

0 Kudos
Message 1 of 18
(4,068 Views)

Take a look at the Queued Message Handler (QMH) either in the labview examples / search online or in the templates - it's an extension of the producer/consumer architecture that allows you to have daemons which you can message individually via a message queue to start/stop running. The best part is that you can launch multiple instances of each one if you have multiple of the same instrument.

 

To launch multiple instances, you need to learn about the Asynchronous Call by Reference node - again - take a look at the examples.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 2 of 18
(4,061 Views)

Hi Sam,

 

I am a little familiar with the QMH (I took the core 3 and advanced architectures class online). After looking at the example, there are 2 things I don't understand. How do I keep the instrument streaming without continuously sending messages? How do I determine which instrument is streaming? For reference, this is the example I am looking at.

 

 

0 Kudos
Message 3 of 18
(4,040 Views)

Your message handler can queue items to itself! Have the 'stream' case re-enqueue itself (remember that you'll need some execution timing!).

 

I tend to want to check things periodically like a timer so I have a 'CheckTimer' case which I keep re-enqueuing and then if it has elapsed I enqueue the 'read' case.


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 4 of 18
(4,037 Views)

If your issue is just the number of queues you have to maintain, I recommend looking making an Action Engine for each queue.  You could then build up an API that calls the AE.  This makes it easier since you don't have to pass the reference everywhere.

 

One of these days I'm going to make a good example of this and post it in the communities...

 

Another option is to use User Events.  That way you just send one event and everybody who is registered for it will recieve the event.  Of course, you will have to add something to the event data to state who the event is for (allowing other loops to ignore it).


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 5 of 18
(4,036 Views)

@Sam_Sharp wrote:

Your message handler can queue items to itself! Have the 'stream' case re-enqueue itself (remember that you'll need some execution timing!).


I actually just use the queue's timeout when I am in the "streaming" mode.  The timeout is normally -1 and when streaming mode is turned on, I set it to whatever I want my loop rate to be.  Since we are talking about instrument communications (which naturally has delays in it), I tend to use 0 for the timeout during streaming mode.  When streaming mode is turned off, the timeout goes back to -1.


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 6 of 18
(4,031 Views)

Thank you Sam and Crossrulz. I would like to try Crossrulz recommendation first because I think it can be easily implemented into my current code. I will consider starting with the QMH in the future though!

0 Kudos
Message 7 of 18
(4,029 Views)

@crossrulz wrote:

@Sam_Sharp wrote:

Your message handler can queue items to itself! Have the 'stream' case re-enqueue itself (remember that you'll need some execution timing!).


I actually just use the queue's timeout when I am in the "streaming" mode.  The timeout is normally -1 and when streaming mode is turned on, I set it to whatever I want my loop rate to be.  Since we are talking about instrument communications (which naturally has delays in it), I tend to use 0 for the timeout during streaming mode.  When streaming mode is turned off, the timeout goes back to -1.


If you set the timeout, how do you know which state it will timeout to? I made a shift register and use a selector when it times out to repeat the previous case, but I think there should be an easier way.

0 Kudos
Message 8 of 18
(4,026 Views)

@Gregory wrote:
If you set the timeout, how do you know which state it will timeout to?

Now, that completely depends on what you are using for your queue data type.  Personally, I use Strings, so the default in an empty string.  So I just have a "Default" case to handle the timeout situation, which is where I do the reading from the instrument and publish the data.

 

If you are using numberics, then 0 will be the default.  So if you are using Enums, make sure that 0 (the first entry) is your "Read Data".


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 9 of 18
(4,007 Views)