trigger

This module provides a unified public interface for creating and managing event-based triggers within the Total Control system.
It allows developers to bind callback functions to system events (e.g. device connect, system start), as well as custom image-based or logic-based conditions.

Key Features:

  • Create triggers for various system events: startup, shutdown, device connection/disconnection, etc.
  • Support for image-based triggers ("Image:SeekImage").
  • Associate multiple callback functions with each trigger.
  • Enable, disable, query, or remove triggers at runtime.
  • Inspect registered triggers and their associated callbacks.

Basic Usage:

  1. Create a trigger using new Trigger(type, name)
  2. Register a callback using .setCallback(fn)
  3. Optionally enable or disable the trigger
  4. Use Trigger.list(), Trigger.exists(), or Trigger.deleteTrigger() to manage lifecycle

Supported Trigger Types (type):

  • tcConst.TC_START: Total Control system starts
  • tcConst.TC_END: Total Control system stops
  • tcConst.DEV_CONNECT: Device connects
  • tcConst.DEV_DISCONNECT: Device disconnects
  • "Image:SeekImage": Custom trigger for detecting image appearance

Static Utility Functions:

  • Trigger.list(): Get all registered triggers
  • Trigger.deleteTrigger(nameOrType): Delete a trigger by name or type
  • Trigger.exists(nameOrType): Check if a trigger exists
  • Trigger.clearAll(): Delete all triggers in the system

This module attaches all functionality under the Trigger class and exports it for runtime event scripting within Total Control.

Classes

Trigger

clearAll() → {number}

Delete all triggers registered in the current system.

Example
var { Trigger } = require("sigma/trigger");

var count = Trigger.clearAll();
print("Total deleted triggers: " + count);
Returns:
number

Returns the number of triggers that were deleted.

deleteTrigger(nameOrType) → {boolean}

Delete a trigger by name or type. You can delete an event trigger based on the name of the trigger, or you can delete all triggers of a type based on the type of the trigger.
Note:
In the UI, listener functions that you add can be found by navigating to [Script] → [Inspect].

Example
var { Trigger } = require("sigma/trigger");
// Create listener function for event trigger
function callback1() {
 print("this is test");
}

function callback2() {
 print("this is test too");
}

// Create an event trigger object
var t1 = new Trigger(tcConst.DEV_CONNECT, "DEV_CONNECT_Trigger1");
var t2= new Trigger(tcConst.TC_START, "T_Start_Trigger2");

// Call listener function
t1.setCallback(callback1);
t2.setCallback(callback2);

// Delete the trigger named DEV_CONNECT_Trigger1.
Trigger.deleteTrigger("DEV_CONNECT_Trigger1");

// Delete the event trigger of type tcConst.TC_START.
Trigger.deleteTrigger(tcConst.TC_START);

// Get all trigger events registered in the current system.
var triggersList = Trigger.list();
if (triggersList.length > 0) {
 for (var i = 0; i< triggersList.length; i++) {
   var trigger = triggersList[i];
   var name = trigger.getName();
   print("Trigger's name is:" + name);
 }
} else {
 print("Two event triggers have been deleted.");
}

// If it executes successfully, it will return:
Two event triggers have been deleted.
Parameters:
string nameOrType

The name of the event trigger. The type of event trigger.

type:

  • tcConst.TC_START: Total Control system starts;
  • tcConst.TC_END: The Total Control system is stopped;
  • tcConst.DEV_CONNECT: Device connection;
  • tcConst.DEV_DISCONNECT: The device is disconnected;
Returns:
boolean

exists(nameOrType) → {boolean}

Check whether a trigger exists by name or type.

Example
var { Trigger } = require("sigma/trigger");

if (Trigger.exists("T_Start_Trigger")) {
  print("Trigger exists by name");
}

if (Trigger.exists(tcConst.TC_START)) {
  print("Trigger exists by type");
}
Parameters:
string nameOrType

The name or type of the trigger to check.

Returns:
boolean

Returns true if a matching trigger is found, otherwise false.

list() → {Array}

Get all trigger events registered in the current system.

Example
var { Trigger } = require("sigma/trigger");

//  Method: callTest1
function callTest1() {
  print('1: T start');
}

// Method: callTest2
function callTest2() {
  print('2: T start');
}

// Create an event trigger object
var t1 = new Trigger(tcConst.TC_START, "T_Start_Trigger1");

// Call the method callTest1
t1.setCallback(callTest1);

// Create an event trigger object
var t2 = new Trigger(tcConst.DEV_CONNECT, "T_Start_Trigger2");

// Call the method callTest2
t2.setCallback(callTest2);

// Get all trigger events registered in the current system.
var triggersList = Trigger.list();

// Output the value of the triggersList.
print("The value of triggersList is: " + triggersList);

if ( triggersList > 0 ) {
 for (var i = 0; i < triggersList.length; i++) {
	  const trigger = triggersList[i];
	  const name = trigger.getName();
	  print("The name of the event trigger is: " + name);
	  const callbacks = trigger.getCallbacks();
	  for (var j = 0; j < callbacks.length; j++) {
	    print("callback's name is : " + callbacks[j]);
	  }
 }
}

//If it executes successfully, it will return:
1: T start
2: T start
The value of triggersList is: [object Object]
The name of the event trigger is: T_Start_Trigger
callback's name is : callTest1
Returns:
Array

If successful, returns a list of event triggers in array format. If it fails, you can get the specific error message through the lastError() function.