Canvas uses JavaScript ES5 for scripting. Nearly all objects and functions that are supported in ES5 are available. 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.
...
Code Block |
---|
// Write an alarm CSV to the HMI's hard drive
alarm.createAllCsv(Storage.Local);
|
Code Block |
---|
// Write a CSV to a USB drive. Only contains alarms with the label "myLabel"
alarm.createCsv("myLabel", Storage.Usb); |
datalog
Provides a way to interact with Gateway data log models.
...
Code Block |
---|
// Enable the model, add one row of data, then disable the model again
datalog.start("myModel");
datalog.addRow("myModel");
datalog.stop("myModel");
|
Code Block |
---|
// Store a CSV with all data for the model
datalog.createCsv("myModel", Storage.Local);
|
Code Block |
---|
// Store a CSV with the past hour of data to an SD card
var current = new Date(Date.now());
var past = new Date(current);
past.setHours(past.getHours() - 1);
datalog.createCsvForRange("myModel", past, current, Storage.Sd); |
keyboard
Allows for sending keyboard events and bringing up keyboard popups for inputting values.
...
Code Block |
---|
// Open a numerical keypad to edit the value of "myTagnumericTag"
keyboard.launchKeypad("myTagnumericTag");
|
Code Block |
---|
// OpenEdit thea keypadnumerical tag withusing custom display options
keyboard.launchKeypad("myTagnumericTag", {"x": 100, "y": 200, "format": "HH"});
|
Code Block |
---|
// Open a text keyboard to edit a string tag
keyboard.launchKeyboard("stringTag");
|
Code Block |
---|
// OpenEdit a thestring keyboardtag with custom propertiesdisplay options
keyboard.launchKeyboard("stringTag", {"header": "Setting OtherTag", "x": 100, "y": 200}); |
notification
Provides a way to interact with the notifications system.
...
Code Block |
---|
// Send a notification to the screen
notification.send("Hello.");
|
Code Block |
---|
// Send a notification that automatically dismisses itself after 3 seconds
notification.send("Hello for a moment.", 3000); |
page
Allows for manipulation of project pages and the current page.
...
Code Block |
---|
// If the page "WarningPage" is currently open, open the page "WarningPopupPage"
// Otherwise, open the page with index 1
if (page.currentName() == "WarningPage") {
page.open("WarningPopupPage");
} else {
page.openIndex(1);
} |
schedule
Provides a way to enable and disable schedules.
...
Code Block |
---|
// Toggle whether the schedule "mySchedule" is enabled
schedule.setEnable("mySchedule", !schedule.isEnabled("mySchedule")); |
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 |
---|
// Store an alarm CSV to the USB drive
alarm.createCsv("Level 1", Storage.Usb);
|
Code Block |
---|
// Store an alarm CSV to the SD card
alarm.createCsv("Level 1", Storage.Sd);
|
Code Block |
---|
// Store a data log CSV to the HMI
datalog.createCsv("model", Storage.Local); |
system
Provides a way to interact with the runtime application.
...
Code Block |
---|
// Run a script in the same thread
system.importScript("someSequentialScript");
|
Code Block |
---|
// Run a script in a different thread
system.runScript("someLoopingScript")
|
Code Block |
---|
// Open the 3-touch config menu
system.openConfig();
|
Code Block |
---|
// Set the translation language to Spanish
system.setLanguage("Spanish");
|
Code Block |
---|
// Login as a user named "guest" that has no password
system.login("guest");
|
Code Block |
---|
// Open the login window and show the list of users in the project
system.openLoginWindow({"listUsers": true});
|
Code Block |
---|
// Open the authorization window and request the password for the user "myUser"
system.openAuthWindow({"username": "myUser"});
|
Code Block |
---|
// Logout the current user
system.logout();
|
Code Block |
---|
// Check if the current user has the "Admin" permission
if (system.hasPermission("Admin")) {
tag.write("someImportantTag", true);
} else {
notification.send("Error: insufficient permissions.");
}
|
Code Block |
---|
// Exit the runtime and stop the project
system.exit(); |
tag
Allows for the manipulation of tags.
...
Note: See the Reading and Writing Tag Values section for more information.
thread
Pauses the script for a specified amount of time. Only affects the calling script’s thread.
...
Examples:
Code Block |
---|
// Check whetherthe therevalue isof ana errortag once per second
// If theretrue, is,increment opena thedifferent errortag pagevalue
while (true) {
if (tag.read("errorCodedoIncrement") != 0) {
page.opentag.write("mytag", tag.read("errorPagemyTag") + 1);
}
thread.sleep(1);
} |
Code Block |
---|
// Gradually increase a tag value from 0 to 10 over the course of 1 second
var value = 0;
while (value < 10) {
value += 1; tag.write("myTag", value);
value += 1;
thread.msleep(100);
} |