Hello All, We have a working function, as mentioned above. I'm sharing it if someone needs it. What it does is basically when PLC changes "Resim" variable, this function will run. Based on "Resim" and "UnitNo" variables, it'll change the path of the image which changes the image on screen. (function () {
/**
* replace module name with a custom name for the local-script.
*
* All local-script should be attached to the "custom.ls" package.
* If more than one script is required for an application, a common root package
* should be created (e.g. "custom.ls.customerName.*").
*/
var MODULE_NAME = "imageChangeScript",
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 */
function updateImage(val,basePath, control) {
// update control image,
// basePath_first = "pics/custom/parcaGoruntuleri/"; // for offline tryouts
// uniteNo = "virtual:deneme_uniteNo"
// basePath = basePath_first + uniteNo;
endPath = ".jpg"
control.vars.imageEl.src=basePath + val + endPath;
fLog("UpdateImage Mevcut basepath: " + control.vars.imageEl.src);
}
/* private functions */
/**
* Implements local-script run function.
*
* This function will be called each time a local-script will be enabled. dene
*
* @param {LocalScript} self instance reference of local-script control
*/
module.run = function (self) {
//Place your Code here
const im = shmi.requires("visuals.session.ItemManager");
self.vars = self.vars || {};
self.vars.cancelable = shmi.onReady({
controls: {
mainChangeImage: ".image_mainScreen"
}
}, function(resolved) {
const mainChangeImage = resolved.controls.mainChangeImage;
//self.vars.unitToken = im.subscribe(["virtual:deneme_uniteNo"], function(name, unitVal, type) { // for offline tryouts
self.vars.unitToken = im.subscribe(["unitNo"], function(name, unitVal, type) {
// This callback function is called automatically, whenever the value of the item changes
fLog("Unit No Mevcut: " + unitVal);
self.vars.unitNoYeni = unitVal; // store the unit value in self.vars
});
//self.vars.imageToken = im.subscribe(["virtual:imageChange_degisken"], function(name, val, type) { // for offline tryouts
self.vars.token = im.subscribe(["Resim"], function(name, val, type) {
// This callback function is called automatically, whenever the value of the item changes
// check for value of subscribed item and update image
if (typeof val === "string") {
// get unit value
const unitNoYeni = self.vars.unitNoYeni;
fLog("OP bilgi unitNoYeni mevcut: " + unitNoYeni);
fLog("OP bilgi Resim Degiskeni mevcut: " + val);
// construct basePath, check PLC inits to 0_ and display initilization image
if (val === '0_') {
const basePath = "pics/custom/parcaGoruntuleri/";
fLog("OP bilgi basePath val === 0_: " + basePath);
updateImage(val, basePath, mainChangeImage);
}
if (val != '0_') {
const basePath = "pics/custom/parcaGoruntuleri/" + unitNoYeni + "/";
fLog("OP bilgi basePath val != 0_: " + basePath);
updateImage(val, basePath, mainChangeImage);
}
//updateImage(val, basePath, mainChangeImage);
//fLog("OP bilgi basePath: " + basePath);
}
});
});
/* called when this local-script is disabled */
self.onDisable = function () {
self.run = false; /* from original .onDisable function of LocalScript control */
// unsubscribe item - this is very important - otherwise memory leaks might occur
if (self.vars.token) {
self.vars.token.unlisten();
}
if (self.vars.unitToken) {
self.vars.unitToken.unlisten();
}
// cancel shmi.onReady to ensure there will nothing be running in the background anymore if the widgets have not been found
if (self.vars.cancelable) {
self.vars.cancelable.cancel();
}
};
};
// MODULE CODE - END
fLog("module loaded");
})();
... View more