08-09-2012 08:32 AM
Hi,
I'm writing some code for the SR630 thermoucouple monitor. I want it to scan through the channels and then save the data into a text or xcel file.
I have managed to get the scan to work, and even saving to the file, but each number is placed beneath the previous one, where instead I would ideally want to store all of the numbers from a single sweep on the same line, such that there would be 5 columns of data each corresponding to sweeps of a single channel.
Ideally an additional column would also be present on each line with a timestamp of the sweep as a whole.
Can anyone help?
code attached below
Solved! Go to Solution.
08-09-2012 08:44 AM
This should fix you right up
08-09-2012 08:46 AM
Hi Tema,
try to understand this:
When you write an array of strings to a file the strings will represent lines of the text file. So you have to convert them to represent just one line...
- I don't know what you expect from "millisecond timer value"...
- Your while loop testing the COM error may run forever - not a very good design decision...
- adding another string element to your string array is left up to you...
08-09-2012 08:51 AM - edited 08-09-2012 08:53 AM
Gerd,
Nice catch on moving the loop invarient code. (the compiler will move anyway though)
but, why not move the constants in the for loop too?
08-09-2012 09:18 AM
Hi Jeff,
I only moved the "most prominent" code outside.
Other parts are also questionable of their function and may get deleted anyway...
I also changed the format string to "%d" as "%1.0d" is questionable for numbers from 0 to 4 - they are limited to 1 digit and no decimals anyway. My intention was to give some hints and tipps for general programming in LabVIEW to the OP...
08-09-2012 10:25 AM
Hi GerdW,
Thank youso much for the tips.
- The millisecond value was just to visualize the timer counting down but its really not necessary and I have removed it.
- The while loop testing the COM error is necessary so that an error in the reading doesn't stop the whole program. Usually the error occurs because the machine takes too long to respond and the program times out, but with the loop trying more times to read it correctly this problem goes away. I know it might go on for ever, but that is only if the machine breaks down completely, in which case I would ahve a bigger problem on my hands.
- Your modifications now bunch the numbers in groupings of 5, but they are still all one under the other. I can modify what they are separated by (ie. a tab, or space, or comma etc.) but this only adds that item in front of the numbers while still moving them on the line below.
I'm guessing this is because the function doesn't wait for all 5 numbers to build a single line to then send off as a whole to "write to text file". It sends each single number as it is received?
Could I use the "pickup line" function to loop onto itself to build a single line?
- Once that is managed, how would I then go about adding a time stamp to that line? I'm guessing I would have to add a loop to separate it from the rest in order to get a single stamp for that entire line..
08-09-2012 10:41 AM
@Tema wrote:
- Your modifications now bunch the numbers in groupings of 5, but they are still all one under the other. I can modify what they are separated by (ie. a tab, or space, or comma etc.) but this only adds that item in front of the numbers while still moving them on the line below.
I'm guessing this is because the function doesn't wait for all 5 numbers to build a single line to then send off as a whole to "write to text file". It sends each single number as it is received?
Could I use the "pickup line" function to loop onto itself to build a single line?
No, it is because the instrument is returning an End of Line at the end of response. You are saving this to the file and therefore each item will show up on separate lines. I would use the Trim Whitespace to clear this out inside of the for loop.
To add a timestamp, simply add it to the string array before formating into the spreadsheet string.
08-09-2012 11:07 AM
thank you it works great now 🙂