LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Save data starting with 0 second

Solved!
Go to solution

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

 

 

Download All
0 Kudos
Message 1 of 36
(2,992 Views)

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.

0 Kudos
Message 2 of 36
(2,976 Views)

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.

Delta Time.png

 

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 3 of 36
(2,972 Views)

@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.)

0 Kudos
Message 4 of 36
(2,960 Views)

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

0 Kudos
Message 5 of 36
(2,939 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 36
(2,933 Views)

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.

0 Kudos
Message 7 of 36
(2,932 Views)

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.

 

Original.png

 

 

To me it looks lige the same as:

Changed.png

 

Or is there something I have missed ?

 

0 Kudos
Message 8 of 36
(2,924 Views)

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.

0 Kudos
Message 9 of 36
(2,919 Views)

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.

0 Kudos
Message 10 of 36
(2,906 Views)