PDA

View Full Version : AX JAVA Timer functions



k7faq
02-17-2010, 11:25 AM
I am looking for a way to implement a replacement for a Basic command of "if timeoff(myPoint) then ...somecode..."

in the 'Control Basic' world you could simply reference iftimeon() or iftimeoff() etc. of a point. I am looking to learn how to do the same in JAVA on the Tridium AX devices.

Thank you greatly for your thoughts!

Steven

leaflying
02-17-2010, 12:30 PM
Use BRelTime.

tshort
02-17-2010, 06:35 PM
BRelTime is part of it. Not sure how familiar you are with java and AX but here's a quick breakdown of a possible solution:

you need an action slot in your component, I've called it timerExpired():
timerExpired()
flags { hidden }

next you need an instance of Clock.Ticket that I've called ticket:

Clock.Ticket ticket;

You can have another slot in your component for you update time interval, I called my updateTime:

updateTime: BRelTime
default {[ BRelTime.make(12000l) ]}

finally you can have a method to run your timer and then do something when it expires:

void startTimer() {
if( ticket != null) ticket.cancel();
BRelTime time = getUpdateTime();
if(time.getMillis() != 0l)
ticket = Clock.schedulePeriodically(this, time, timerExpired, null);
}

public void doTimerExpired() {
calc();
}

So basically when the time expires the actin timerExpired is fired thus causing the event under the doTimerExpired() method to fire.

Hopefully this helps and isn't to confusing.