LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event structure inside while loop preventing the loop from running

Hello everyone,

 

I have a producer/consumer architecture. The producer loop is picking up two channels of DAQ data, the consumer loop is essentially just combing them into an XY graph. I wanted to write all the data to an Excel file when I press a keyboard key. I used the example "Write Table to XL.vi" and put it in an event structure within my consumer while loop. I created a third loop to pick up the keyboard strokes, got all the event stuff set up correctly as far as I can tell.

 

However, now nothing in my consumer loops run. It's a similar issue to this thread (http://forums.ni.com/t5/LabVIEW/Event-structure-inside-while-loop/m-p/843085) but I read through that thread and I couldn't figure out how to fix it.

 

The other issue is that I would like to stop the data sampling when I hit the space bar (or another key). However my keyboard loop just flips false to true when I press the key and it flips back when I release it. Is there a VI that waits for a transient T/F flip then throws a permanent false to stop the producer loop?

 

-Xander

0 Kudos
Message 1 of 17
(3,183 Views)

The big event loop depends on an output from the small while loop on the left. This small while loop never completes, thus your big loop can never start.

 

Why do you use user events? Simply create a plain "key down" event.

0 Kudos
Message 2 of 17
(3,175 Views)

Well of course it stops the loop.  The event structure has to run before the loop can iterate.  You should put the event structure in its own loop.  Store the waveform data in a notifier.  You can then use a Key Down event to look for the spacebar, read the notifier, and save it to your excel sheet.  I would use another notifier for stopping all of the loops.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 17
(3,171 Views)

I went with user events for no particular good reason whatsoever (I'm learning as I go, sometimes grasping at straws). However, I just removed the user events and the whole keyboard loop out to the left and changed it to a Key Down event. The event works perfectly but the While Loop is still paused. I have a filtered rotation waveform chart in the consumer loop that should be outputting signal as soon as I start it. That's how it behaves when there's no event structure in the while loop. If I just delete the entire event structure it starts outputting that waveform again.

0 Kudos
Message 4 of 17
(3,165 Views)

@xander18 wrote:

I went with user events for no particular good reason whatsoever (I'm learning as I go, sometimes grasping at straws). However, I just removed the user events and the whole keyboard loop out to the left and changed it to a Key Down event. The event works perfectly but the While Loop is still paused. I have a filtered rotation waveform chart in the consumer loop that should be outputting signal as soon as I start it. That's how it behaves when there's no event structure in the while loop. If I just delete the entire event structure it starts outputting that waveform again.


That's correct.  Everything in the loop has to finish before it can iterate.  So if no event happens, the event structure will just sit there waiting for an event and block the loop from iterating.  Move the event structure into another loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 17
(3,162 Views)

Okay, the event structure is now in its own while loop and everything is working... EXCEPT the keyboard no longer triggers the event structure. Crossrulz, any particular reason to use notifiers instead of data tunnels?

0 Kudos
Message 6 of 17
(3,155 Views)

Tunnels and wires going between loops creates a data dependancy.  Therefore the loops won't be able to run in parallel, which is what you need.   I said to use a notifier since it only holds the last set of data, which is perfect for your situation.

 

Can you post your latest code so we can see where you are at?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 17
(3,148 Views)

But since I'm trying to output all of the collected data to the Excel spreadsheet wouldn't I need a queue? When you say the last set of data will it be all data collected since I hit the run button?

0 Kudos
Message 8 of 17
(3,144 Views)

Maybe I misunderstood.  I was under the impression you only wanted to save 1 set of data when the spacebar was pressed.  Are you saying you want to save all of the data as long as the spacebar is down?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 17
(3,139 Views)

A little background... This is for an instrumented diesel test engine, I'm trying to create a pressure trace of in cylinder pressure against crank rotation. Eventually I want it to take every other rotation (4 stroke engine) and continually average the pressure traces together so I can run it for a minute or two, gather a few hundred pressure traces, and it spits out one pressure trace for that fuel at that load. That was proving difficult so right now I'm just trying to kick all the data out into Excel so I can do some test runs, make sure everything is working properly, and see what kind of traces are coming out. I'll just run it for awhile, make a scatter plot in Excel, and see what it looks like.

 

The Build XY Graph VI is taking all of my pressure and rotation data points and plotting them against each other. Of course since you don't have the hardware you can't tell but when I run it I can just spin the encoder by hand and put pressure on the transducer it starts spitting data points out all over. Then I'm formatting the data into strings, making an array, and passing it over to the Excel event structure. I want it to output that table of everything I've recorded in that run when I press the space key.

 

Does that make it a little clearer?

0 Kudos
Message 10 of 17
(3,132 Views)