LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing data into measurement file only after a certain condition is met

Solved!
Go to solution

Hi all,

 

I have a producer/consumer loop with a NI-DAQmx acquiring one sample every second, which is then written into a measurement file along with its time interval (basically 0s, 1s, 2s and so on), which in turn gets sent into an excel file. When I start the program, it starts reading immediately and everything gets written into the measurement file. However this requires a bit of manual post-processing in Excel because I need to cut out the initial conditions data which is of no interest to me and reinitialize the time back to zero. To illustrate: I start the program, data starts being read and displayed, it takes me 4 seconds to make a change to the system, so for example

0s, 5

1s, 5

2s, 5

3s, 5

4s, 5

5s, 1

6s, 8

 

Everything before that 4 s can be ignored so I want the measurement file to read

0s, 5

1s, 1 

2s, 8

 

The thing is, I cannot set the data writing after a certain amount of elapsed time simply because the system change must be made manually and different users have different reaction times. I have an idea of maybe asking the program to only start writing data if the difference between the value and the next value crosses a certain threshold, and replace the time value to 0 s.

 

I feel this might be doable somehow using case structures but I'm not sure how to go about it. Ideally I would create a SubVI so I integrate it easily into the system. Can anyone give me an idea of how to accomplish this using Labview programatically, (without making a macro in Excel)?

 

Thanks in advance.

0 Kudos
Message 1 of 5
(2,579 Views)

Hi nikvl,

 

The thing is, I cannot set the data writing after a certain amount of elapsed time simply because the system change must be made manually and different users have different reaction times.

Can the user press a button (on the frontpanel of the VI) to actually start the logging?

 

I have an idea of maybe asking the program to only start writing data if the difference between the value and the next value crosses a certain threshold, and replace the time value to 0 s.

What is your idea?

From the description it sounds like a good one!

 

I feel this might be doable somehow using case structures but I'm not sure how to go about it.

What have you tried so far?

I would compare current reading with previous one (aka shift register!) until a certain condition is met to start the logging rountine…

Best regards,
GerdW


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

Can the user press a button (on the frontpanel of the VI) to actually start the logging?

No, they can press a button to export the data the into Excel (which where I want the processing to take place) though. On the front panel is a graph which they can watch the process (there are other buttons to set it to automatically stop measurements or manually if they want).

 

An extra button isn't helpful because the user either has to press the button first and then change the system (causing the same problem or unwanted extra data), or change the system and then press the button (losing valuable data which is worse) 

 

What is your idea?

Well right now the measurements are written into a text file as it is read, and after the measurement cycle is complete, pressing the aforementioned button reads that text file and sends that data into a pre-prepared Excel report template. The simple text file serves as a backup copy on the local drive (from experience sometimes the user forgets to save and starts a new measurement so all that past data is gone for nothing or simply if the measurement cycle has to be stopped halfway for whatever reason).

 

I do want to keep the text file as it is including all the unnecessary initial conditions just in case we ever need to refer to it (the curse of the engineer's instinct for redundancy haha). And only when the user presses the Export button, will the data be processed and pasted into the Excel sheet as I mentioned in the first post. 

 

An idea might be that I find the difference past a certain threshhold between two samples, and if that's true, to get to the time value of the previous value ("somehow"; I'm stuck here), subtract it from itself (to get 0), and every following time value to subtract that value. It feels rather unelegant though.

 

What have you tried so far?

I'm using the Get Date/Time in Seconds (one outside the While loop and one inside) to obtain the time interval by subtracting one from the other From other threads, I'm guessing it's not the most accurate way to get the time but I basically just need the amount of time of how the sample value continually changes from beginning to end. 

 

To be honest, I haven't tried anything yet (usually just through trial and error) because of work priority issues, so I'd hope to get pointed in the right direction.

 

I would compare current reading with previous one (aka shift register!) until a certain condition is met to start the logging rountine…

Point 2 above of wanting all data in the backup file but not in post-processing makes that not possible...  

 

 

0 Kudos
Message 3 of 5
(2,554 Views)
Solution
Accepted by topic author nikvl

Hi nikvl,

 

Well right now the measurements are written into a text file as it is read, and after the measurement cycle is complete, pressing the aforementioned button reads that text file and sends that data into a pre-prepared Excel report template. The simple text file serves as a backup copy

So now your requirements have changed quite a lot: now you are talking about two files, one of them being a safety backup for the full measurement.

But that should be no big deal: all you need to do is to define an exact condition on where to cut the data.

What is that condition?

Then all you need to to is to read the backup file line by line, check for your condition, and save the interesting lines to a second file…

 

I'm using the Get Date/Time in Seconds…

Once you found the interesting data samples you also know the new start time: simply subtract that new start time from the following timestamps to do an additional (time) offset correction…

 

Point 2 above of wanting all data in the backup file but not in post-processing makes that not possible...

Why not?

Still you probably want to compare previous with current data: use a shift register to do so!

Best regards,
GerdW


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

So now your requirements have changed quite a lot: now you are talking about two files, one of them being a safety backup for the full measurement.

No that was my original program, which maybe I should have explained from the start

 

But that should be no big deal: all you need to do is to define an exact condition on where to cut the data.

What is that condition?

Then all you need to to is to read the backup file line by line, check for your condition, and save the interesting lines to a second file…

I only wonder if it reads the backup file line by line, would it be reading strings or double...?

 

Once you found the interesting data samples you also know the new start time: simply subtract that new start time from the following timestamps to do an additional (time) offset correction…

 

Why not?

Still you probably want to compare previous with current data: use a shift register to do so!

Thanks for the tip. I'm going to try and hack at it and I'll report back if I get anything 🙂

0 Kudos
Message 5 of 5
(2,543 Views)