ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving my measurement data in a .txt file

Hello dear Labview friends,

 

The problem here is my 2nd problem and therefore the continuation of my previous thread " Splitting Array with n Elements n times, while the array is filled up" thanks to the mastermind @altenbach I got several potential solutions right away. The solution I integrated is also directly in the attached vi. The simplified VI I send here has only the functions needed to show approximately what is happening, so it is not too much to look at and you don't have to spend years to understand:)

 

Currently 4 data are "measured" (random numbers) and are plotted in two graphs. The values are the replacement for the measured values taken for the 2 channels from the Keithley 2614B.

 

Now back to the problem:

Finally everything should be saved in a .txt file.
What should look like in the end:

Screenshot 2022-02-17 224115.png

The header simply outputs the values that were entered at the beginning of the measurement + an IDN? Output
As second there were some calculations (can be ignored for now)
and the third are the actual measurement data for our case its:
voltage_A, Current_A, voltage_B, Current_B

 

Normally the measurement data comes into the "Write To Spreadsheet File.vi" as stream of a 2DArray of doubles which looks like this: (here only channel A was measured in the old test program, but in principle there would 2 rows more)

Screenshot 2022-02-17 222404.png

 

While running the Program:
Before you click on Start you can select a .txt file at Save Data where you want to save the data at the end.
If you press Start and have not yet selected one, a message appears that you should do it and you must select a .txt document.
So you have to create a .txt to move on
After the measurement, the data should then be in there.

 

I am quite honest I have no idea how I can do this best:/

It does not even have to be the best solution 😄 if it works I would find it already awesome.

 

I thought I could simply build a 2 D array during the measurement and then send it to the save area. Unfortunately this did not work.

Or maybe at the lower Loop where the graph is plotted then collect the measurement data into a 2D Array and return it to the "save" area

 

Would be cool if you could put your potential solution in the VI i sent along so i can see and learn what you did 🙂

 

I wish you all a nice week!

Sebastian

 

 

 

0 Kudos
Message 1 of 9
(6,660 Views)

I save all my data to text files (Tab delimited test files to be exact)

 

IMHO: Your architecture is flawed, or at least I am having a very hard time following what you are doing...

 

Anyway what I do is as soon as the user selects a data file I write all the headers and any other information that needs to go on top of the data.

 

As I take measurements I save the data to the file one line at a time. Don't try to build up a huge array of measurements and write it all at ones at the end. Because if your program crashes form some reason you will lose all of your data. (Imagine a test running for hours, days, weeks, months!) 

 

Also I don't use "Write To Spreadsheet File.vi" I use the file primitives to open the file and pass the File Reference, this has the benefit of locking the file while the program is running so if someone try's to open it and look at t the data Windows will force them to open it read only or copy it. Then I use "Write Text File" to write each line of text.

 

Here's an example of how I write one line of measurements to my data file

onelineCapture.PNG

 

========================
=== Engineer Ambiguously ===
========================
Message 2 of 9
(6,613 Views)

Hello RTSLVU,

that look pretty good 🙂 could I theoretically do it in a loop? that it always takes the next line in the .txt?
Was having issues when I do this in a while/for loop that the whole file is always overwritten and it doesn't hop to the next line.
Can you maybe add the VI file for it, so I can take a closer look in Labview:)

 

If I have 4 data I would theoretically need 4 of them not 2?

Screenshot 2022-02-20 194839.png

 

 

 

0 Kudos
Message 3 of 9
(6,589 Views)

Hell


@RTSLVU wrote:

I save all my data to text files (Tab delimited test files to be exact)

 

IMHO: Your architecture is flawed, or at least I am having a very hard time following what you are doing...

 

Anyway what I do is as soon as the user selects a data file I write all the headers and any other information that needs to go on top of the data.

 

As I take measurements I save the data to the file one line at a time. Don't try to build up a huge array of measurements and write it all at ones at the end. Because if your program crashes form some reason you will lose all of your data. (Imagine a test running for hours, days, weeks, months!) 

 

Also I don't use "Write To Spreadsheet File.vi" I use the file primitives to open the file and pass the File Reference, this has the benefit of locking the file while the program is running so if someone try's to open it and look at t the data Windows will force them to open it read only or copy it. Then I use "Write Text File" to write each line of text.

 

 


Hello  RTSLVU,

 

do you have the VI for this little Programm:) because i cant find all the pictured Blocks in the VI:(

0 Kudos
Message 4 of 9
(6,557 Views)

Hi Sebastian,

 


@Sebbastiannn wrote:

because i cant find all the pictured Blocks in the VI:(


Which ones don't you know?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 9
(6,553 Views)

@GerdW wrote:

Hi Sebastian,



Which ones don't you know?  

 


Screenshot 2022-02-21 135330.png

One time the blocks 1 and 2 on the picture.
For block 1, I don't know how to create it, let alone what it is.
And with 2 I don't know what it does with the little time thing and how to create it.

and is it necessary to take the time into the .txt?
Therefore, I wanted to peek into the VI to see what happens there:)

 

 

 

Screenshot 2022-02-21 135345.png

And on the 2nd image I do not know where I find the blocks

0 Kudos
Message 6 of 9
(6,543 Views)

Hi Sebastian,

 


@Sebbastiannn wrote:
For block 1, I don't know how to create it, let alone what it is.
And with 2 I don't know what it does with the little time thing and how to create it.

Item #1 is a string constant as you can see from its pink color. (It's a TAB constant.)

Item #2 converts a float value into a timestamp - as you can see from wire color and appearance (and the glyph in the FormatIntoString input!). So you will find this function in the numeric conversion palette and in the Time function palette.

 


@Sebbastiannn wrote:
and is it necessary to take the time into the .txt?

That depends on your requirements!

When you want to have timestamps in your text file then you should write them into the file…

 


@Sebbastiannn wrote:

And on the 2nd image I do not know where I find the blocks


These are file functions and so you will find them in the file functions palette!

One of them writes a text (see that pen glyph with those "ab" chars"?), the other has to do with file size (see that scale glyph?)…

 

Suggestion: did you take note of those Training resources at the top of the LabVIEW board? You will make your life easier when you learn the LabVIEW basics before starting to code in LabVIEW…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 9
(6,532 Views)

@GerdW wrote:

Hi Sebastian,

 


@Sebbastiannn wrote:
For block 1, I don't know how to create it, let alone what it is.
And with 2 I don't know what it does with the little time thing and how to create it.

Item #1 is a string constant as you can see from its pink color. (It's a TAB constant.)

Item #2 converts a float value into a timestamp - as you can see from wire color and appearance (and the glyph in the FormatIntoString input!). So you will find this function in the numeric conversion palette and in the Time function palette.

 


@Sebbastiannn wrote:
and is it necessary to take the time into the .txt?

That depends on your requirements!

When you want to have timestamps in your text file then you should write them into the file…

 


@Sebbastiannn wrote:

And on the 2nd image I do not know where I find the blocks


These are file functions and so you will find them in the file functions palette!

One of them writes a text (see that pen glyph with those "ab" chars"?), the other has to do with file size

 


Hello GerdW,

Thanks for all your tipps:)!

 


Do you know why only 2 values are displayed although I enter 4? What do I have to do differently:| ?

Screenshot 2022-02-21 205316.png

The values for 2 I get in the array and also in the .txt displayed but the other 2 not:/

0 Kudos
Message 8 of 9
(6,520 Views)

Hi Sebastian,

 


@Sebbastiannn wrote:
Do you know why only 2 values are displayed although I enter 4?

Yes, I know…

 

How do you want to replace element #3 and #4 in an array containing only 2 elements?

 

Did you do any basic training course so far?

Did you learn basics of array handling in LabVIEW?

Did you learn to start element indices at 0 (zero) rather than 1 (one) in LabVIEW (like in any other reasonable programming language 🙂 )?

Why don't you use BuildArray when you want to build an array???

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 9
(6,513 Views)