07-30-2015 10:47 AM
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?
07-30-2015 10:59 AM
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.
07-30-2015 11:06 AM
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.
07-30-2015 11:09 AM
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.
07-30-2015 11:09 AM
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).
07-30-2015 11:12 AM
@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.
07-30-2015 11:13 AM
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!
07-30-2015 11:15 AM
@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.
07-30-2015 11:30 AM
@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".
07-30-2015 08:33 PM