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 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 |
---|
// 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 |
---|
// Edit a string tag with custom display 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 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 a data log CSV to the HMI datalog.createCsv("model", Storage.Local); |
system
Provides a way to interact with the runtime application.
...
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.
...