LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview 8.2 output to spreadsheet

Solved!
Go to solution

Hi,

 

 I am having problems outputing my data to excel.  The project is to design a program that turns a DC motor and a starter on and off at specific times and record the RPM, Current, and Torque from these devices.  I am usind LabView 8.2 with a PCI-6024E and a BNC-2110. My vi seems to operate correctly when it does not have the spreadsheet additions to it.  However, when I attempt to export the data to excel it will only send 1 set of data every cycle.  Attached is the vi.  Any help would be greatly appreciated.

 

Thank You

0 Kudos
Message 1 of 10
(3,737 Views)
Solution
Accepted by topic author dehmann

First of all, you are opening a binary file, not a spreadsheet file.  You open the file outside your loop, which is OK.  I don't see any write function in your loop.  you aren't writing anything to the file except the header stuff.  Inside your loop, you are closing the file over and over again.  You need to move the close function to the outside of the loop and add a write function inside the loop.  If you want to read your file with excel or with a text editor, don't use the Write to Binary File function, use the Write to Spreadsheet File instead.

 

- tbob

Inventor of the WORM Global
Message 2 of 10
(3,732 Views)

Thank You tbobI made the changes you suggested but I do not understand what you mean regarding the write file.  I have moved it inside the For loop but the output on the spreadsheet now is just the header over and over.  Which loop is it needed inDo I need to combine all of my input signals into it? I have never used LabView before and I have no manual so please excuse the beginner questionsIf you know of any examples I would like to know.

 

 

0 Kudos
Message 3 of 10
(3,701 Views)

You have a Write to Spreadsheet File function inside your loop.  The header string is wired to the delimiter input.  This is wrong.  The delimiter input should be a comma or a tab.  Since this function is in your loop, you will get headers written to the file each time the loop iterates.  I'm sure this is not what you want.  But before I can give you a solution, I need for you to clarify what you want to happen.  It seems as if you are wanting to write the headers, then write some measurements from the Measurements vi, then later you have a While Loop with a Format Into File function where you will write more information into the file.  Neither write functions match the headers.  Please let me know exactly what you want to write.  Give me an example of the file format.  Also, you cannot write a 2D array of numbers, then later on write strings to the same file.  You have to keep the same data type going into the file.  I suggest you change the 2D array of numbers to strings to be consistant with header strings.

 

To properly write headers, use the Write File function outside the loop at the beginning to write headers.  Then inside the loop, write the data.  After the loop, close the file.

One more thing, you don't need the inner While Loop.  It executes only once.  Combine all data writes into one write function instead of two.

 

After you clarify, I can help you more.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 10
(3,695 Views)
The end result should see the outputs from the torque and current transducers as well as the RPM sensor output to a waveform graph on the front panel as well as to an excel spreadsheet.  For the spreadsheet I want the headers to read Cycle, Date, Time, RPM, Current, and Torque, and then output the corresponding values below.  I want each write iteration to occur every 100ms.  
0 Kudos
Message 5 of 10
(3,685 Views)

I don't have LV 8.2, just LV2009, so I made a picture of my suggestions:

 

TestStand1.4[1]_BD.png

- tbob

Inventor of the WORM Global
Message 6 of 10
(3,670 Views)
Wow, thank you for the diagram tbobThe program outputs correctlyI've been searching for help for almost 3 weeks nowI have a few remaining questions. 1) Why did you choose to use shift registers instead of indexing nodes2) What exactly is writing the data inside the loop? 3) How do I make the program write every 100 ms instead of once every cycle? 4) Do you have any other tips for programmingThank you so much for your help.
0 Kudos
Message 7 of 10
(3,661 Views)

Hi Dehmann,

 

1) If you are wondering about shift registers versus auto-indexing nodes, take a look at this help file which describes what auto-indexing does, it's not really appropriate to use it here. 

 

The shift register is taking the last value and using it for the next iteration of the loop.   In this case you are using writing to the same file, so you use a shift register to use the same reference to the file.  In this case the shift register is being use to take the same constant value, but the shift register is also useful when you need to perform the same calculation at each iteration and take the last value (such as a running average).

 

2) The format into file is writing your data.

 

3) If you want to write to file every 100 ms and you know your loop is iterating at less than 100 ms, you could add a wait VI to make sure your loops are iteration at 100 ms intervals.  And it looks like tBob has a Wait Until Next Multiple VI in there.  Is that not give you expected results? 

 

Tejinder Gill
National Instruments
Applications Engineer
Visit ni.com/gettingstarted for step-by-step help in setting up your system.
0 Kudos
Message 8 of 10
(3,618 Views)

dehmann wrote:
Wow, thank you for the diagram tbobThe program outputs correctlyI've been searching for help for almost 3 weeks nowI have a few remaining questions. 1) Why did you choose to use shift registers instead of indexing nodes2) What exactly is writing the data inside the loop? 3) How do I make the program write every 100 ms instead of once every cycle? 4) Do you have any other tips for programmingThank you so much for your help.

 

1)  You are using a For Loop which can run 0 times if the input to N is 0.  With regular terminals, if this happens, the output terminals will be at default value and you will get an error on your Close function after the loop, and the file will not close.  Causes memory problems.  Also if there was an error before the loop, the default error (no error) will occur after the loop and you lose your error.  With shift registers, the values going in (error and file reference) will be carried to the output if the loop does not execute and the file will close normally and the errors will be reported.  This was a suggestions given to me by NI in one of their training classes.

 

2)  The Format Into File function will format the data according to the input format string and then write the formated string to a file.

 

3)  Make the cycle 100ms and then write once every cycle.  This is the easiest way to do it.  Make the delay 100ms to do this.  You gather data every loop cycle so just write once every cycle.  Why would you want to write the same data more than once?

 

- tbob

Inventor of the WORM Global
Message 9 of 10
(3,616 Views)
Thank you. This explains so much.
0 Kudos
Message 10 of 10
(3,602 Views)