Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Canvas uses JavaScript ES5 for scripting. All Nearly all JavaScript objects and functions that are supported in ES5 are available for use in Canvas scripts. For a complete list of supported features, see the ES5 specification: https://262.ecma-international.org/5.1/ .

...

Below is a list of the built-in functions provided by Canvas.

alarm

Provides a way to interact with Gateway alarms.

Function Name

Description

Arguments

Returns

alarm.createAllCsv(enum storageType)

Creates a CSV file of all alarms in the specified location.

enum storageType: see the Storage section below.

undefined

alarm.createCsv(string label, Storage type)

Creates a CSV file of all alarms with the specified label in the specified location.

string label: the name of an alarm label to use as a filter.

Storage type: see the Storage section below.

undefined

datalog

Provides a way to interact with Gateway data log models.

Function Name

Description

Arguments

Returns

datalog.start(string modelName)

Causes the specified logging model to begin logging.

string modelName: the name of the data log model to target.

undefined

datalog.stop(string modelName)

Causes the specified logging model to stop logging.

string modelName: the name of the data log model to target.

undefined

datalog.addRow(string modelName)

Adds a single row to the specified logging model.

string modelName: the name of the data log model to target.

undefined

datalog.createCsv(string modelName, enum storageType)

Creates a CSV file of the specified logging model in the specified location.

string modelName: the name of the data log model to target.

enum storageType: see the Storage section below.

undefined

datalog.createCsvForRange(string modelName, Date start, Date end, enum storageType)

Creates a CSV file of the specified logging model, in the specified location, within some time bound.

string modelName: the name of the data log model to target.

Date start: a JavaScript Date object specifying the beginning of the time range.

Date stop: a JavaScript Date object specifying the end of the time range.

enum storageType: see the Storage section below.

undefined

keyboard

Allows for sending keyboard events and bringing up keyboard popups for inputting values.

...

Code Block
keyboard.launchKeypad("MyTag");
keyboard.launchKeypad("MyTag", {"x": 100, "y": 200, "format": "HH"});

keyboard.launchKeyboard("OtherTag");
keyboard.launchKeyboard("OtherTag", {"header": "Setting OtherTag", "x": 100, "y": 200});

notification

Provides a way to interact with the notifications system.

...

Code Block
notification.send("This notification will dismiss itself after a few seconds.", 3000);
notification.send("This notification won't automatically dismiss.");

schedule

Provides a way to enable and disable schedules.

Function Name

Description

Arguments

Returns

schedule.isEnabled(string title)

Returns whether or not schedule title is enabled.

string title: the name of the schedule to check.

true if the schedule is enabled, otherwise false.

schedule.setEnable(string title, bool enable)

Enables schedule title if enable is true; otherwise turns schedule off.

string title: the name of the schedule to check.

bool enable: whether to enable (true) or disable (false) the specified schedule.

undefined

system

Provides a way to interact with the runtime application.

...

Code Block
system.openLoginWindow("listUsers": true); // opens the login window with a list of users
system.openAuthWindow("username": "myUser") // opens the authorization window and requests the password for the user "myUser"

page

Allows for manipulation of project pages and the current page.

...

Code Block
if (currentPage() === "MyPage") {
  openPage("ABasicPopupPage"); // By name
} else {
  openPage(1); // By index
}

Storage

The Storage object allows you to specify a location for saving various data within scripts. Either the numerical value (0, 1, 2, 3) or the enum value (Storage.Invalid, Storage.Local, Storage.Usb, Storage.SdCard) may be used whenever a storageType argument is required.

...

Code Block
alarm.createCsv("Level 1", Storage.Usb)
datalog.createCsv("model", Storage.Local)

tag

Allows for the manipulation of tags.

...

Code Block
tag.write("MyTag1", tag.read("MyOtherTag") + 20);

thread

Pauses the script for a specified amount of time. Only affects the calling script’s thread.

...