LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to build a 1D array n save it as a line on an open text

Solved!
Go to solution

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

0 Kudos
Message 1 of 8
(2,838 Views)

This should fix you right up

aa.png


"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 8
(2,833 Views)

Hi Tema,

 

try to understand this:

check.png

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...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 8
(2,831 Views)

Gerd,

Nice catch on moving the loop invarient code.  (the compiler will move anyway thoughSmiley Wink)

but, why not move the constants in the for loop too?


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 8
(2,827 Views)

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...

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 8
(2,820 Views)

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..

 

 

 

 

0 Kudos
Message 6 of 8
(2,809 Views)
Solution
Accepted by topic author Tema

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 8
(2,805 Views)

thank you it works great now 🙂

0 Kudos
Message 8 of 8
(2,796 Views)