LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

New to labview - Probing data types

Solved!
Go to solution

I've started a new job where I'm moving from text based programming (Mathematica) to LabVIEW, and one challenge I've been hitting while working through tutorials and problems, is how to figure out data types when inputs and outputs don't match, particularly when I'm working with arrays.

 

For example, I have a small program that reads in a CSV which contains only a single column, deletes the header with "Delete From Array", and then I'm attempting to write those values to an analog output on a USB-6002. I struggled for a while with getting the correct dimensions on my array so that I could pass it along to DAQmx Write.

 

Is there a simple way while debugging and writing code to probe array sizes/structures? I know about "Array Size", but I need my program to at least have all connected wires so I can run it and see the output. If I have a VI I'm working on, that isn't in a state where I can run it, how can I easily look at outputs of functions and see what their type/dimensions are?

 

Thanks in advance!

0 Kudos
Message 1 of 9
(2,176 Views)
Solution
Accepted by topic author WinstonDC

In the LabVIEW IDE, press CTRL+H to display the help menu, then put your mouse on any wire, terminal, constant, control, indicator of your code.

The help menu will display the associated data type:

raphschru_0-1672243499777.png

Here for example this gives you the dimension of the array (1D).

However, you cannot expect LabVIEW to know before execution the size(s) of your array.

In your use case, the CSV file can contain any number of values, which is not known in advance...

Message 2 of 9
(2,169 Views)

Thanks Raphschru, that helps!

 

I understand that prior to loading the CSV, the program can't know what dimension it will find. I think I'm just spoiled by Mathematica allowing me to run small snippets of code at a time, so I can walk through it. It seems like the answer in LabView is that I need to divide my code in to more subVIs so I can have small parts to run and test before the whole program is completed.

 

 

0 Kudos
Message 3 of 9
(2,158 Views)

Sounds like you need to learn about the LabVIEW debugging tools.  Search for "LabVIEW debugging".  Here are a few good ones:

 

Debugging Techniques in LabVIEW - NI

LabVIEW Debugging Techniques – Digilent Blog

LabVIEW Debugging Tips: Conditional Probes | DMC, Inc. (dmcinfo.com)

 

You are absolutely right about separating functionality into subVIs.  You can also leave indicators on your subVIs that show intermediate values (even graphs and charts).  Close them when you no longer need the detailed info.

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
Message 4 of 9
(2,148 Views)

I think your main problem is unfamiliarity with LabVIEW and looking in all the wrong places for a "solution".

 

It you say "dimensions" (plural!), it probably means hat you are reading the data as a 2D array with one column, so "csv" seems a misnomer, because there are no column delimiters. OTOH, your DAQ write might want a 1D array.

 

Easiest would be to read the file as plain string, then use "spreadsheet string to array" with a 1D array as type and linefeed as delimiter and you will get a 1D array directly. No need to know the size! (There are plenty of other easy alternatives, I can think of quite a few!)

 

Similarly, if you want to get the first column from a 2D array, you can use index array with a zero wired to the lower index and the upper index disconnected, and you'll get the entire column. Again: No need to know the size! (see also this recent post)

 

altenbach_0-1671728037442.png

 

Array handing in LabVIEW is extremely elegant! You simply need to get familiar with the tools!

Message 5 of 9
(2,134 Views)

Thanks Altenbach. I think what threw me off was that the CSV file (which yes, being only one column is all new line delimited really) when opened with Read Delimited Spreadsheet, returned a 2D array of size 52x1, which in my head meant it was an 1D array, but even though it's second dimension is 1, it's still a 2D array!

 

I was trying to find a simple single function that would allow me to take this "2D" array, drop the first row, and return a 1D array, but the best I found was to use a "Delete From Array" to remove the first row, and then an "Index Array" to take only the first column, yielding a 1D array.

0 Kudos
Message 6 of 9
(2,115 Views)

You can look inside "read delimited spreadsheet" and see that it will do a 2D array anyway, so to get one column, you could set transpose=true and use the 1D output to get the first column. (If the header string is important, you should even read it as one column of strings and parse later.)

 

Unless you need to do something with the header string, "delete from array" is overkill, because it gives you two outputs, one you don't even use! Just use array subset on the 1D array with the index set to 1.

(All that said, the LabVIEW compiler optimization will probable end up with the similar machine code in the end. :D)

 

You can also read one line from the file first as text to get the header, then use "read delimited spreadsheet" using the offset returned to get the data without header.

 

altenbach_0-1672248381824.png

 

Of course if the file is gigantic and performance matters, it might be easiest to read it as plain string and do all parsing in memory.

Message 7 of 9
(2,104 Views)

To turn a "2D" array of N rows and 1 column, or N columns and 1 Row, simply pass it through "Reshape Array" and give it the single dimension "N".  Note you can also run this the other way and turn a 1D into a 2D with N columns and 1 row (but why would you want to?).

 

Bob Schor

 

To the tune of "Anything You Can Do, I Can Do Better" -- Anything Mathematica can do, LabVIEW can do with more panache ... (OK, it doesn't scan, so don't sue me).

Message 8 of 9
(2,038 Views)

Search "Stretchy String.vi" on these forums.   

 

Custom Probes ROCK!


"Should be" isn't "Is" -Jay
Message 9 of 9
(2,028 Views)