01-20-2020 02:18 AM
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!
Solved! Go to Solution.
01-20-2020 02:49 AM
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:
01-20-2020 04:21 AM
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...
01-20-2020 06:05 AM
@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)
01-20-2020 06:21 AM
01-20-2020 06:40 AM
@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.
01-30-2020 10:05 AM
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