Difference between revisions of "IC Python API:RLPy RPyTimer"
Chuck (RL) (Talk | contribs) m |
Chuck (RL) (Talk | contribs) m |
||
Line 7: | Line 7: | ||
This class is used to setup a timed event. Use [[#SetInterval ( self, nMSec )|SetInterval]] and [[#GetInterval ( self )|GetInterval]] to access and set the time interval. Use [[#SetSingleShot ( self, bSingleShot )|SetSingleShot]] and [[#IsSingleShot ( self )|IsSingleShot]] to access and set the trigger state (single shot or repeatly trigger). Use [[#RPyTimer.Start ( self )|Start]], [[#Stop ( self )|Stop]], and [[#IsRunning ( self )|IsRunning]] to control the execution of the Timer. | This class is used to setup a timed event. Use [[#SetInterval ( self, nMSec )|SetInterval]] and [[#GetInterval ( self )|GetInterval]] to access and set the time interval. Use [[#SetSingleShot ( self, bSingleShot )|SetSingleShot]] and [[#IsSingleShot ( self )|IsSingleShot]] to access and set the trigger state (single shot or repeatly trigger). Use [[#RPyTimer.Start ( self )|Start]], [[#Stop ( self )|Stop]], and [[#IsRunning ( self )|IsRunning]] to control the execution of the Timer. | ||
− | In order to receive trigger events, first create a new class and inherit from | + | In order to receive trigger events, first create a new class and inherit from [[IC_Python_API:RLPy_RPyTimerCallback|RPyTimerCallback]]and register with [[#RegisterPyTimerCallback ( self, pCallback )|RegisterPyTimerCallback]]. When not in use, you can unregister the timer event with [[#UnregisterPyTimerCallback ( self, pCallback )|UnRegisterPyTimerCallback]]. |
− | See Also: [[IC_Python_API:RLPy_RPyTimerCallback|RPyTimerCallback]] | + | *See Also: [[IC_Python_API:RLPy_RPyTimerCallback|RPyTimerCallback]]. |
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
Line 36: | Line 36: | ||
=== GetInterval ( self ) === | === GetInterval ( self ) === | ||
− | Get the time interval for the event triggered by the timer in milliseconds. The default interval value is 0, which will cause the timer to start triggering immediately after | + | Get the time interval for the event triggered by the timer in milliseconds. The default interval value is 0, which will cause the timer to start triggering immediately after [[#Start ( self )|Start]]. |
See Also: [[#SetInterval ( self, nMSec )|SetInterval]] | See Also: [[#SetInterval ( self, nMSec )|SetInterval]] | ||
Line 86: | Line 86: | ||
==== Parameters ==== | ==== Parameters ==== | ||
− | :pCallback [IN] Callback object inherited from | + | :'''pCallback''' [IN] Callback object inherited from [[IC_Python_API:RLPy_RPyTimerCallback|RPyTimerCallback]]- [[IC_Python_API:RLPy_RPyTimerCallback|RPyTimerCallback]] |
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
Line 127: | Line 127: | ||
==== Parameters ==== | ==== Parameters ==== | ||
− | :nMSec [IN] Timer interval in milliseconds - int | + | :'''nMSec''' [IN] Timer interval in milliseconds - int |
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
Line 142: | Line 142: | ||
==== Parameters ==== | ==== Parameters ==== | ||
− | :bSingleShot [IN] Set to single-shot triggering - bool | + | :'''bSingleShot''' [IN] Set to single-shot triggering - bool |
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> |
Revision as of 22:27, 8 April 2020
Contents
- 1 Description
- 2 Member Functions
- Main article: Modules.
- Last modified: 04/8/2020
Description
This class is used to setup a timed event. Use SetInterval and GetInterval to access and set the time interval. Use SetSingleShot and IsSingleShot to access and set the trigger state (single shot or repeatly trigger). Use Start, Stop, and IsRunning to control the execution of the Timer.
In order to receive trigger events, first create a new class and inherit from RPyTimerCallbackand register with RegisterPyTimerCallback. When not in use, you can unregister the timer event with UnRegisterPyTimerCallback.
- See Also: RPyTimerCallback.
class MyPyTimerCallback(RLPy.RPyTimerCallback):
def __init__(self):
RLPy.RPyTimerCallback.__init__(self)
def Timeout(self):
print ("timeout")
# Set Timer
timer = RLPy.RPyTimer()
timer.SetInterval(100)
timer.SetSingleShot(True)
print(timer.GetInterval()) # 100
# Register the callback
timer_callback = MyPyTimerCallback()
timer.RegisterPyTimerCallback(timer_callback)
# Start the Timer
timer.Start()
# Unregister the callback
timer.UnregisterPyTimerCallback()
Member Functions
GetInterval ( self )
Get the time interval for the event triggered by the timer in milliseconds. The default interval value is 0, which will cause the timer to start triggering immediately after Start.
See Also: SetInterval
Returns
- Timer interval ( milisecond ) - int
timer = RLPy.RPyTimer()
timer.SetInterval(1000)
print (timer.GetInterval()) # 1000
IsRunning ( self )
Check if the Timer is currently running.
Returns
- True if the timer is currenlty running, else False - bool
timer = RLPy.RPyTimer()
timer.Start()
print (timer.IsRunning()) # True
IsSingleShot ( self )
Get the Timer trigger settings. Return True if the trigger is single-shot and False for repeat trigger.
See Also: SetSingleShot
Returns
- True if trigger is single-shot, else False - bool
timer = RLPy.RPyTimer()
timer.SetSingleShot(True)
print (timer.IsSingleShot()) # True
RegisterPyTimerCallback ( self, pCallback )
Register a Callback object with the Timer.
See Also: UnregisterPyTimerCallback
Parameters
- pCallback [IN] Callback object inherited from RPyTimerCallback- RPyTimerCallback
class MyPyTimerCallback(RLPy.RPyTimerCallback):
def __init__(self):
RLPy.RPyTimerCallback.__init__(self)
def Timeout(self):
print ("timeout")
timer = RLPy.RPyTimer()
timer_callback = MyPyTimerCallback()
timer.RegisterPyTimerCallback(timer_callback)
UnregisterPyTimerCallback ( self, pCallback )
Unregister the Callback object for the Timer.
See Also: RegisterPyTimerCallback
class MyPyTimerCallback(RLPy.RPyTimerCallback):
def __init__(self):
RLPy.RPyTimerCallback.__init__(self)
def Timeout(self):
print ("timeout")
timer = RLPy.RPyTimer()
timer_callback = MyPyTimerCallback()
timer.RegisterPyTimerCallback(timer_callback)
# unregister callback
timer.UnregisterPyTimerCallback()
SetInterval ( self, nMSec )
Set the Timer trigger interval in milliseconds. The default interval value is 0, which will cause the timer to start triggering immediately after Start().
See Also: GetInterval
Parameters
- nMSec [IN] Timer interval in milliseconds - int
timer = RLPy.RPyTimer()
timer.SetInterval(1000)
print (timer.GetInterval()) # 1000
SetSingleShot ( self, bSingleShot )
Set the Timer trigger state. Single-shot will only fire off the trigger event once, otherwise the event will fire off according to the Timer interval. The default setting is False.
See Also: IsSingleShot
Parameters
- bSingleShot [IN] Set to single-shot triggering - bool
timer = RLPy.RPyTimer()
timer.SetSingleShot(True)
print (timer.IsSingleShot()) # True
Start ( self )
Start or restart the Timer. If the Timer is already running, then this operation will stop the Timer first then start it again. If the trigger is set to single-shot then the Timer event will activate one more time.
timer = RLPy.RPyTimer()
timer.SetInterval(100)
timer.Start()
Stop ( self )
Stop the Timer.
timer = RLPy.RPyTimer()
timer.SetInterval(100)
timer.Start()
# do something
timer.Stop()