LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help writing data to excel sheet

Good Day All,

 

I have been working on a small project for few hours and i got stuck at the stage where i need to export the readings/measurements to an excel sheet. To give you an idea of the program, hardware used, It's a simple program to read 3 Voltages and 2 Currents but in the virtual channels i inserted all available channels for each reading ie.(cDAQ1Mod2/ai0:7) *Even though i'm only taking 3 V measurements and two current measurements, but i'll delete irrelevant ones from excel sheet later*. The module used is NI 9207 (16-channel Analog Input 8 Voltage, 8 Current). 

 

The problem: due to my lack of knowledge and experience in Labview i was unable to write the measurements in the format i would like it to be and i'm not sure if i can even do it. I attached the VI and how the excel sheet looks like and how i want it to look like. Would really appreciate your help in solving my problem.

0 Kudos
Message 1 of 9
(3,640 Views)

I see two problems with your code.

 

First, right from the screenshot, your create channel functions belong outside the loop.  Right now you are recreating those tasks on every iteration of your loop.  You are eating up resources.  They belong outside, and only the DAQmx Read belongs inside.  Be sure to put a DAQmx clear task outside after the loop.

 

Second, looking at your Express VI that converts to the dynamic data type (an evil wire that hides the underlying data), you have it set for 1-D array of single channel.  So it is putting all of the data in one column.  It should be 1-D array multiple channels.

 

See the attached VI for an improved version of your VI.  You should probably also have the Write to Measurement File set to append data to the file rather than overwriting the file.

 

You should be sure to open up the LabVIEW help system and read up on the functions.

Message 2 of 9
(3,611 Views)

First of all, thank you for the quick response! And i really appreciate your comments and improvements on the VI. Yeah i didn't know much about how the loops work and other things, i just followed few tutorials on how to take measurements and searched for similar projects to the one i'm working on to come up with the mess i had. Moreover, I am testing the VI now and it seems like everything going well so far! I will finish testing and mark this problem as solved once its confirmed. Again, Thanks a lot for the quick help.

Edit: Now to label the columns headers, i looked around and it seems like i need to add an express VI "Set Dynamic data attributes", but where should it be? inside the while loop, outside while loop or inside Case loop? Also, do i need one for each channel? (total 16 channels).

0 Kudos
Message 3 of 9
(3,587 Views)

Experiment.  See if it works.

 

I think you'll probably need to do it in the case structure after you convert to the dynamic datatype, because before that, there is nothing about it other than an array of data that indicates the channels.

 

And I think you wold need to do it for all 16 channels.  Without seeing a sample of code using it, I'm not sure right now.  It looks like that express VI lets you type in the names for all 16 channels within its configuration dialog.

0 Kudos
Message 4 of 9
(3,577 Views)

So i think everything worked well, now i'm facing another issue which is the sample rate and readings per second.. I am trying to write the readings on an excel sheet. I want to write 200 readings per second for 2 minutes or so which will result in an excel sheet with 24,000 (2*60*200) readings, however, i get rows with the same readings or i get very few readings compared to the rate i asked it to be in like it gives me 2 readings per second instead of 200. attached are a picture of output data on excel and the block diagram with the edited VI. 

Download All
0 Kudos
Message 5 of 9
(3,529 Views)

can anybody help me with the issue? I think one reason is the computer itself, i noticed when i check the "write to excel" while running the program causes CPU usage to go up to 90%+. would changing to a better computer perhaps solve the problem?

0 Kudos
Message 6 of 9
(3,516 Views)

You've got 2 or 3 problems going on.

 

1.  You've got your DAQmx read set up to read only 1 sample at a time.  That means you are at the mercy of how fast the loop runs for how fast you can acquire data.  Try setting up to read N samples at a time.

2.  You may actually be acquiring samples at 200 times per second, but the 1 sample read is coming out as an array of doubles (for the N channels) and thus has no timing information.  So the conversion to the dynamic datatype, or the Write to Measurement File is adding timing info that is probably based on the clock at the time the data is converted or written, as opposed to the time it was actually acquired.

3.  You are using Write to Measurment File expresss VI within that loop.  Express VI's are great for getting something configured quickly with some flexibility, but they aren't meant for performance.  You are actually opening and closing your file every time you write that 1 sample you acquired.  File operations are among the more time consuming things a PC can do.  It is effectively slowing down your loop rate quite a bit.

 

For #1 and #2, try using N samples and acuiring a 1-D array of waveforms so you get larger chunks of data that contains the timestamp information.  For #3, look at the producer/consumer design pattern to move the actual writing of the file off to a separate consumer loop.

0 Kudos
Message 7 of 9
(3,510 Views)

 

Thank you RavensFan for your continuous help, I have followed your comments but was still unable to fix the issues, I changed the DAQmx read to read N Channels & N Samples and export it to excel. The results would again come in chunks based on the read rate, say I set the rate to 2, I would get 2 IDENTICAL readings per second and so on. I tried to play around with the while loop and the Express VI (Write to measurement file)'s loop and I got nothing.. the second solution you suggested is a bit difficult for me to implement as I don't have a lot of time to go through a lot of readings and NI study-material.

Download All
0 Kudos
Message 8 of 9
(3,455 Views)

iMalik,

 

I glanced over your code, and I noticed that you have a very long time delay in your loop (1 second or greater). Is there a reason that you are using the Time Delay Express VI in your loop and incrementing the delay second by one time for each loop?

 

Is the data in your transposed array correct? Is it just the excel data that is showing up incorrectly?

 

I also noticed that you are clearing your task within the loop. In general, we recommend stopping and clearing your task after completing all of your reading. I would recommend looking through our examples using our Example Finder under Help >> Find Examples. The specific ones that may help you design your program are Write Excel File.vi under Fundamentals >> File Input and Output >> Spreadsheet and the Voltage – Continuous Input.vi under Hardware Input and Output >> DAQmx >> Analog Input. The other File Output examples will provide alternatives that you could use to write the data to the spreadsheet.

 

Regards,

Hannah

Applications Engineering

National Instruments

www.ni.com/support

0 Kudos
Message 9 of 9
(3,418 Views)