LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuously writing data

Solved!
Go to solution

Hello guys, newbie here.

 

What I am trying to do is to continuously acquire a voltage analog input from a hall sensor, apply a linear equation to transform it to the responding current, and write both values with time stamp while the loop goes on. But I get confused. because if I put the 'Write to measurement file' inside the loop, I get a lot of excel tabs when I open the file, while if I put it outside the loop. i only get the number of data that the DAQ assistant reads. Is there a method to continuously write date to a tdms file, put it all in one excel tab and create a new tab only for example when the date changes?

 

I put a screenshot of the thing I am trying to build.

 

I use NI USB 6008 for data acquisition.

 

 

 

0 Kudos
Message 1 of 10
(5,356 Views)

@kapablanca wrote:

I put a screenshot of the thing I am trying to build.


I don't see any screenshots.

 

You can open a text file and append a new row with each writing operation using lowlevel functions. Don't do express VIs and excel and such. What is your loop rate?

 

0 Kudos
Message 2 of 10
(5,351 Views)

Screenshot_8.png

Thanks for the quick answer. Maybe I mistakenly didn't post it.  Here is what I am trying to build. I am not sure I understand your question about loop rate. Do you know any good tutorial with an example of the method you suggested?

0 Kudos
Message 3 of 10
(5,347 Views)

If you use express VIs and dynamic data, a screenshot is useless because there is no way to tell how things are configured. Can you attach the VI instead?

 

I strongly recommend to start with a few simple LabVIEW tutorials and learn about the basics of dataflow

 

In your image, the second loop cannot start until the first loop has completed and then the second loop will write the same data over and over as fast as the computer allows until the stop button is pressed. Makes no logical sense.

0 Kudos
Message 4 of 10
(5,342 Views)
Solution
Accepted by topic author kapablanca

I recommend just using the actual TDMS functions.  Create the TDMS file before the loop, close the file after the loop.  You can write to the channels inside of the loop all you want.  You can even change which group (ie tab) is written to for whatever reason, in your case the date.


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 5 of 10
(5,336 Views)

Here I attached my VI.

I understand what you say about the loop but I was just testing to see if this would work. As I said in my first post, when I put the  'write to measurement file' outside the while loop, I have to stop the program, and then it writes only the number of data that the DAQ assistant read. When I put it inside, it appends the next set of measurements in a new tab in excel, creating a lot of them that isn't practical to handle.

 

What I want is to write the data ( I presume I can put a button to enable writing data or not whenever I want to) when I run the program with timestamps and append them to one file. Ideally, I would like to change the excel tab if the date changes so that I can have each days measurements in one tab and so on.

0 Kudos
Message 6 of 10
(5,316 Views)

First of all get away from the express VIs. Use DAQmx functions and TDMS functions. They're not difficult to use and will save you a LOT of headaches.

 

Next, TDMS is not an Excel file. TDMS is a binary file format that can be read into Excel with the appropriate add-on. The tabs that you see in Excel should correspond to group names - so if you want to write data to different tabs on different days you just change the group name. You have much better control of this using traditional functions.

0 Kudos
Message 7 of 10
(5,267 Views)

Hello guys, I really appreciated your help and it really helped me progress with my project.

Screenshot_1.png

 This is what I have built so far. I post it here first to get feedback (e.g maybe my code can become better). I also wanted to ask if there is a way to conditionally add a group to the tdms file ( like I said for every different day I want my measurements to be on a new group) or how to conditionally create a new tdms file when the date changes.

0 Kudos
Message 8 of 10
(5,174 Views)

@kapablanca wrote:

I also wanted to ask if there is a way to conditionally add a group to the tdms file ( like I said for every different day I want my measurements to be on a new group) or how to conditionally create a new tdms file when the date changes.


You just change which group you are writing to.  For your exact request, I would just use a Format Into String with a format of "%<%Y-%m-%d>T" and the input being the first timestamp in the time array.  This will give you a string that you can write directly to the group name using the year, month, and day as the basis of your 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 9 of 10
(5,163 Views)

To change the file, create a case structure with the TDMS reference wire going through.  Do a close, and open with a new name, when you want to change the file.

0 Kudos
Message 10 of 10
(5,154 Views)