LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving data file at end of program with incremental suffix

Solved!
Go to solution

Hi all,

 

so I wrote a SubVi that 'initializes' by creating a file under a specific name (serial number) and then during the course of the program another subvi finds and open the data file and writes and closes constantly and repeat. It all works fine. However, because reasons, the customer would like the following sequence of things to be done instead:

 

1) Program start, test runs

2) Write data to file (without first defining the serial number)

3) When test specimen is within given limits, a serial number is allocated to it and data file saved

4) The process repeats and the next serial number is incremental (the index doesn't necessarily start at zero though so if e.g. the first serial number is 7452113, the next would be 7452114 and so on)

 

5) If it's a fail though, the user is able to repeat the test and the serial number doesn't change to the next increment

 

Unfortunately, the text data is built with the format of   

 

Serial. no;Timestamp;Data point A;identifier

Serial. no;Timestamp;Data point B;identifier

Serial. no;Timestamp;Data point C;identifier

Serial. no;Timestamp;Data point A;identifier

 

So in the beginning, by allocating the serial number first, it's relatively simple to continuously write and save the text data. However with these new requirements, I feel like I would have to allocate a dummy number at first and replacing every data line at the end with the correct serial number. 

 

Is there another way to do this without overhauling my entire program? Also in the event that the program doesn't run to completion or the computer crashes or wtv, all data prior to that should also have been saved, so I can't just store data  (in an array or similar) without saving first 

 

Thanks in advance!

 

0 Kudos
Message 1 of 7
(2,402 Views)
Solution
Accepted by topic author nikvl

Hi nik,

 


@nikvl wrote:

1) Program start, test runs

2) Write data to file (without first defining the serial number)

3) When test specimen is within given limits, a serial number is allocated to it and data file saved

4) The process repeats and the next serial number is incremental (the index doesn't necessarily start at zero though so if e.g. the first serial number is 7452113, the next would be 7452114 and so on)

5) If it's a fail though, the user is able to repeat the test and the serial number doesn't change to the next increment


You can also allocate a serial number before step 2:

  • you can write to your file with correct serial number, no need to edit the file afterwards
  • when the test fails you just delete the created file
  • when the test succeeds you keep the file
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(2,385 Views)

How is the serial number defined assuming the test passes?

If it is calculated only from previous tests (i.e. incremented) then you can easily go ahead as GerdW described (including deletion if necessary, so that the repeat doesn't increment).

 

If it depends on the results in some way, you may need a temporary file. If you at least know the length of the serial number, it may be possible to replace it within a finished file without having to rewrite quite as much, although I'm not sure this would be better than simply rewriting the file...


GCentral
0 Kudos
Message 3 of 7
(2,358 Views)

@cbutcher wrote:

How is the serial number defined assuming the test passes?

If it is calculated only from previous tests (i.e. incremented) then you can easily go ahead as GerdW described (including deletion if necessary, so that the repeat doesn't increment).

 

If it depends on the results in some way, you may need a temporary file. If you at least know the length of the serial number, it may be possible to replace it within a finished file without having to rewrite quite as much, although I'm not sure this would be better than simply rewriting the file...


The serial numbers are predetermined and depends on a so-called order number but they aren't allocated to any test cycle yet at the beginning. For example order A could be five test cycles starting from 2020010 (so it goes until 2020014) while the next order B could be 20 test cycles with serial numbers starting from 7999999 (until 8000018).

 

So if we take A as example, the first test cycle is a pass (and does depends on the results of the test), so it's (the data file, that is) given the serial number of 2020010, the next is a fail so it doesn't get the next serial number and if the third one passes it would get 2020010 and so on, and it shouldn't blindly perform increment exceeding 2020014 either... and all of this needs to run without additional input from the user (other than the starting serial number and number of test cycles probably right at the beginning)

0 Kudos
Message 4 of 7
(2,346 Views)

Then go ahead with GerdW's plan - write the first file (using your A example) as 2020010 regardless of pass or fail, and if you pass, increment the value for the next test and start it with 2020011. If you fail, go on to the next test but delete file 2020010 and then write again to 2020010.


GCentral
0 Kudos
Message 5 of 7
(2,343 Views)

@nikvl wrote:

So if we take A as example, the first test cycle is a pass (and does depends on the results of the test), so it's (the data file, that is) given the serial number of 2020010, the next is a fail so it doesn't get the next serial number and if the third one passes it would get 2020010 and so on, and it shouldn't blindly perform increment exceeding 2020014 either... and all of this needs to run without additional input from the user (other than the starting serial number and number of test cycles probably right at the beginning)


Sounds like GerdW gave you the way to go then.  You know what the serial number will be if the UUT passes.  So just write the file assuming it will pass.  If it fails, then you worry about renaming it and/or deleting the file.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 7
(2,339 Views)

Thank you all for your prompt replies. It took a while to attempt the changes and implement them and I'm happy to report that it works nicely

0 Kudos
Message 7 of 7
(1,738 Views)