LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create new file after interval with serial cable and select sample rate

The goal of my program is to run the program, and then the "Write to measurement file.vi" will start to collect data within a given time. After the time has been reach, and the "Elapsed time.vi" is giving TRUE in the "Time has elapsed" output, then the program will go in a time loop where collection of data will be stopped. After the time loop is finished, then it goes "back to start" and collection of data starts again (I also want it to create a new file when the program runs again). The program is simple. The clock runs and toggles between TRUE and FALSE in the "Case Structure". When FALSE, collect data. When TRUE, do nothing.

'

Here is the problem. It creates too many files while the program is running. It should only be 1 file that it writes to when running, then pause, then create a new file and start writing again. I am able to disable the "Write to measurement file.vi" by giving FALSE to the ENABLE input of the "Write to measurement file.vi" while we are in the time loop (When Case Structure = TRUE). I also want to be able to select a sampling rate.

 

My program is attached below. Thanks in advance!

 

Kristian

0 Kudos
Message 1 of 8
(1,876 Views)

You need to learn how to program state machines in LabVIEW. I would also suggest to learn how to use low level file functions, not that Express one.

 

You should go through the LabVIEW Core 1 training, at the end you will understand how a state machine can be designed: www.ni.com/self-paced-training

0 Kudos
Message 2 of 8
(1,864 Views)
Hi Kristaje, As blokk mentioned you need to use state machine to complete your vi as you requested ,I can't see your code hence it is 2015. Post your code for 2013 version so that i can help and learn the basics
Venugopal
0 Kudos
Message 3 of 8
(1,852 Views)

Hi! Okay, I created a new program with state machines. I'm using a timer for now to switch between the states. The thing now is that I want the program to create a new file each time the "Collect data" state executes. 

 

Kristian

0 Kudos
Message 4 of 8
(1,826 Views)

Okay, I made a solution for creating a new file when it goes back to the "Collect data" state. I made it so that the "write to measurement file.vi" gets a reset at the end of the "Pause" state. I know how to select sampling rate when I'm using the DAQ-Assistant, but not when I use connection through serial cable.

0 Kudos
Message 5 of 8
(1,786 Views)

@kristaje wrote:

Okay, I made a solution for creating a new file when it goes back to the "Collect data" state. I made it so that the "write to measurement file.vi" gets a reset at the end of the "Pause" state. I know how to select sampling rate when I'm using the DAQ-Assistant, but not when I use connection through serial cable.


Not commenting the rest of the code, but for serial you need to do the timing yourself. Note that you have a maximum and quite limited rate in case of serial com, so you cannot really sample fast. If you want to set a constant rate software timed, like 1 Hz, use the "Wait Until Next ms Multiple" function inside your while loop. If the serial read takes less than 1 sec, in this case this function will "round up" the iteration time to 1 sec:

 

wait.png

 

edit: since you need to measure elapsed time, you could just use 100 msec if that fits into the time frame for the above function. In this way you will have seconds timing with 100 msec precision. If you use 1000 msec for the above function, you will either lose or add one more sec to your timing. Anyway, there is plenty of room to improve this code. You would understand much more, if you went through some tutorials, like Core 1-2...

0 Kudos
Message 6 of 8
(1,780 Views)

Hi ,

 iam attaching a snippet this will solve your issue.just change the reset value to 5000 means 5sec it works

Venugopal
0 Kudos
Message 7 of 8
(1,777 Views)

Snippet

Venugopal
0 Kudos
Message 8 of 8
(1,775 Views)