05-29-2012 10:24 AM
Hello, I got a problem with the time in the saved file. I would like it to always start from 0 till the end (can be over 60 seconds). Here is the VI I already have but the data saved in the file is starting from the current time (only second). How can I adjust my code to make it start from 0 till the program stops without returning to zero again. For example ; 0, 1, 2, 3,....100.
I also attached the saving format too. It should start from zero instead of the current second
Solved! Go to Solution.
05-29-2012 10:44 AM - edited 05-29-2012 10:44 AM
You should keep track of the time (and the timing) in the calling program. At program start, get time in seconds (before the loop) and then do the same inside the loop and always subtract the start value.
If the loop runs at a constant pace, you can also calculate the seconds from the wait value and the iteration terminal value.
05-29-2012 10:50 AM
Here is an example of how you can keep track of time from some known starting point. I also included the delta time as well.
You also have some weird stuff in your code. Given that you have the wait outside of any loop I can only assume that you are using thr run continuously to execute the code repeatedly. This is not the way you would run a program continuously. It should only be used for debugging purposes, if at all. I can't even remember the last time I used run continuously.
05-29-2012 11:09 AM
@Mark_Yedinak wrote:
Given that you have the wait outside of any loop I can only assume that you are using thr run continuously to execute the code repeatedly.
Since the VI has connectors defined and the data comes from a control, this is a subVI. One row is appended to the file with each call.
(As I mentioned, It is odd to have the loop timing defined by a subVI, that belongs into the main program.)
05-29-2012 02:31 PM
Yes it's a sub VI. Should I add a for loop to my vi? I think when I add a for loop, it might affect something in my main VI
05-29-2012 02:41 PM
The only answer I can give is "I don't know." The answer to your question depends on what exactly you want to happen. If you leave this as a subVI I would recommend removing the timing from it. Let the caller determine when and how quickly it should be called.
Also, depending on how much data you plan to write and how often you may consider having a separate task to handle the logging. This task would get data to be logged via a queue. As a separate task the file access will not impact your processing and you can buffer data and reduce the number of times you access the file. File access is generally slow. Writing a few dozen bytes thousands of times will be slower than buffer up the data and writing data only after you have reached some size or time threshold. This would reduce the disk thrashing on the system. If on the other hand you are writing a small amount of data infrequently it really doesn't matter.
05-29-2012 02:42 PM
You've already got a loop in your main VI. Please pay attention to what was said. That is where the initial time is set to 0 and incremented.
05-29-2012 02:58 PM
I must amit that I don't see the point in having the two for-loops. They make no sense to me.
First you make an array with a string of the combind Name and Position.
Then you take each Name and Position and combind them again and search the string array for the combind value.
The index you get are you using to replace an element in an array with the value.
To me it looks lige the same as:
Or is there something I have missed ?
05-29-2012 03:15 PM
Yeah your new vi looks quite the same as mine, not sure if it is exactly the same. I am still struggling to get the time starting from 0. I tried to put Get Date/ Time in Seconds before the second for loop and inside the second for loop, then subtracted each other and then wired the result to Format Date time String. Only 0 appeared in my text file.
05-29-2012 03:43 PM
You STILL don't get it. ALL OF THE TIME FUNCTIONS SHOULD BE DONE IN YOUR MAIN WHILE LOOP! Stop screwing around with the subVI and pay attention to the answers you have been given.