LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

changing value of variable periodically

Solved!
Go to solution

Hi all

 

I want to change the value of the variable periodically such that on the front panel, the initial, final and incremental  value is to be defined by the user and the value of variable changes automatically after every 5 secs. and i also want the time interval to be defined by the user on the front panel. How is it possible?

 

Any help will be greatly appreciated

0 Kudos
Message 1 of 7
(4,413 Views)

Hi,

 

for changing/doing something periodically you can use a timer callback. You can change the timer interval programmatically, i.e. read the interval value from a contrl of your GUI and adjust the interva accordingly.

0 Kudos
Message 2 of 7
(4,412 Views)

and what about the remaining task...

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

What remaining task?

 

Wolfgang described what you need to do.  Here are a few more details.

 

Put numeric controls on your UI for everything you want the operator to be able to control (the variable's initial value, final value, and increment value, and the timer interval).  Put a timer control on your UI as well (this control isn't visible at runtime).

 

At the start of your program, use GetCtrlVal to read all the values.

Use SetCtrlAttirbute to set the timer interval, called ATTR_INTERVAL.

In the callback for the timer, on event EVENT_TIMER_TICK, read the variable's current value using GetCtrlVal, increment it by the increment value, then check it against the desired final value.  If the new value is greater than the final value, set it to the final value.  Use SetCtrlVal to display the new value.

 

If you want the operator to change values at any time while the program is running, you can read all the values on every timer tick.  Or create callbacks for your numeric control to reset the timer if the operator changes the timer interval.  Or provide a button to read the new values.  Or a checkbox to suspend timer operation while new values are entered.  If the operator is trying to update the variable value at the same time as the timer, results could be unexpected.

0 Kudos
Message 4 of 7
(4,401 Views)
Solution
Accepted by topic author mhs100

Take a look at the simple project attached.  You can change all values on the fly.  Changing the Initial Value or the timer Interval Value are asynchronous to the timer (the changes are made as soon as the operator changes the value on the user interface).  The other values are only updated when the timer clicks.  The difference is that I added callbacks for the Initial Value and the timer Interval Value.  Since those other values are only used when the timer clicks, they didn't need callbacks.  Their values are used in the timer callback.

 

I added a callback for the timer interval to allow an operator to correct a mistake.  For example, if they wanted to wait 10 seconds, but they entered 100, with the callback they don't need to wait 100 seconds before the timer is updated with the correction.

Message 5 of 7
(4,397 Views)

Hi mhs,

 

when I posted my reply late at night (for me) I was at home without CVI at my hands, so I could not tell you the exact attribute value, which is

SetCtrlAttribute (panel, PANEL_TIMER, ATTR_INTERVAL, interval)

 

But actually I was expecting that it should be possible using the provided information at least to realize that there is an example that comes with CVI. It is called timer.cws and shows the functionality.

 

There is a tool called example finder you can use to search for keywords such as timer...

 

 

0 Kudos
Message 6 of 7
(4,373 Views)

Wolfgang:

 

On a side note, NI's license agreement allows you to install a copy at home if you have a copy at work.

 

See the following note for details.

http://digital.ni.com/public.nsf/allkb/25D3687EACB9E02C86256D7500576AC6

 

Don't we all want to take our work home with us?

Message 7 of 7
(4,364 Views)