11-15-2022 03:20 PM
I'm looking at the NI example project for cRIO RT control, called "LabVIEW Real-Time Control on CompactRIO (RIO Scan Interface)". It uses the Message Queue VI's for messaging from the "worker" loops to the main message handler loop. So what I'm seeing is that the only entity that can read messages, using the Dequeue Message VI, is the main message handling loop. The others can only transmit messages.
What if I wanted the main message handling loop to be able to message back to the worker loops? Could I also throw a Dequeue Message VI in the worker loops? Or would that create undesirable behavior. Because whoever happens to read the queue first will get that message and no one else sees it?
11-15-2022 04:36 PM - edited 11-15-2022 04:38 PM
Or maybe if I want the main loop to be able to message back to the individual VI loops, they each need their own incoming queue? I attached a zip of my test project, or you can look at the screenshots. Also just noticed that Loop 2 is missing it's message queue wire, but lets just pretend that it's there
11-15-2022 04:45 PM
Yes, you can do that, but you'll need timeouts. Remember to "think dataflow"- if your loop is always waiting on a message, it'll never exit that loop until it receives a message.When I do something like this I usually set my "Receive message" timeout to 0 ms, that way it just checks for an incoming message and moves on without doing any waiting.
11-16-2022 10:43 AM
@BertMcMahan wrote:
Yes, you can do that, but you'll need timeouts. Remember to "think dataflow"- if your loop is always waiting on a message, it'll never exit that loop until it receives a message.When I do something like this I usually set my "Receive message" timeout to 0 ms, that way it just checks for an incoming message and moves on without doing any waiting.
Amazing, thank you. Where/how do I set a timeout? These queue functions don't seem to have an input for that
11-16-2022 11:03 AM
I guess what I could do is edit the Dequeue Message VI and add a timeout control input element to it? Where I'm talking about is circled in teal
11-16-2022 04:16 PM
Yes, that's where you'd put it. Those VI's are parts of the template, not "core LabVIEW", so feel free to modify them to specifically fit each project.
Note that you do need SOMETHING that dictates timing. If your loops all just check for a message, then if they have none, check for a new message, etc. then you'll eat up all your processing power with a free-spinning loop. Usually this timing is something like e.g., data acquisition.
If there isn't anything else dictating timing you should use something reasonable, say, 200 ms or so.
Also- you'll want to add a Timed Out? indicator to that as well so the caller loop will know if the request timed out or received an actual message.