11-09-2021 10:13 AM
Hi, i'm fairly new to Labview and i'm currently stucked in a problem that i think is very simple but to which i can't find a simple solution.
I'm using a data acquisition device to get measured temperature, force, pressure and i would like to save those data (with header) on a spreadsheet file when i press a button (the "write to file" button in the Vi attached) and stop recording data when unpressed. I can now do this but if i stop and restart the recording the new data are just appended to the previous file without header, so i cannot distinguish when a new recording started.
Actually what i wanted to achive with this Vi was to automatically create a file with a specified name (with header wich is only present one time in it) that is changing to each press of the button and without asking for a new path for every new file.
Is there a way to simply do this?
thank you.
11-09-2021 11:53 AM
In order to create a new file you need the "append to file?" input set to false. Right now you don't have a good way to do this inside the while loop, I'd recommend an event structure, and when the "Write to file" button transitions from false to true, you can start a new file and write the headers.
For the file name, if you want to avoid the pop-up that occurs when you don't wire the input, you will have to think about how you want to generate the name. I prefer to use a timestamp at the beginning of the file, with enough precision so they never duplicate. For example, if I know I'm never going to create 2 files per second, I will use something like "YYYYMMdd_hhmmss_data.txt". There is also a VI you can use called "Create file with incrementing suffix" which will simply add a number to the filename so you don't overwrite anything.
11-09-2021 12:06 PM
Too messy. I'm going to try to follow it.
11-09-2021 02:11 PM
if i don't ask too much, do you have any example of this?
11-09-2021 02:15 PM
@paul_cardinale wrote:
Too messy. I'm going to try to follow it.
Agreed... You really need to rethink your architecture. I know the tutorials make it look like One Big Loop is a valid program architecture. But as you are finding out once you start programming real world applications OBL fails miserably.
A simple State Machine is what you should consider using. Then you can have an "SaveToFile" state that you can easily run when a button is pressed.
11-09-2021 02:28 PM
@Manuel275 wrote:
if i don't ask too much, do you have any example of this?
Sure. Suppose I ask someone to help me set a formal dining table. The person asks me "Where are your plates, utensils, napkins, etc?" So I bring out a large bag containing everything in a big jumble. Then the person says to me: "Get back to me after you've organized that mess."