Showing results for 
Search instead for 
Did you mean: 

how continuously write data to a txt file

Go to solution

first of all, sorry for bad English, but I have a problem to continuously write data to the txt file.... I have one 2D array with values of some function and based on 2 sliders (values of the sliders) i want to interpolate value using bilinear method... and after that value of the sliders, interpolated value, and value of the nearest points i wish to write to txt file ... for every 2-3 seconds perhaps it would be ideal to be formated as :: 
x   y   f     f1   f2   f3   f4
..   ..  .. . .. .   ..   ...  . ..
... ...  ..    ...   ...   ...   ...

but... first i have problem with writing data, because every time it deletes old data and just write new one and it's not horizontal... I'm very very new at this (it is obvious) and any help will be very appreciative 😄 
thanks 😄 



0 Kudos
Message 1 of 4

Hi there,


May I suggest you start with the LabVIEW tutorial?  Or perhaps this one?


I say that because 1) you said you're new at this, and these tutorials are great for getting started; and 2) you don't seem to understand the concept of dataflow.


A structure, such as a loop or subVI or function, cannot start executing until it has all of its inputs available.  Therefore, the loop which contains your file write (bottom loop) cannot execute until your top loop is done executing, because it depends on inputs from your top loop and those inputs aren't available until the top loop is finished.  Thus, your file will contain only the data from your final top loop execution.  You might be thinking that your loops are executing in parallel.  They are not.  Your file loop is executing after your data loop has finished...that is to say, your file loop executes exactly once, after you press your stop button.


You can do two things here to fix that:


1.  You can move your file write into the top (data) loop. (probably easier for now)

2.  You can use a queue to transfer the data from your top (data) loop into your bottom (file write) loop. (more complex, but a better idea in the long run)


One other thing.  Move the "open file" function outside the loop.  Opening and closing the file in each loop iteration will cause problems.  Open the file once.  Write to it in each loop iteration.  Close it when you're done.  Like this:


file write.png

Note that this is not complete need to provide the data to write.  This is just to show you how to set up a continuous file write.


Ok, start with the tutorials and we'll go from there.  Smiley Happy



Message 2 of 4
Accepted by topic author yeKciM

Diane beat me to it, I have made some modifications to your code, so I shall post it anyway.

write to file.png

As suggested, please go through the tutorials.

I have added a write to spreadsheet node at the end, just to show that this can be done right at the end as well. Building array on a while loop is not very memory efficient, but this is just to show you what could be done. If you are planning to go down that route, initialise an array and use replace array subset function.

All the best.

CLA CTAChampion
Subscribe to our Test Automation user group: UK Test Automation Group
Message 3 of 4

Thanks both of you 😄 very much 😄 

0 Kudos
Message 4 of 4