Search code examples
while-loopreal-timelabviewfifo

Best way to stop multiple RT Timed Loops simultaneously?


Background

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.

Current Plan

  1. Stop the low-priority communication loop using the network shared Stop button variable.
  2. Delete all of my RT FIFOs when this loop stops using the RT FIFO Delete VI with the force destroy? input set to True.
  3. Let the high-priority loops shut themselves down the next time they try to read their (now destroyed) FIFOs, which will hopefully cause an error.

This is illustrated in a distilled example below.

Illustrative Example VI

Questions

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!

Update

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.


Solution

  • 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.

    Example VI Front Panel

    Example VI Block Diagram

    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.