First I would suggest serializing the robot positions (in your PLC application) into a single JSON string:
This will allow you to subscribe to a single item in your WebIQ application, plus it will ensure consistancy of the position data.
To build the JSON you could employ one of the official libraries - CODESYS provides one - but in this case it suffices to build it by hand:
In WebIQ, map the single JSON string (here: Position) over OPC UA. A local script to subscribe to this one item, then parse it and reconstruct the real array is shown below:
(function () {
var MODULE_NAME = "robot_position",
ENABLE_LOGGING = false,
RECORD_LOG = false,
logger = shmi.requires("visuals.tools.logging").createLogger(MODULE_NAME, ENABLE_LOGGING, RECORD_LOG),
fLog = logger.fLog,
log = logger.log,
module = shmi.pkg( MODULE_NAME );
// MODULE CODE - START
/* private variables */
/* private functions */
/**
* Implements local-script run function.
*
* This function will be called each time a local-script will be enabled.
*
* @param {LocalScript} self instance reference of local-script control
*/
module.run = function (self) {
//Place your Code here
var im = shmi.requires("visuals.session.ItemManager"),
userManager = shmi.visuals.session.UserManager,
itemHandler = im.getItemHandler(),
tok = null;
itemHandler.setValue = function(v) {
let _v = JSON.parse(v); // parse string into a json object
// for demonstration: just write values into WebIQ variables
for (let i = 0; i < 6; i++) {
// adapt example here to set three.js robot positions
im.writeValue(`positions[${i}]`, parseFloat(_v.Position[i]));
}
};
// subscribe item means: Every time, when item value changes function itemHandler is called
tok = im.subscribeItem( "position", itemHandler);
/* called when this local-script is disabled */
self.onDisable = function () {
tok.unlisten(); // remove subscription
self.run = false; /* from original .onDisable function of LocalScript control */
};
};
// MODULE CODE - END
fLog("module loaded");
})();
Modify it as required to tie into your three.js model. Sample output (crude) would look like:
WebIQ project attached.
... View more