Reputation: 12928
I have a real-time application, RT Main
, that has multiple high-priority timed loops running some simulation code and using RT FIFOs to communicate with a low-priority communication loop that talks with an outside program. I also have a monitoring VI, DT Main
, running on a non-real-time desktop that I use to start and stop the real-time simulation, load parameter files, that sort of thing.
Currently I am passing the Stop
button from DT Main
to RT Main
via a network shared variable. What I want to know is: how can I use this to stop all of my loops on RT Main
at (close to) the same time?
I know I could use a FIFO-enabled network shared variable in my Timed Loops, but I am worried that with multiple loops reading from the same FIFO, I would only stop one or two of them and then the FIFO would be cleared and the other loops would not stop.
Stop
button variable.RT FIFO Delete
VI with the force destroy?
input set to True
.This is illustrated in a distilled example below.
I have two questions: will this work? And regardless of whether this works, what is the "right" way to stop multiple high-priority Timed Loops in a real-time application in LabVIEW?
I can't figure out whether the RT FIFO Read
and RT FIFO Write
VIs will throw an error if they try to read/write from/to a FIFO that isn't there. There is an RT FIFO error code -2206 "RT FIFO does not exist" that I would assume gets thrown in these cases, but I cannot test it right now (no hardware to run this on yet) and so I cannot verify.
For the record, I have found the NI LabVIEW for CompactRIO Developer's Guide pretty helpful so far, but it does not seem to get into enough detail to answer my question.
Thanks!
I was able to test the code and verify that I can stop multiple Timed Loops in this way, but I would still be interested in hearing what your best method is for shutting down a remote RT VI with multiple loops at the press of a button on your desktop VI.
Upvotes: 2
Views: 1578
Reputation: 324
The concern with timed loops is keeping everything deterministic.
The other option for deterministic comms you have is using shared variables with RT FIFO enabled. If you set this to be a single element FIFO it still works like a normal variable.
I believe this can directly be a network variable as well without any problems, or sometimes I like to keep internal comms internal and have another loop that will read the network variable and write it to the internal variable to reduce coupling between the host and RT target implementation.
This allows for a more explicit stop function in the software which increases flexibility and readability as well. See the image for an example:
Upvotes: 2
Reputation: 590
This is going to be the best way to do this and is a cross-platform Producer-Consumer pattern. One suggestion I have is do not use the Force Destroy
option when destroying the FIFOs. It would be best to keep track of the FIFOs individually and make sure you are destroying all instances properly rather than just atomically eliminating all references to the FIFO. From what I can see in your application, you are not creating named FIFOs, so there should be no need to atomically destroy all instances of the FIFO.
Cheers, Matt
Upvotes: 1
Reputation: 12928
The example code works for shutting down multiple Timed Loops simultaneously using errors from the destroyed FIFOs. I was able to verify it with the VI shown below.
I would still be interested in hearing your best solution for stopping an RT VI with multiple loops from a single stop button on your desktop VI.
Upvotes: 1