LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

When program is aborted it automatically saves the data into log file

Solved!
Go to solution

Hi all 

 

when vi abort due to power cut or someone abort it actually saves the data into the log file.

 

Example:

I have Vi outside the while loop I am saving the data to file when this while loop completes.

what if someone aborted it, it should have the data in a log file.

0 Kudos
Message 1 of 14
(1,333 Views)
Solution
Accepted by Basavaraj093

Hi Basavaraj,

 


@Basavaraj093 wrote:

Example:

I have Vi outside the while loop I am saving the data to file when this while loop completes.

what if someone aborted it, it should have the data in a log file.


Simple solution: write the data to your log file "inside the loop" instead of "after the loop"…

 


@Basavaraj093 wrote:

when vi abort due to power cut … it actually saves the data into the log file.


Simple solution: place a UPS next to your computer and react on the "active" signal of this UPS…

 


@Basavaraj093 wrote:

when vi abort due to … someone abort it actually saves the data into the log file.


Simple solution: create an EXE from your VI and prohibit the "aborting" of this EXE…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 14
(1,329 Views)

@Basavaraj093 wrote:

Hi all 

 

when vi abort due to power cut or someone abort it actually saves the data into the log file.

 

Example:

I have Vi outside the while loop I am saving the data to file when this while loop completes.

what if someone aborted it, it should have the data in a log file.


The only way someone can "abort" a loop is if you are running your program from the LabVIEW development environment. You should NOT be doing that. You should be building executables and running them.

 

A properly written program could have an "abort" button that would exit the loop and save your data. Using events like "Panel Closed" in an executable can also trigger your program to save the data when someone closes the window.

 

 

========================
=== Engineer Ambiguously ===
========================
Message 3 of 14
(1,104 Views)

@Basavaraj093 wrote:

when vi abort due to power cut ....


As an additional note, if the power is cut, you might lose the last log entries due to disk caching unless you flush. Of course using that lowers performance.

 

Another possibility is a computer crash due to some other running process or faulty driver (... or even a bug in your own code!) and an UPS won't help there.

 

All other scenarios need to be handled in code as has been explained already.

Message 4 of 14
(1,007 Views)

Of course, there is a case of hard drive corruption due to power loss (it may happen), then these precautions are useless if hard drive cannot be recovered.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 5 of 14
(986 Views)

Its working fine but it also makes it run slow,

 

for example, if you want to stop loop at exact 30min using elapsed time, it stops loop when time is elapsed, but it also skips some seconds during logging data into the excel. 

 

 

 

0 Kudos
Message 6 of 14
(870 Views)

Hi Basavaraj,

 


@Basavaraj093 wrote:

Its working fine but it also makes it run slow,

 

for example, if you want to stop loop at exact 30min using elapsed time, it stops loop when time is elapsed, but it also skips some seconds during logging data into the excel. 


Yes. This is by (your) code design!

 

  • You might think about using a producer-consumer scheme to decouple DAQ from file operations.
  • You might think about using a different file format to increase speed of file operations. "Excel" tends to be one of the slowest options…
Best regards,
GerdW


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

@Basavaraj093 wrote:

Its working fine but it also makes it run slow,

 

for example, if you want to stop loop at exact 30min using elapsed time, it stops loop when time is elapsed, but it also skips some seconds during logging data into the excel. 


"Make it run slow" and "exactly" are very poorly defined terms. You probably know the loop rate and the program can stop according to the number of iterations instead of elapsed time. 

 

Typically, the acquisition time is important. The time for saving is not part of the experiment and is irrelevant. In order to efficiently save, you need to use an efficient file format (e.g.open the file once, keep it open while appending data, and only close it at the end). Most high level file IO will open/close the file around each write, which is significantly more expensive. In addition, the saving can be done in a parallel loop where more jitter is acceptable.

Message 8 of 14
(395 Views)

As you said i tried but I am getting to many readings in log file, I want every minute reading. But here i am getting to many.

 

 

0 Kudos
Message 9 of 14
(271 Views)

Your spin your loop every 10ms but only look at integer seconds so the remainder will be zero ~100 times (at 0, 10, 20, 30, 40... 990ms, unless the saving takes more than 10ms).

0 Kudos
Message 10 of 14
(260 Views)