Canvas provides a set of utility functions for interacting with the project and with the Xpanel device.
...
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 |
---|---|---|---|
| Creates a CSV file of all alarms in the specified location. | enum storageType: see the |
|
| 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 |
|
datalog
Provides a way to interact with Gateway data log models.
Function Name | Description | Arguments | Returns |
---|---|---|---|
| Causes the specified logging model to begin logging. | string modelName: the name of the data log model to target. |
|
| Causes the specified logging model to stop logging. | string modelName: the name of the data log model to target. |
|
| Adds a single row to the specified logging model. | string modelName: the name of the data log model to target. |
|
| 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. |
|
| 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. |
|
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 |
---|---|---|---|
| Returns whether or not schedule title is enabled. | string title: the name of the schedule to check. |
|
| 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 ( |
|
system
Provides a way to interact with the runtime application.
Function Name | Description | Arguments | Returns | ||
---|---|---|---|---|---|
| Executes a script in the current project named scriptName on the current thread. Any variables and functions declared in the target script will become accessible in the calling script. Note: The calling script will not continue to execute until the target script finishes executing. | string scriptName: the name of the script to execute. | The value of the last expression of the specified script. For example, if the external script “myScript“ contains the following:
then This can be used to pass information from the target script to the calling script. | ||
| Executes a script in the current project named scriptName. Note: The target script will run on a separate thread. Execution of the calling script will immediately continue. The target script will not be able to access any variables defined in the calling script, and vice-versa. In most cases, it is recommended that you use | string scriptName: the name of the script to execute. |
| ||
| Opens the runtime config (3 touch) menu. | N/A |
| ||
| Opens the Xpanel Control Center (desktop). Note: This function does nothing in the simulator. | N/A |
| ||
| Sets the language used by the runtime translation feature. | string language: the name of the language to use. This should be one of the column names defined in the Translation Editor window. |
| ||
| Immediately logs in as the specified user for the runtime IAM feature. Note: Do not store user passwords using tags that can be accessed by other devices or by non-authorized users. | string username: the name of the IAM user to log in. string password: the password for the specified user. If the user does not have a password, you may omit this argument or use an empty string |
Note: a return value of | ||
| Opens the built-in dialog for logging in a user for the IAM system. Note: This function does not wait for user input, nor does it return whether the user was logged in. The rest of the script will be executed immediately. | object properties (optional): an object specifying optional properties to be used for the popup. See the properties section below for details. |
| ||
| Opens the built-in dialog for authenticating a user. The user will be required to re-enter their password.Note: This function blocks the event loop. If no user is specified, the current user will be used instead. If no user is logged in, the function will return false. Note: This function blocks the event loop. The calling script will not continue executing until the dialog is closed. | object properties: an object specifying optional properties to be used for the popup. See the properties section below for details. |
| ||
| Logs out the current user from the IAM system. | N/A |
| ||
| Checks to see if the current user has the specified permission. | string permission: the name of the permission to check. |
| ||
| Closes the current project and the runtime application. The gateway will also be closed if running on the same device. | N/A |
|
...
Property | Description |
---|---|
username | Sets the desired user to authenticate. If no user is provided, the current user will be used. If no user is logged in, return false immediately. |
Examples:
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.
...