LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple While Loops Write to One File

Hello,

I have three different instruments from which I am sampling, each at a different sampling rate.  Each instrument is being sampled in its own While loop.  How do I write all the samples I collect to a single text file?  I would like something in the following format:

[Timestamp] [Instrument 1's First Sample] [Instrument 2's First Sample] [Instrument 3's First Sample]
[Timestamp] [Instrument 1's Second Sample] [Instrument 2's Second Sample] [Instrument 3's Second Sample]
...and so on..

Thank you,
Olyvia
0 Kudos
Message 1 of 4
(2,923 Views)
Use a fourth loop that does all of the writing to the file. Send data to the loop using a queue from each of the three instrument loops. The queue will need to contain the data to write to the file and also some info to identify which loop it came from.
0 Kudos
Message 2 of 4
(2,916 Views)


@ofro wrote:
I have three different instruments from which I am sampling, each at a different sampling rate.  Each instrument is being sampled in its own While loop.  How do I write all the samples I collect to a single text file?  I would like something in the following format:

[Timestamp] [Instrument 1's First Sample] [Instrument 2's First Sample] [Instrument 3's First Sample]
[Timestamp] [Instrument 1's Second Sample] [Instrument 2's Second Sample] [Instrument 3's Second Sample]
...and so on..

This seems like a flawed project. 😉

If each loop samples at a different rate, the samples will arrive at different times. Typically there won't be a single timestamp for all three samples. Can you explain what you actually want to write to the file from each loop?

Do you want to write to the file incrementally inside each loop, or do you want to write everything at once after all loops have finished?

0 Kudos
Message 3 of 4
(2,905 Views)
I had a similar project independently collecting data (using datasockets) from several different sources at vastly different rates and writing the results out to a single file. My solution was to sample the datasocket at the fastest rate and when the fastest collector sent a new sample, just write the last value sent from the slower loops. So you might see:

Fastest value: 0 Faster value: 0 Slowest value: 0
Fastest value: 1 Faster value: 0 Slowest value: 0
Fastest value: 2 Faster value: 1 Slowest value: 0
Fastest value: 3 Faster value: 1 Slowest value: 0
Fastest value: 4 Faster value: 2 Slowest value: 1
etc.

Worked fine even for loops that ranged from 300ms to 30 seconds in their collection times.

0 Kudos
Message 4 of 4
(2,859 Views)