02-18-2025 07:11 AM
Hi, help with the implementation of time saving.😿
I want to go to mine.txt file the time data was saved from the moment the button was pressed, not from the moment the coding was started. (i.e., the countdown starts from 0 when the button is true)
As soon as the button is pressed: Data recording stops, the countdown stops, and the countdown resets again to 0 for the new file.
Additional questions: Can you tell me how to implement a good counter? I mean, when the score reaches 60 seconds. The saved file did not show 61..62...120.. seconds, and 1 minute is 1 second, etc. (For example, all 60 minutes are 60 seconds)
How do I organize this in my program?
02-18-2025 10:58 AM
Sorry, I cannot open your VI. Consider "save for previous" (2020 or below) before attaching.
Your picture shows overly complicated Rube Goldberg code. All you need is "built array" for your four values, the write that to file. For relative times, use "high resolution relative seconds". no need to deal with timestamps!
All you need to implement your requirements is a simple state machine. To fix your value precision, don't reduce DBL to integers, right?
02-18-2025 04:07 PM
When you are going as slow as once every 500 msec, you can simplify things a lot. Consider the text (not an "Excel") output (if you use the default extension for the Delimited Spreadsheet, ".csv", Windows will give it an Icon that looks like Excel, and will probably use Excel to open it, but it is simply a "tab-delimited" file (it is not even "comma-separated", unless you make it so)).
Think about what you want to do. You want a file that has one header (4 Text column labels), then every 500 msec, you want to read 4 values and write them as Delimited Spreadsheets, starting at Time = 0.
So first write the header, then (in a While loop, initialized with Time = 0 being held in a Shift register of either an Integer (if you want to count milliseconds) or Dbl (if you want to count seconds) that you initialize to 0 by putting constant 0 outside the left side of the loop and wired to the left Shift Register.
Also initialize your Delimited Spreadsheet (outside the loop on the left) and write the array of 4 Column Labels (in an Array), bringing the file path wire into the While Loop in another Shift Register (you may be able to get away with a tunnel here). So now you have initialized your output. You also want another Shift Register to measure elapsed time, initialized to 0.
Inside the While Loop, generate one row of data. For Time, use the Loop Index ("i") times the Loop Time (500 if you are outputting Time in ms, 0.5 if you are outputting time in seconds). When you enter the loop, the time on the Shift Register is 0 (correct!). Build your array of 4 values (with Time as the first), then add the other three values. Note that you don't need to change the numeric data to Text -- Write Delimited Spreadsheet does that for you (read the Help text for this function). Once you have your 1D array of 4 values, write them to the Delimited Spreadsheet (be sure to wire "T" to "Append to file"). Now all you have to do is (a) increment the "Time Wire" on the Shift Register by 500 or 0.5, and (b) bring the file path wire to its shift register on the right edge. Did you remember to wire an Error Line into the While Loop and through the Write Delimited Spreadsheet? Wire "Stop" to stop the loop, and you are done!
Bob Schor
02-20-2025 12:13 AM
Here's the 2020 version
I recently started learning LabVIEW. Unfortunately, I have not yet found good information on how blocks of clusters, arrays, etc. should work together. Apparently this is such a feature of
LabVIEW - to be ashamed --> to understand --> to develop.
02-20-2025 12:21 AM
Dear Bob_Schor,
I don't quite understand your train of thought yet. Could you please provide a visual example with a more detailed explanation. From what I've managed to understand, it's that you're suggesting using a shift register to count time from a starting point of 0. I was trying to organize such logic using an Event Structure. But the problem there is that by pulling out the button parameters, I can only adjust the register operation for the time the button is press/stop, which does not meet my requirements (Count the time from the moment the button is pressed and the button should not be pressed until the moment when recording needs to stop)
02-20-2025 01:03 AM
Here's a quick draft how to append data to file while the button is true. There are many things not clear, for example in the fist message, you say recording should start when the button is pressed, but in the next sentence you say it should stop. What should happen to the time when you start again during the same run. (start over? Start from last saved time value?)
02-20-2025 03:29 AM
02-20-2025 03:31 AM - edited 02-20-2025 04:04 AM
Could you also explain the logic of the development so that I can better understand how it is implemented correctly?
02-20-2025 05:44 AM
@SeraphimSeth wrote:
I'm sorry that I'm not being precise. I would like the time to reset back to 0 after pressing the button.
You re still not precise. If the time is zero until you press the button and zero right after, it will never be nonzero.
Do you only want to record one row with each press? Do you want to start from zero after the button goes from true to false? Something else?
02-20-2025 05:46 AM
@SeraphimSeth wrote:
Could you also explain the logic of the development so that I can better understand how it is implemented correctly?
Are you replying to any specific post? Maybe start with the learning resources listed at the top of the forum. Use the context help when hovering over any part of the code.