LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger Parallel Loop from Event Structure

@ RavensFan

Thank you for your reply. 

 


I truly don't understand how you are using the Notifier.  I see you create it and pass the references to both loops.  In your event structure loop, you never use the reference.  So nothing ever changes.  Your notifier is based on strings, but you don't ever send any strings.

I am trying to use the notifier to trigger and stop the parallel loop for logging.  I inserted a probe right after the "Wait on Notification" function, and I am seeing the "Start Logging" and "Stop Logging" strings, so not sure why you aren't.  I added a Conditional Loop to catch that Cancel on the replace file dialog, but, other than that, I am seeing the string.

 

I know that I can shrink some of this into Sub-VIs, but I want to make sure I have everything working first.  Somehow, this is easier for me to understand right now.  🙂

 

Attached is the updated VI.

0 Kudos
Message 11 of 13
(466 Views)

You've gotten the Block Diagram smaller (congratulations) -- now it only takes 8 laptop screens (two across and 4 down).  Some suggestions:

  • The headers for the .csv and .txt files are almost identical!  Save space by making a (constant) array of the header strings (the first two entries being "Date" and "Time") that you put outside the loop.  Inside, you put it through "Array to Spreadsheet", using either a <tab> or <comma> as the delimiter.  Done.
  • Get the Timeout out of the Event structure.  I'm not certain what it is doing nor how to do it better, but am pretty sure it doesn't belong here.  And it needs to be rethought/rewritten to not "sprawl".
  • Now you can move all of the Event code to the left and make the Event Loop a fraction (10%?) of its former size.
  • Now let's think about the Logging Loop.  As I see it, it has several "States".  Initially, it is "Off" (doing nothing).  At some point, it goes to "Start Logging", and then almost immediately goes to "Log Data" until it finally goes to "Stop Logging".  One way to represent a State Machine is with a While Loop having a Shift Register that holds the State and a Case Statement that uses the State as a Selector to "do the right thing".  Now all you have to do is to set the States and manage State Changes properly.
    • "Off" is simple -- just wire it in from the outside of the State Machine into the Shift Register.  What do you want to do in the "Off" State?  Maybe wait a tenth of a second (so you don't waste all the CPU Time saying "Am I Off?  Am I Off?").
    • Consider the "Start Logging" State, which opens files, selects folders, etc.  Once it is done, it puts "Log Data" onto the Shift Register so when the While loops, it gets "Log Data".
    • The Log Data State doesn't need to do anything to the Shift Register -- it will stay in Log Data unless something changes it.
    • When "Stop Logging" is entered, it should "do its thing" and stop the While Loop.
  • All this is fine, but how do we get into the "Start Logging" or "Stop Logging" States?  This is where a Queue comes in handy.  Suppose you have a Queue and you don't put anything on it.  You have a Dequeue function that you give a very short timeout (so if there's nothing on the Queue, you don't "wait").  If it Times Out, you use the State that's on the Shift Register, but if a new State is on the Queue, you use the State on the Queue (which becomes the new State on the Shift Register).
  • The Start Logging Event now becomes putting "Start Logging" on the Queue, and Stop Logging Event becomes putting "Stop Logging" on the Queue.
  • Now it should work (Famous Last Words ...).

Bob Schor

Message 12 of 13
(458 Views)

@LV_Noob wrote:

@ RavensFan

Thank you for your reply. 

 


I truly don't understand how you are using the Notifier.  I see you create it and pass the references to both loops.  In your event structure loop, you never use the reference.  So nothing ever changes.  Your notifier is based on strings, but you don't ever send any strings.

I am trying to use the notifier to trigger and stop the parallel loop for logging.  I inserted a probe right after the "Wait on Notification" function, and I am seeing the "Start Logging" and "Stop Logging" strings, so not sure why you aren't.  I added a Conditional Loop to catch that Cancel on the replace file dialog, but, other than that, I am seeing the string.

I'm sorry.  I had browsed through all the event cases and never saw where you were setting the notifier. 

 

Now that I look again after seeing your message, I see it was there in event case [13].

0 Kudos
Message 13 of 13
(452 Views)