10-17-2016 03:28 AM
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
10-17-2016 03:47 AM
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
10-17-2016 05:17 AM
10-17-2016 12:44 PM
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
10-18-2016 02:01 AM - edited 10-18-2016 02:02 AM
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.
10-18-2016 02:10 AM - edited 10-18-2016 02:12 AM
@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:
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...
10-18-2016 02:15 AM
Hi ,
iam attaching a snippet this will solve your issue.just change the reset value to 5000 means 5sec it works
10-18-2016 02:15 AM
Snippet