To download NI software, including the products shown below, visit ni.com/downloads.
Overview
This VI demonstrates how to perform a simple action every X number of minutes.
Description
Often it is necessary to perform a certain action at certain intervals, such as writing to a log file or updating a graph. Although the Elapsed Time Express VI will help perform this action, if we are trying to maximize the efficiency of our code, we may want to do this manually. This code demonstrates how to perform a simple action every X number of minutes, although it could easily be changed to occur by a second increment, and the action performed could be changed to be anything.
One common misunderstanding involving timestamps is that they are just a count of seconds that LabVIEW cleanly displays as time and date. We can perform calculations and comparisons on these timestamps, just like we could other many other data types. This code adds X number of minutes to the current time, and then saves that as the next time to execute the action. Within the while loop it is comparing the current time to the time of the next action, then once this the time has elapsed, it increments another X number of minutes onto the time of the next action and performs the action, in this case a simple switching of a boolean light.
Requirements
Steps to Implement or Execute Code
Additional Information or References
VI Snippet
**This document has been updated to meet the current required format for the NI Code Exchange.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
Sorry I need to save difference between one data each hour
Greetings Oscarin20, you could certainly achieve this, and any other activities that need occur on some kind of timed basis. In this example, you would changd your 'Minutes to Delay' to be 60. Inside the 'True' case I chose to use a boolean indicator that alternated states every time the time elapsed. You could certainly achieve calculating or saving a difference each hour by putting that code inside the case structure, instead of my code to alternate the boolean indicator.
I have a while loop running for 24hrs and I want that loop to pause and switch to another inner loop after every 30 minutes. Can you explain how to do that?
Due to dataflow, if your inner while loop is executing, the outer will not iterate until the inner finishes. Therefore, you could wrap your inner while loop in Case Structure using True/False. Basically inner loop would go inside where 'alternating light' is above. If the time has elapsed (TRUE), your inner while loop will start executing and run until it is stopped. If the time has not elapsed (FALSE) then the case structure is empty, and your outer loop keeps iterating without starting the inner loop.
In this scenario of 2 loops it would be important to at least use a local variable to capture your 'Stop' button inside the inner for loop, or else you wouldn't be able to stop your code until the inner loop finished. Better practice than a local variable would be to use an event structure, but that's well outside this discussion.