05-11-2023 08:51 PM
Hello, LabVIEW community, I am new to LV and have developed a VI which stores data in a .csv file. I am running into an issue to which I am not able to find a solution.
I want my data to look like what it is in "Expected.csv", currently looking like "Actual.csv"
I am reading data from different devices, all works well when all devices are connected and running but if anyone of the device is not operational the data shifts to the left and does not stick to the column I wanted it to be in.
I am not sure if I can share the VI as a whole so I decide not to but here is a snip that I have attached.
Thank you for your help.
Solved! Go to Solution.
05-11-2023 09:30 PM - edited 05-11-2023 09:33 PM
Replying to myself for a probable solution:
Use case structure inside the "for" loop with error handler as input and when in error case condition send the predetermined array of zero to save in Excel so the other values do not displace. This sounds like a ghetto way to me, there should be a simpler method to achieve this.
The error input will be from the error-out pin of the communication block such as XNET, LAN etc.
05-11-2023 10:01 PM
05-12-2023 03:48 PM
One reason to write text files (including .csv files) is to make them "human-readable". The problem, of course, is humans don'tparticularlylikereadingstuff when there are no separators. And if this is a minor PITA when reading a line of text, it gets much worse when you have a line of numbers, and even more so when .there are multiple lines.
The "secret" to be able to "have your data and read it, too" is to use spacing. If the numbers require fewer than 8 characters to display, you can replace the "comma" separator with a horizontal tabs, which in many text readers result in having the numbers line up in columns 1, 9, 17, 25, ... .
The other thing you can do is to figure out (by examining the data) a suitable string representation that is wide enough to include the widest number + 1 (for the comma) (and maybe another + 1 for a space after the comma). Note that if your data are "real" (meaning "floating"), you may need to work a little harder to find the proper balance between "legibility" and "precision" (as you'll want to limit the number of digits for numbers such as 1/3 = 0.333333333333333333333333333333333333333).
Bob Schor
05-12-2023 05:41 PM - edited 05-12-2023 05:41 PM
Ohh apologies on missing that.
Here they are.
05-12-2023 09:58 PM
Aha! Did you notice the Icon that the company who makes the Operating System (Micro-something-or-other) also makes a spreadsheet program (name sounds like "XL"), and (by default, but it doesn't have to be!) uses their spreadsheet program to open the CVS file? They even assign an icon to make you think that you are writing a native XL file (when, in fact, it is an ordinary text file).
But that's not your problem -- the problem is that 11 "items" after the first three (which are strings representing a Date, a Time, and "Elapsed Time" aren't showing up in your "Actual.csv" file. This certainly should not be happening. I think you are setting up your Write Delimited Spreadsheet function incorrectly. Without your attaching your code (please, as a file with the extension .vi, coming from LabVIEW, so I can see the code, run the code, and edit the code with LabVIEW), we can only "guess" where the mistake lies.
Bob Schor
05-13-2023 10:57 AM - edited 05-13-2023 11:08 AM
Thanks for the csv files. (while excel can open them, the are NOT excel files, of course).
Sorry, we are not really good looking at truncated code pictures with messy wiring (e.g. wires crossing underneath primitives, etc.).
Which part of the data is missing? From the looks of your files, it might be the data from "Signal Single-point", which would output an empty array, thus shifting the array from the lower FOR loop down by N positions. All you need is pad that array with zeroes (or NaN) to the known length (I assume you exactly know that length, 10?).
Also note that you don't really need any of these FOR loops, right? Shouldn't your shift register be initialized?
Do you have all possible permutations of instruments that can be down?
"Reshape array" can be used to pad/truncate arrays to a given size, so here's one possibility (adjust the precision as needed):
05-15-2023 08:49 PM
Here is the attached LabVIEW file that I have been working on.
To answer some of the other questions:
05-16-2023 09:33 AM - edited 05-16-2023 11:37 AM
@Happy96 wrote:
Sorry I do not understand how a shift register would replace the For loop. The output is a 1D array of N elements.
You are mixing two separate statements!
(1) Your shift register should be initialized with zero, else the time will not start at zero if you do a second run during the same session. It will start at whatever accumulated time was left in the shift register from the previous run.
(2) Your FOR loops can be eliminated as follows. Now just pad the array to 10 elements as already shown in my earlier message and you'll get an array of 10 zeroes if the array is originally empty. If the array already contains 10 elements, they will be left untouched. If the array contains fewer than 10 elements, it will be padded with zeroes and if it contains more than 10 elements, it will be truncated to 10. "Reshape array" is a wonderfully useful function!
And if you would pad after the formatting, you would get an array of 10 empty strings, which might be a better option if zero can also be a valid entry.
05-18-2023 01:27 PM
Thank you, I initialized my shift register and also removed the for loop.
This is what I ended up doing and it work as intended.