LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert data into an array

Solved!
Go to solution

Hello everyone,

 

I am trying to communicate with an oscilloscope and save the data i read. I also want to record the duty_cycle,frequency etc. 

 

The problem is, i get those values succesfully but cannot save them to an excel. First, i have tried to write some data on excel. The file is excellast.vi. It works nice. Since i have to put an array to write spreadsheet block i have tried this

It says to use "instert into array". when i do it on my "oscilloscope basic" it does not work. I only get 0's even though i see that i get the values from my oscilloscope. I draw a graph on labview and check the values there.

 

I would like to write the data lilke this.

 

dutycycle   frequency   amplitude

50                  250              2

50                  247              2

49                  250              2

 

Any ideas about what i am doing wrong? Any other suggestions?

Thank you so much! 

Download All
0 Kudos
Message 1 of 13
(3,813 Views)

Hi doguhanpala,

 


@doguhanpala wrote:

Any ideas about what i am doing wrong? Any other suggestions?


You don't follow the "THINK DATAFLOW!" paradigm of LabVIEW: in each iteration you try to insert into an empty array at an invalid location. (And you use local variables where you should use the control terminal and wires instead.)

 

Please take the free Training resources offered in the header of the LabVIEW board to learn about LabVIEW basics, like array handling!

(All you need is a BuildArray node and a shift register…)

Best regards,
GerdW


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

Hello GerdW

 

About local variables, there is another part of file but i've cut it to decrease the confusion. Even though it still might be wrong, i'm a newbie to labview.

 

I've watched a few videos from ni basics and checked about this problem all day long. The link i've shared on the post confused me. I will check shift register solution. If it works i will post my solution. If not another question will be on the way...

 

Thank you so much for your answer!

Have a nice day!

0 Kudos
Message 3 of 13
(3,792 Views)

Hi doguhanpala,

 

I think it might be even simpler than GerdW said - since at each instant in time you have all the values you want for a new row, you can simply create an array of those values and write them to the spreadsheet (using the append option as you show in Excellast.vi).

 

This isn't particularly efficient (because you'll be writing to disk every iteration), but it will work (provided the loop doesn't need to be very fast).

 

To write more efficiently, you could consider using Open/Create/Replace File, then Write to Text File with a Shift Register as GerdW mentioned (I'm not sure if he meant for a file reference or not - that's what I mean here). Close the File (Close File) after your loop stops.

There is an Array to Spreadsheet String node that doesn't write directly (hence the Write to Text File node) that will convert from Array to a string with a chosen delimiter (e.g. "," ).


GCentral
0 Kudos
Message 4 of 13
(3,791 Views)

Exactly. There is no need to build an ever growing array of ultimately infinite size. Build an array of your three measurement values and append them as new row to a file that you open before the loop and close once the program completes. 

 

You also don't need these extra indicators (orange, of the wrong datatype). Just show the digital display of each chart.

 

altenbach_0-1574705306920.png

0 Kudos
Message 5 of 13
(3,739 Views)

Hello again,

 

Thank you all. I've read your suggestions and i've a few questions. 

 

First of all, i think the best option is to hold data and writing to file "after" the loop as cbutcher suggested. Still looking and trying to learn shift registers.

 

"There is no need to build an ever growing array of ultimately infinite size. Build an array of your three measurement values and append them as new row to a file that you open before the loop and close once the program completes."

 

I've tried that in the file. Opened/created the file before the loop, wrote in the loop and closed file when pressed stop(when loop is done). The problem is i am getting only one line. It overwrites to first line always i assume. If i change the the delimiter, it stops writing in different columns.

 

How do i say to the labview to go next row?

filewrite.PNG

Thank you so much!  

0 Kudos
Message 6 of 13
(3,693 Views)

Hi dogu,

 


@doguhanpala wrote:

I've tried that in the file. Opened/created the file before the loop, wrote in the loop and closed file when pressed stop(when loop is done). The problem is i am getting only one line.


Because you didn't follow the suggestion!

Open the file before the loop and wire the file refnum into the loop using a shift register! Using this file refnum LabVIEW will keep track of the current write position in the file and append new data to the end of the file. When using the file path (like you do) the file will be opened each time again and writing starts at beginning of the file…

Also move the VISAClose and FileClose after the loop: no need for a case structure!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 13
(3,681 Views)
Solution
Accepted by topic author doguhanpala

Hi again doguhanpala,

 


@doguhanpala wrote:

First of all, i think the best option is to hold data and writing to file "after" the loop as cbutcher suggested. Still looking and trying to learn shift registers.


I don't think either of my suggestions included saving the data as a block after the loop, although that would also work. However, it isn't particularly close to what you already had before, or what you have now.

 


@doguhanpala wrote:

"There is no need to build an ever growing array of ultimately infinite size. Build an array of your three measurement values and append them as new row to a file that you open before the loop and close once the program completes."

 

I've tried that in the file. Opened/created the file before the loop, wrote in the loop and closed file when pressed stop(when loop is done). The problem is i am getting only one line. It overwrites to first line always i assume. If i change the the delimiter, it stops writing in different columns.


You're really close with the attached VI - as GerdW has pointed out and we both previously pointed towards, you just need to connect the file reference output from the Open/Create/Replace file that you've setup to the outer edge of a Shift Register on the loop (right click on the loop to "Add Shift Register", or wire the reference then right click on the tunnel and click "Replace with Shift Register") and then wire that across the loop through the Write node.

 

Here's a basic example of what you're looking to do:

Example_VI_BD.png


GCentral
Message 8 of 13
(3,674 Views)

Hello everyone,

 

Thank you all for your help. The problem solved after last post. I also tried with spreadsheet so, i have 2 different solutions now.  I am adding both of them here. Basic 2 is done with shift register, 3 is done with spreadsheet.

 

Thank you very much!

 

Have a nice day! 

Download All
Message 9 of 13
(3,654 Views)

#2 is preferred for performance reasons (there is absolutely no need to open and close the file with every write as the high-level file IO does. Opening and closing files involve the OS and is expensive. Keeping the file open also prevents other apps (e.g. excel) from opening it simultaneously, an action that would cause the next spreadsheet write to fail).

 

You also moved the visa close out of the loop as suggested. Good!

 

A few minor points:

  • Don't branch the file reference and error wires, wire them across the file write function. (A good habit to enforce execution order needed in typical usage).
  • The shift register on the reference makes no difference and can be omitted (shift registers are needed for file refs in the case of FOR loops where zero iterations are a possibility).
  • You might want to place the error wire in a shift register though and/or even stop the loop on error.
  • The "Channel" control terminal belongs inside the loop branching to all places if it can change during the run. If the channel value should remain invariant during the loop, the terminal belongs outside the loop, but still wired to all the places. No locals!!!
0 Kudos
Message 10 of 13
(3,639 Views)