Event Hooks

At the core of t is event hooks. Triggered when a specific event occurs, t treats hooks as functions, executing the code within its block in response. You can also have multiple definitions of each hook in a single script. When triggered, they will each execute in the order they appear in the script from top, to bottom. There are 10 hooks currently defined in the t programming language.

on start
This block executes when the t script starts. Right after the variables section has been initialized, all on start hooks will run.

on stop
Like on start, all on stop hooks will run once the program has been ordered to stop.

on key key
This hook activates when the specified key is pressed. This allows the user to trigger an event hook to occur on command. If more than one on key block is defined with the same key, the code in all blocks will run in sequence.

on Timer timer
When the designated timer expires, this hook will trigger.

on envvar variable
Whenever the designated environment variable is changed, including being assigned the same value. This hook is also called when a script is restarted if the environmental variables have been altered since the last time the script was run.

on CanMessage message
This hook triggers when the specified message arrives. This hook will not execute for CAN FD messages. The hook declaration provides methods for specifying the channel(s) being monitored by the hook and which message(s) trigger the hook.

on CanMessageFd message
When the specified CAN FD message arrives, this event hook will trigger. CAN FD messages are distinguished from Classical CAN messages by having the canMSGFD_FDF flag set. To capture error frames, even on a CAN FD bus, use the on CanMessage event hook.

on CanTpMessage event
The on CanTpMessage event hook executes when an event connected to the name of a CanTpHandle occurs. The connection is established using the canTpSetHandler() function.

on IoEvent event
The on IoEvent hook triggers when the specified I/O event occurs.

on exception
This hook triggers when an unrecoverable situation within a function occurs. If there are multiple on exception blocks defined, each block will execute in sequence. Within the block itself, this references the error that triggered the exception. Since this is a constant, only read access is allowed.

Lesson tags: t script, TRX
Back to: <em>t</em> Scripting > Basics of t