LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

stop and start saving in multiple files without stopping run (cdaq)

Hi,

 

I'm very new to Labview.

I'm currently trying to create a Labview program for my CDAQ where I can constantly look at the temperature and RTD plots. I want to leave them running constantly.

From time to time I want to be able to start saving data and stop when I want to without stopping the whole program from running. Whenever I stop saving data I want to save this data in a new file and not the same file as before. Currently I have to stop the whole program from running to create a new file.

Furthermore the time in the saved file should be able to start from 0 when i start saving and reset whenever i stop. Currently I unfortunately only managed to stop the time while it's turned off of saving. Once i restart it will switch to the time the program has started running.

 

Thanks in advance!

0 Kudos
Message 1 of 6
(177 Views)

A couple of comments (related to your being "new to LabVIEW"):

  • Try to avoid using the Dreaded DAQ Assistant (DDA) and its evil Twin, the Dynamic Data Wire (the black-and-white Checkerboard Wire coming out of the DDA).  There are excellent White Papers on DAQmx, and one of the best is "Learn 10 Functions in NI-DAQmx and Handle 80 Percent of your Data Acquisition Applications" (start typing this into a Web Search Engine and you should quickly find it, even if I missed a word or two in the title).  Disregard the first item (about the DDA) and see how simple it is to use MAX and/or the LabVIEW Project to create a DAQmx Task, then "do 80% of your tasks" with a configuration function,a Start function, a read (or write) function in a loop, and a Stop function.
  • Don't use the High Resolution Relative Seconds here.  This is really designed when you want to benchmark (= measure execution time) some LabVIEW code.  The "Date/Time in Seconds" function returns a LabVIEW TimeStamp -- subtracting two TimeStamps (from "Before" and "After") gives you a Dbl related to "elapsed Seconds".
  • You have both a "Date/Time in Seconds" and a "Get Date/Time String" function whose "TimeStamp" input is unwired.  The unwired input means that Get Date/Time String does a second "Date/Time in Seconds", which is silly and might even return a (slightly) different value than the function in your code.  So connect a wire from the output of "Date/Time in Seconds" to "Get Date/Time String".
  • As a general rule, all functions (and sub-VIs that you write) have "default" input values.  Be sure you either wire what you want into the inputs, or know (and accept) the use of the "default value".  For most numeric inuts, the default value iis 0, but for "Date/Time in Seconds", the default value is "Now!".
  • As to saving data, that is most easily done in conjunction with acquiring the data.  Suppose you are (continuously) acquiring data, 1000 points at 1 kHz.  Every second, a new "chunk" of data is acquired that can be graphed and saved to a file.  Consider the file-saving part of the situation, which can exist in several "States" -- not saving, Starting to Save (which involves opening a file), Saving (to an open File), and Stop Saving (either writing the current data as the "last entry" or simply closing the file without writing anything more, your decision).  This "sequence of actions, dependent on some State of the program" is called a State Machine, and is pretty easy to create in LabVIEW with a Case Statement whose Input is the "State" (which can be a number, 0, 1, 2, 3, a String "Idle", "Open", "Write", "Close", or an Enum consisting of the choices Idle, Open, Write, Close.  This might be a little advanced for you, but you can look up State Machines in LabVIEW and (probably) find some simple examples.
  • Another "feature" of the program you are trying to develop is that you have two semi-independent actions going on, acquiring (and displaying) data continously, and saving "chunks" of the data without interfering with the continuous acquisition process.  Sounds like two separate processes working simultaneously, and in parallel.  And LabVIEW supports this, too, in a very natural way -- it is called the "Producer/Consumer Pattern", which you'll learn about soon enough.

Bob Schor

Message 2 of 6
(133 Views)

Thank you for your reply.

I tried converting my code to DAQmx and used 2 different methods.

 

- I'm not too sure on how to use the Date/Time in Seconds instead of my High Resolution Relative Seconds as the first one apprently has the wrong data type to be saved together with the variables. Furthermore I don't understand how I initialise that with "now"?

- I have managed to get both running at the same time (the while loop responsible for saving data and the while loop responsible for showing the data). I don't know though how to "restart" the while loop after I've saved my document once. I thought about putting it in a another case structure and while loop, but then I would constantly get asked if I want to save the document after I've ended the inner while loop. I thought about using a global variable that would turn false after the program has saved once. And would turn true again once the inner loop is started again. But I don't know how to wire that to the case structure or even give a variable a positive or negative value.

You had proposed to use a state machine for that, but I don't know how I would connect the actions of different states with one another.

 

 

 

Many thanks.

 

0 Kudos
Message 3 of 6
(92 Views)

I have now managed to do the last thing I've mentioned to restard my while loop with local variables. I have noticed that it seems that the data my RTD is collecting apparently has some problems with the clock. I put a data example in the attachments. I think that is because of the sample clock I put at the Temperature measurment but not the RTD. When I'm trying to implement a similar clock there I get the error of:

"Possible reason(s):

Specified property cannot be set while the task is running.
Set the property prior to starting the task, or stop the task prior to setting the property.

Property: SampQuant.SampPerChan

Task Name: _unnamedTask<40D6>"

Download All
0 Kudos
Message 4 of 6
(84 Views)

@jolli12 wrote:

- I'm not too sure on how to use the Date/Time in Seconds instead of my High Resolution Relative Seconds as the first one apprently has the wrong data type to be saved together with the variables. Furthermore I don't understand how I initialise that with "now"?


Sorry -- I thought the "Help" for this Function would be more useful.  "Get Date/Time in Seconds" returns "now" in a special LabVIEW 128-bit datum called a "TimeStamp", which represents the number of seconds (and fractional seconds) since 1 Jan 1904 (UTC).  There are functions in the Time Palette that will let you express the TimeStamp as "Date and Time", but you can also "do arithmetic" with it.  So if you save the TimeStamp when you start collecting Data ("Start of Experiment") and get a second TimeStamp when you finish ("End of Experiment"), subtracting the two will give you the Duration of the Experiment.  Since the TimeStamp is already "in Seconds", subtracting two of them gives you a Dbl representing the elapsed time!  Divide by 60 to get "Minutes", by 3600 to get "Hours", etc.

Bob Schor

Message 5 of 6
(70 Views)

There is an alternative route here that will get you farther faster.

  • Create a New Project from Template
  • Choose Continuous Measurement and Logging (DAQmx)
  • Throw out the old code.

This should get you your Pause and Start new File features without any modification as well as 95% of the DAQmx configuration.

 

There will even be a link to the Developer Walk-through video and Documents that will explain how the sections of code work and can be expanded.


"Should be" isn't "Is" -Jay
Message 6 of 6
(66 Views)