LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Designated cell spacing for the write to spreadsheet data

Solved!
Go to solution

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. 

Happy96_0-1683856211879.png



Thank you for your help. 

0 Kudos
Message 1 of 11
(1,443 Views)

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. 

0 Kudos
Message 2 of 11
(1,429 Views)

Did you forget to attach the csv files?

 

 

0 Kudos
Message 3 of 11
(1,416 Views)

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

0 Kudos
Message 4 of 11
(1,362 Views)

Ohh apologies on missing that.  
Here they are. 

 

Download All
0 Kudos
Message 5 of 11
(1,345 Views)

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

0 Kudos
Message 6 of 11
(1,330 Views)

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):

 

altenbach_0-1683994012623.png

 

0 Kudos
Message 7 of 11
(1,314 Views)

Here is the attached LabVIEW file that I have been working on. 

To answer some of the other questions: 

  1. Correct, the signal from "Signal Single-point" was missing because the CAN bus was not connected. 
  2. The entire 3rd stanza is the correct representation of the behavior seen. 
  3. It would be of the exact length of 10 always as I read 10 values from that data bus. 
  4. Sorry I do not understand how a shift register would replace the For loop. The output is a 1D array of N elements.
0 Kudos
Message 8 of 11
(1,264 Views)
Solution
Accepted by topic author Happy96

@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! 

 

altenbach_0-1684247479650.png

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.

 

0 Kudos
Message 9 of 11
(1,248 Views)

Thank you, I initialized my shift register and also removed the for loop. 

Happy96_0-1684434394603.png

This is what I ended up doing and it work as intended. 

0 Kudos
Message 10 of 11
(1,209 Views)