05-31-2006 09:57 AM
05-31-2006 10:08 AM
If all you want is a header than I suggest putting a Write to Text File VI outside your loop and write the header to the file. Then send that path in to the loop and use the Write to Spreadsheet File VI. Make sure you have data flow in place to ensure that the header write finishes first.
The above will work but I have to mention that using the high level VIs like that is very in efficient. You are opening and closing the file in a loop, which is slow. However, you also have a 1 second wait, so I am not sure how important timing is in your actual application.
05-31-2006 10:16 AM - edited 05-31-2006 10:16 AM
Timing doesn't have to be spectacularly fast. I can take data every 5 seconds and write once every five minutes.
What kind of setup would you recommend to make it cleaner? Which combination of VI's?
In addition to header data I also will need a time stamp on each row.
Message Edited by Ralph@NES on 05-31-2006 11:21 AM
05-31-2006 10:20 AM
05-31-2006 10:37 AM
Ok we have a couple issues. Take a look at the attached VI and you will see how you can open the file once and then continue to use its reference. I then write to it in a loop, and then close it at the very end.
As far as the data flow question that is a much bigger question. Basically that is how LabVIEW executes code. I would suggest searching the help, taking the tutorial and looking on the forums for more info on it. I will give you a quick run down here though.
Look at the attached Data Flow example. Notice that the addition occurs first and then the subtraction. The reason is due to data flow. In LabVIEW a function will occur as soon as all of its inputs are available. So as soon as you run that simple VI the addition has its 2 inputs, x and y so it can execute. The subtraction must wait for the data to flow to it from the addition before it can execute. Therefore it goes second.
Makes sense so far. Now it can get a little more complicated with multiple functions ready at the same time. So look at the second VI. Notice that the addition subtraction section is totally separate from the multiple divide section. So in this VI as soon as you run it both the addition and the multiplication have all their inputs. So both can run and you have no way of knowing which will execute first. That may be ok, you just need to watch for it.
Now lets assume that the addition occurs first this time. After it executes the multiple has all its inputs still, and now the subtraction does as well. So, theoretically either function could execute now. LabVIEW could do the subtraction or the multiplication. Both are valid.
The above examples of data flow are obviously simplified but the same occurs for loops, and other functions. In the code I sent you because I pass the error cluster and fiel refnum into the while loop we are sure that the open and header write will occur before the loop starts to iterate. Therefore I know that the header will be before the data in the file.
05-31-2006 10:56 AM
05-31-2006 11:03 AM - edited 05-31-2006 11:03 AM
Message Edited by Evan on 05-31-2006 11:03 AM
05-31-2006 11:03 AM - edited 05-31-2006 11:03 AM
Message Edited by Evan on 05-31-2006 11:06 AM
05-31-2006 12:14 PM
Thanks for bearing with me on this Evan. I do appreciate it.
Here's what I've got mocked together now. It's outputting basically what I want, but there's this annoying tendency in the output .txt file to put the time stamp on a separate line as the temps. I've rearranged it a couple different ways and it still makes the time stamp go to the next line even though the preceding string is a space or tab.
If I can get it to make that all linear, then I'll be close to my goal as far as output file is concerned.
Notice my structure at the bottom with the concatenate strings? That was the way I approached the header spacing. You mentioned something about commas, is there a better way than what I've butchered together?
05-31-2006 01:09 PM
The new line is coming from the array to spreadsheet function. It adds a new line delimiter at the end of each string. An easier fix may simply be to strip off the last character of the spreedsheet string though. See the attached.