Execution of JavaScript functions

JavaScript functions are executed when events occur. For example, a user can define a script for the OnMouseClick event and the JavaScript script will be executed when the button is pressed on the HMI device.

JavaScript functions are executed only when the programmed event occurs and not cyclically. This approach minimizes the overhead required to execute logic in the HMI device.

JMobile Studio provides a JavaScript engine running on the client side. Each project page can contain scripts having a scope local to the page where they are added; global scripts can be created to be executed by scheduler events or alarm events.

In both cases scripts are executed on the client. This means that if more than one client is connected to the HMI device (for external computer running the HMI Client), each client will run the same script, providing different output results depending on the input, since inputs provided to different clients may be different.

For example, if a script acts according to the position of a slider and this position is different on the different clients, the result of the script will be different on each client.

JavaScript functions for page events

JavaScript editor will open when you add a JavaScript action inside an action list.

  1. Select the even that will execute the action.
  2. Add a JavaScript action from the Widget category.
  3. Either leave the default function name, or type a new one.
  4. Click OK to confirm: the JavaScript editor displays your function structure.

You can also open the JavaScript editor from the Script tab at the bottom of the workspace.

JavaScript functions for alarms and scheduled events

JavaScript code associated with alarms and scheduled events and not associated with a specific page, can be edited from the main Project properties page.

Path: ProjectView> double-click Project properties

Note: JavaScript actions are client actions so they are executed only when a client is logged in.

Shared JavaScript code

The project global variable can be used to share JavaScript code between the pages. Variables are created/initialized from the main JavaScript code from the main Project properties page and can then be used from the project pages.