Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Button to log data in text file

Solved!
Go to solution

I need a button to log data in text file. When button clicked then data will be written into the file. 

0 Kudos
Message 1 of 7
(3,821 Views)

Have you tried looking at Help > Find Examples > Fundamentals > File input and output

There are write and read text file examples.

0 Kudos
Message 2 of 7
(3,785 Views)

Thanks Bryan! 

I am getting data in text file but same data logs multiple times (say 20-30 times). Is there any way to log a single data only and other data will be appended to the same. 

0 Kudos
Message 3 of 7
(3,782 Views)

Yes you can, but how depends on how you want the data recorded.  The more specific you can be with your questions the better answers you will get.  Your first post said you want to push a button and write data into a file, that is a very general question that can have many answers.  Currently your program sounds like it does exactly what you asked.

 

Going back to your question, when you push the button do you want to continuously record data until you push the button again to stop recording?  Or do you just want to write the current data at that moment and then push the button again to record more data?  You will find that the better you can define what you want to do the easier it will be to figure out how to write your code.

 

If you are writing data faster than you are reading data you will get multiple samples that are the same value.  So you need to speed up how you read your data or slow down how fast you are writing data.  If you can't speed up your data you can figure out how to only write data in the file when you have new data so it does not repeat.  But without screen shots or VI's nobody has any idea of what you are actually doing or trying to do.

0 Kudos
Message 4 of 7
(3,777 Views)

Thanks for your support. 

Let me more specific, i need a button to write the current data available only once to the file but the button must be available for click. 

I am attaching my vi's image format. 

Explanation of vi: 

DAQ (Manual Data input) is provided by numeric control in front panel ; input will be plotted over graph and the same will be converted to Celsius and Fahrenheit ; but the data in file would be in the following such format :

DATE      TIME     MANUALINPUT     CELSIUSVALUE    

7-7-2017 09:30            35                         35

7-7-2017 09:30            38                         38

7-7-2017 09:30            40                         40

0 Kudos
Message 5 of 7
(3,771 Views)

Do the mechanical action of button has some role ?

0 Kudos
Message 6 of 7
(3,770 Views)
Solution
Accepted by topic author abinash_bam

That block diagram really needs to be cleaned up.  Being that messy makes it really hard to figure out what is going on.  You should look into the free training courses that NI offers.  You need to remember that LabVIEW follows the dataflow model for running VIs.  The image explains why you are having problems with duplicated data.  You write your data in a while loop every 2 seconds and the DAQ input is outside the loop.  The while loop will only get new data when the loop is started and not while it is running.

 

There are many things I just do not understand with your vi.  I have no idea why you have the case structure around the while loop or why you have a for loop that runs 1 time with the save file. 

 

Instead of going through your VI with all its issues take a look at this example and see how you can adapt it to your needs.

 Example 1.png

Download All
0 Kudos
Message 7 of 7
(3,757 Views)