JS Object SDK Documentation

JS Object is first released in EasyBuilder Pro v6.05.01 in 2020.
The goal of this object is to help create an user-customizable object.

Quick Start

When a JS Object is created, this refers to the JsObject itself.

console.log("Hello World");
console.log("Config:", this.config);
console.log("State:", this.state);

MouseArea

To capture any mouse event, use MouseArea.
It must be created and added to the widget container for it to start working.

var ma = new MouseArea();
ma.on("mousedown", function(e) {
    console.log("I am clicked");
})
this.widget.add(ma);

Canvas

To draw something, use Canvas.
Same as MouseArea, it must be created and added to widget container.

var canvas = new Canvas();
this.widget.add(canvas);
// draw text
canvas.fillStyle = "black";
canvas.font = `10px Consolas`;
canvas.fillText("Hello World", 0, 10);
// draw a rectangle
canvas.fillStyle = 'green';
canvas.fillRect(20, 20, 150, 100);

Read Device Data (Synchonous)

To read Device/PLC data, you need to configure the address beforehand in [Config] tab of JS Object.

Assume we have configured one called param1 as driver.Address.
We can retrieve its value by calling driver.promises.getData with await and promises

var data = await driver.promises.getData(this.config.param1, 1);
console.log(data.values[0]);

Read Device Data (Asynchonous)

To read Device/PLC data, you need to configure the address beforehand in [Config] tab of JS Object.

Assume we have configured one called param1 as driver.Address.
We can retrieve its value by calling driver.getData with a callback.

driver.getData(this.config.param1, 1, function(err, data) {
    if (err) {
        console.log('Error:', err.message);
    } else {
        console.log(data.values[0]);
    }
});

Runtime Context

When a JS Object is created, it will be given a context shared with all other JS object in the same window.
See window.

JS Object Changelog

Listed according to EasyBuilder Pro versions: