From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Read all input lines and append to a file to avoid overwriting previous reads

Hi,

I need some help regarding appending (writing) data to a file after reading the input value from all lines. So, I have came so far that it reads the inputs and can write to a .txt file. However there are two problems with current solution:

  1. I do not want the most recent data to overwrite the previous reads in the log file. I want to store all inputs from the startup to a certain amount of time, thus the overwriting in the .txt file is not good enough.
  2. The second problem, which actually is not that critical for me, is that the current solution do not add delimiter to make the importing to MS Excel or other tools trivial.

I have attached a figure of my current solution, and the attempt to switch to spreadsheet. The thing I find difficult to figure out is how I can transfer the boolean array to be appended to the file. I guess I have to use the "Write delimited spreadsheet" to append current reads with the previous but I am not able to import a 2D array from the boolean array used in the current solution. 

 

22449384_10214541990973077_376403765_o.jpg

 

All help will be highly appreciated. Thanks in advance.

0 Kudos
Message 1 of 8
(2,921 Views)

Well, I don't have much experience with LabVIEW NXG, but can make some observations about LabVIEW and the File I/O functions, particularly the Read and Write Delimited Spreadsheet functions.

  • The LabVIEW Help for these two functions provide important "clues" to let you solve your problem, particularly if your data are in "simple Spreadsheet form", with all of the entries of the same type (i.e. all strings, all Dbls, or all Integers).
  • A Read Delimited Spreadsheet can read the entire "Spreadsheet" file all-at-once and give you a 2D array of all of the data.  Note, however, that this closes the file when the Read finishes.
  • Write Delimited Spreadsheet has an input Control called "append to file?" (default=False) that, if True, adds data to the end of an existing "Spreadsheet" file.
  • You'll notice I write "Spreadsheet" file.  This is a text file in "Comma-separated Values" (.csv) format, with a separator character (the LabVIEW default being a <Tab>, not a <comma>) separating columns and <New Line> separating rows.  Excel can also open these Text files, and, if installed, will place an Excel-appearing Icon on these files ...
  • Look at the analogous functions in LabVIEW NXG, or use the LabVIEW 2017 Spreadsheet functions I mentioned above.  This should enable you to read an existing file and append one or more rows with little effort to the end of the existing file.

Bob Schor

 

 

0 Kudos
Message 2 of 8
(2,890 Views)

Thanks for the answer. Yes, I am aware that the Write Delimited Spreadsheet function is probably the way to go to achieve what I want. However, the thing I do not understand is how I can create a 2D array that from a 1D boolean array such that the Write Delimited Spreadsheet can be used. 

0 Kudos
Message 3 of 8
(2,879 Views)

Hi salasjad,

 

convert the boolean array to 0/1 resulting in an 1D array of U8. Then use BuildArray to create a 2D array from this 1D array:

check.png

Btw. atleast in LabVIEW (without NXG) the WriteSpreadsheetFile function also accepts 1D arrays at its inputs…

Best regards,
GerdW


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

Hi GerdW,

Thanks for the reply. Can I ask what the second last block is called? I am not able to find it.

0 Kudos
Message 5 of 8
(2,862 Views)

Hi salasjad,

 

I will repeat my last message, perhaps you didn't read it:

convert the boolean array to 0/1 resulting in an 1D array of U8. Then use BuildArray to create a 2D array from this 1D array

Best regards,
GerdW


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

Indeed I did not read your message properly. Now I am able to create the 2D array. Thanks for that.

 

Here comes a followup question:

I use DAQmx task to read the inputs, which returns a boolean array with the value of inputs. Let us say that I only want to store the inputs that have a high value to the 2D array. And in addition I want to store the line number (pin number) of the input. So the question is whether there is a straight forward way to store input value that are high together with the line number as a 2D array?

0 Kudos
Message 7 of 8
(2,847 Views)

Hi salasjad,

 

Let us say that I only want to store the inputs that have a high value to the 2D array.

So you want to create an array containing only TRUE booleans? Use InitArray… (Yes, sarcasm… :D)

 

in addition I want to store the line number (pin number) of the input. So the question is whether there is a straight forward way to store input value that are high together with the line number as a 2D array?

Sure there is!

Use a FOR loop to iterate over your boolean signal array. For each TRUE bit you store the FOR loop iterator in an array to receive an array of the TRUE channel numbers…

This is pretty basic LabVIEW stuff. Did you take the free beginner courses?

You still don't attach your VI to show what you have tried so far - we will not solve your homework for you!

Best regards,
GerdW


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