04-15-2010 05:38 PM
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
Solved! Go to Solution.
04-15-2010 06:18 PM
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.
04-16-2010 02:28 PM
Thank You tbob. I 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 in? Do 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 questions. If you know of any examples I would like to know.
04-16-2010 03:24 PM
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.
04-16-2010 04:15 PM
04-16-2010 05:53 PM
I don't have LV 8.2, just LV2009, so I made a picture of my suggestions:
04-16-2010 06:51 PM
04-19-2010
10:40 AM
- last edited on
01-21-2025
02:20 PM
by
Content Cleaner
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?
04-19-2010 10:44 AM
dehmann wrote:
Wow, thank you for the diagram tbob. The program outputs correctly. I've been searching for help for almost 3 weeks now. I have a few remaining questions. 1) Why did you choose to use shift registers instead of indexing nodes? 2) 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 programming? Thank 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?
04-19-2010 05:26 PM