LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write to File on Stop

Two questions here:

 

1. How to I take a continuous semi-infinite number of measurements from start to a push button stop.

 

2. How to get the results to write to file after the stop.

 

My current VI is attached, I have tried different methods but so far can only get it to stop and write to file after a set number of samples.  

0 Kudos
Message 1 of 11
(3,269 Views)

Hi dflynn,

 

1. You already do that: take readings as soon as you start your VI until you stop it…

 

2. Then you should place the WriteFile function after the loop! THINK DATAFLOW!

But: why do you want this? You would need to collect all data in the loop in (possibly) huge arrays - no fun…

 

Btw. do yor really want to ask for a file name in each iteration? Really?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(3,262 Views)

You have "crippled your understanding" (in my humble opinion) by using Express VIs.  Here is what you really want to do:

  1. Open a File for saving your data.
  2. Inside a While loop, generate a piece of the data (say 1000 points at 1KHz, to be continuously generated as long as Stop is not pushed) and append it to the opened Data File.
  3. When you exit the Loop (by pushing Stop), close the file.

The logic is simple when stated this way, but gets "clouded over" when buried within an Express VI.

 

I (almost) never use Express VIs, so it is possible that my "solution" here is not correct, but I think the option "If a file already exists, Append to File" is what you want to do in Express-VI Land.  You also want to Save to One File and Ask User to Choose, but only once.

 

See if that makes a difference.

 

Bob Schor

0 Kudos
Message 3 of 11
(3,258 Views)

The problem is your DAQ Assistant settings.  Your loop will stop when you get an error.  And I'm certain you'll get a timeout error because you are requesting 1 million samples, but at a rate of 5000 Hz.  That would take 200 seconds to acquire, but the default timeout value is 10 seconds.  You'll only windup with 50,000 samples, the function will timeout and the loop will end.

 

Try acquiring a smaller number of samples such as 5000 and it will write data every one second.

 

The next steps you'll need to learn are to get rid of the Express VI's, and perhaps use a producer consumer architecture to separate the file writing from the acquisition.

0 Kudos
Message 4 of 11
(3,257 Views)

Do not read so many samples per iteration.  1M samples at a 5kHz rate is 200 seconds worth of data.  So you can only stop your loop every 3.33333 minutes!  And that is assuming the stop button is read after the read (not likely).  So the delay will be more like 6.5 minutes to stop your VI!  So cut the number of samples to read down to something more like 500.  This would be 100ms worth of data, making your VI a lot more responsive (ie, each iteration of the loop will be 100ms, meaning your stop condition will be checked every 100ms).

 

Also, there is a "Stopped" output of the DAQ Assistant that you should be using to stop your 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 11
(3,250 Views)

Wow thanks for all of the fast answers! I'll break replies up into pieces to try making it easier to follow.

 

GerdW, I should have phrased that differently. Normally my application is testing a product line where I run one or two 4 second tests on a product, then change over to another product and repeat. So yes, as annoying as it is to be asked for a file name each time it works for my application. 

 

I have a different test coming up where I need to compare two products performing a similar task, so my total time is unknown. One could last 10 seconds, the other could last 10 minutes but I have no way of knowing until the tests are run so running the program based off set samples/frequency could get me in trouble as I only have one shot at capturing the data. 

 

I suppose I can turn my frequency way down for this application in an attempt to save memory and speed up the process. I want to hit start, capture data for however long the test runs, then hit stop and export the data rather than relying on a set number of samples. I will be moving the move samples out of the loop as well, sounds like that will solve an issue with my normal testing!

0 Kudos
Message 6 of 11
(3,235 Views)

Bob_Schor, I agree that using Express VIs is kind of cheating and limiting myself but at the moment I am only doing basic data collection so the more simple my program the better. Need to keep it so myself and my fellow mechanical engineers who have never used LabView before can understand. I'll look further into "If a file already exists, Append to File" and see how it will work.

0 Kudos
Message 7 of 11
(3,231 Views)

RavensFan, is there a way to bypass the DAQ Assistant sample settings?

0 Kudos
Message 8 of 11
(3,230 Views)

You can open up the Express VI and change the settings to something else.

 

 But better is to open up the Example Finder and search for the examples using the actual DAQmx functions.

0 Kudos
Message 9 of 11
(3,224 Views)

Crossrulz, if I understand right do you mean that I can create smaller loops, then combine them into one write file to increase performance?

0 Kudos
Message 10 of 11
(3,223 Views)