From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Save state machine data after each iteration then write all data at once

Solved!
Go to solution

I'm having trouble determing the best way to handle the data generated by my state machine. Here's the data that it will save:

 

*After a pressure is set, a setpoint is returned.

*After pressure is set, a reading will be taken from a multimeter.

 

What would be the best way to accomplish this? Would it be better to store all the data in memory, then write all the data at once? If so, what would be the best way to accomplish this? I want to use the Report Generation Toolkit after all the pressures have been set. I've attached my current application. Thanks everyone!

0 Kudos
Message 1 of 12
(3,704 Views)

Just store your data in a shift register using an array.  The most efficient way would be to initialize the array to the desired size first, then just use Replace Array Subset to insert  data to the array.  Avoid the Build Array primitive as it causes too many data copies.

>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
Message 2 of 12
(3,698 Views)

Hello vt92 (Go Hokies!),

 

Is this what you mean? Also, what would be the best way to write all the data at once? Should I add a case for it? Thanks for your help!

 

Arrays.jpg

0 Kudos
Message 3 of 12
(3,690 Views)

Hi,

 

The answer depends on how much data, how often you are taking data, and how tolerant you are to loosing data. 

 

If you are taking data slowly, I would recommend saving to file after each pass, you really won't take a hit for the file access time and the data is saved.

 

When you are ready to make a report then you can open the file and dump the full data set to the report subroutine.

 

If you want to save the data in memory, and if you have an idea how many points you can initialize an array in a shift register to store the data.  There are techniques to resize the array if you don't know what exact amount of data you need.  For example, if the initialized array is becoming full, then double the size of the array each time it gets close to full, etc.. 

 

 

 

 

 

 

-------
Mark Ramsdale
-------
0 Kudos
Message 4 of 12
(3,686 Views)

Hello Mark,

 

Thanks for the response. It's not much data at all. When it's time to create the report, do I put it outside the case structure to the right of "Close file" or would it be better to make a case for it?

 

Thanks again

0 Kudos
Message 5 of 12
(3,682 Views)

I would make another state in your state machine for saving the data.  It is a logical part of your sequence.


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 12
(3,675 Views)

HI,

 

My preference would be to have a state that would ( with the file reference already in your code) load the data, process the data using the reports VI's, and save/display the report. 

 

I would probably have a button to activate that state.

 

That being said, it would be ok to have the report state run automatically at the end of the measurement run.

 

If you start putting GUI controls to run reports, etc...  you have to be more selective on how you write the code. For example, if the data run completes, you would then have to have an idle state where the program cycles and would wait to see if you want to shut down or run the report (or any other action).  This would be done by polling the front panel control ( like start report, etc ...).  

 

Generally polling is not the best method, but if this is a straight forward program, as in take measurements, end, wait to either report or stop, then polling is fine.  If the program is for you only, then this is fine.  You probably want the control to be in the idle state so that you don't accidentally change the front panel control and send you code into the report state during measurements.

 

If you want to have more interactive code, another discussion to be sure, you will start using event cases within the state machine, FWIW.

-------
Mark Ramsdale
-------
Message 7 of 12
(3,674 Views)

Mark,

 

I would want the report state to run automatically. However, using the Report Generation Toolkit, how would I use the file that's being appended to insert data? Close the file within the write report state using the Close File VI then open its path using one of the VIs within the toolkit?

 

Thanks again

0 Kudos
Message 8 of 12
(3,664 Views)

Hi,

 

You have the reference already in the code.  So you can use that reference to read that file and get the data.   Just because you are adding to the file doesn't preclude loading all the data already written to the file. 

 

The report generation toolkit would create a new file, the report file, and a different reference.  The toolkit components are looking for data inputs, not a file input.  For example the toolkit has a component that creates a new report, then that reference is passed to other toolkit components. 

 

You could think of the toolkit as a report driver, that is , passing a reference along to a string of report SubVI's.

-------
Mark Ramsdale
-------
0 Kudos
Message 9 of 12
(3,657 Views)

Mark,

 

I can't use this example: https://decibel.ni.com/content/docs/DOC-11074 because the file refnum doesn't point to a path. I also can't remove the "Read from Speadsheet" VI and use 2-D data because I'm writing all my data to a file like you suggested. If this is the case, how can I extract the data that's being written to the file to use in the toolkit? 

 

Sorry if I'm not getting it Smiley Embarassed

0 Kudos
Message 10 of 12
(3,654 Views)