04-05-2010 09:01 AM
Hello Everyone,
I need some help with the attached VI (created in 8.6.1). I am building a VI that will take data from WSN nodes and save them to files. I am just using this VI to try and debug my file building and naming. You can see the naming convention in the attached VI. I will be taking data points every six seconds and would like to have the data fill down in text files with naming corresponding to the date they are being recorded. I cannot figure out what to wire for the case structure so that the files will build in the correct way (i.e. correct file name, with multiple lines of data).
I appreciate any help that people can give.
Thanks
04-05-2010 09:45 AM
You need to test for the date outside the loop, and run the code to create a new file if the date has changed. In other words, Get Date/Time should be outside, and it should compare the date to the last date where a file was created. If you're on a new day, create a new file.
Aside: You should not use string operations to create paths. Use the Build Path and Strip Path functions. Also, I am assuming that in your "real" VI you don't have the paths hard-coded like that. For instance, the path you provided would work under XP, but would not, for example, work under Windows 7.
04-05-2010 11:33 AM
04-05-2010 12:10 PM
Use the Date and Time functions to read the current time and convert it to a time record. The cluster you get will allow you to get the day of the year (Julean date) which you can use in your application. Keep this value in a shift register and create a new file when this value changes.
04-05-2010 12:19 PM
First of all, you need to add a date to your filename. I suggest using "%m_%d_%Y". Separate the date from the time with a space in your filename creation. Now when wanting to compare the filename with today's date, get today's date with Format Date String, get the file date by extracting the date part, and compare the strings.
04-05-2010 12:50 PM
Here is what I have right now. It appears to all be working except for one detail. I think it has to do with someones advice from above about looking for the date outside of the loop (which i could not figure out how to do successfully). When i create my data files with this vi, the last point in the data file really belongs on the data file a day ahead (ex. the last two points of file 04/05/10 would have 11:59:55 PM and 12:00:01 AM instead of 12:00:01 AM being in file 4/06/10 ). Anyway, the file i have attached seems to work...mostly. But i do think there is a cleaner way to successfully perform my task. Any advice would be helpful.
04-05-2010 12:58 PM
I wouldn't use the "Value has changed" vi. It is a lot of VI there for what is a simple comparison operation.
Initialize your shift register with a value such as 0 or -1. Do the comparison ahead of the case structure with the current time's day of year to the value in the shift register. You get that carry over because you feed the day of year into the shift register at the end, so the day changes in one iteration, but doesn't get looked at until the next iteration.
04-05-2010 01:19 PM
04-05-2010 01:33 PM
lockesmith wrote:Here is what I have right now. It appears to all be working except for one detail. I think it has to do with someones advice from above about looking for the date outside of the loop (which i could not figure out how to do successfully).
Sorry. I meant to say "outside the case structure in the loop".
Try something like this:
04-05-2010 01:34 PM