LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write to file in .txt every hour for 30 seconds (Save data, data saving)

Hi, guys.

I have a trouble with saving data in VI. I think it would be simple, but I don't know how to solve it...

 

I will use DAQ assistant to measure 4 sensors, but I keep working on the data save process before doing that with waveform formula.

 

In my VI, data is saved in every hour into the .txt format, for 1 second only.

I want to save data for 30 seconds or for 1 minute in every hour.

(because in the real process, I need measurement results for 5 minutes at least).

 

so is it possible to do this easily without adding loop structure?

I found some questions related to mine, they are similar but I don't understand how it works...

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

Hi MSK,

 

no need for one more loop. And no need for your inner While loop!

 

All you need is to use ElapsedTime together with an additional shift register. Keep the state of the "save? condition in the shift register.

When state is FALSE you have ElapsedTime to wait for 59min, when state is TRUE you have a wait target of 1min.

Change/negate the state when the time has elapsed…

Best regards,
GerdW


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

I'd probably get time as time record and check the Minutes. If it's 0, sample and record. That way it'll record the 1st minute of the hour, every hour.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 7
(3,105 Views)

you can certainly use the elapsed time VI to trigger the acquisition and save.  This approach, however, means that you are only reading your sensors during that time; a short window once an hour in your case.

 

If you attack the problem from the other direction, you can get a more fluid user interface and even enable some emergency actions if required (sensor value out of range type of things).  Look at Action Engine (AE)  https://forums.ni.com/t5/LabVIEW/Community-Nugget-4-08-2007-Action-Engines/m-p/503801#M240328    for your data storage.

 

1) based on your sampling rate and desired save window (30 sec, 45 sec, whatever) initialize your AE shift registers with an array of the required size.  Think of this as a data buffer

2) Continually sample your sensors, updating the front panel and the AE with the new values  (rotate 1D array   combined with in-place structure "replace array element"); buffer update (most recent N values)

           2a) using an array of set size and the "in-place" structure keeps your memory segment within the OS as a contiguous segment.

           2b) since you are continuously sampling the sensors, you can add logic for emergency situations (process out of control) and respond accordingly (notification or even emergency shut down if you have that level of control with your hardware)

3) in terms of data saving, you can again rely on the "elapsed time" vi to trigger the save.  In this case, however, you will simply fetch the values from your AE data buffer and write them to the file.  As opposed to triggering a hardware data fetch event.

4) for implementing this, think two parallel loops  (this is why i suggest the Action Engine as opposed to simple shift registers).  1 for monitoring the sensors and updating the AE "buffer" (for lack of a better word).  The other loop will check for "elapsed time" and save.

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

Thanks for your comment

But the problem is that I don't understand how to use the shift register to realize this code because I never used LabVIEW like this before.

 

If you don't mind, could you show me the example?

I am just trying to erase inner while loop and change the condition loop, but still it is hard to do this...

 

I am really sorry to bother you with this...

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

You can watch the link below.

It explains "How to use Shift Registers" 

https://forums.ni.com/t5/forums/replypage/board-id/170/message-id/1096630

0 Kudos
Message 6 of 7
(3,028 Views)

Hi MSK,

 

the problem is that I don't understand how to use the shift register to realize this code because I never used LabVIEW like this before.

Then you should take those FREE online resources offered to you to learn LabVIEW.

See at the top of this LabVIEW board for "Training resources"!

 

If you don't mind, could you show me the example?

I don't mind:

check.png

(Using XOR to negate the boolean condition when time has elapsed. I love boolean logic operations…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 7
(3,021 Views)