@webiq-sk wrote: "The issue is that internal to the js code, there is no way to access the .value of an item and read that as an integer." Sure there is - there are two ways available: 1. When you only need a one-shot read: readDirect 2. When you want to react to continuous item changes: subscribeItem Here is the corresponding code from the scripting demo ("demo-item-subscribe") that illustrates this: // Define our item names to use - it's best to put them here and not somewhere in the code below
// for easier changeability and understanding
const observedItemName = 'ls-observed-item';
// See below
let subscriptionToken = null;
// Get a reference to the ItemManager
const im = shmi.requires("visuals.session.ItemManager");
// Create a new instance of an item handler to use and define a function that will be called
// asynchronously by the framework whenever the item value changes (or is received initially)
const myItemHandler = im.getItemHandler();
myItemHandler.setValue = function (value) {
console.log("[LS demo-item-subscribe] The value of the item has been set to " + value);
};
// Obtain a subscription token. You ALWAYS have to store this token and call the appropriate unlisten function
// when you no longer need it, in this case when the LocalScript will be disabled (see below)
// If you do not do that this will likely cause memory leaks (https://blog.logrocket.com/escape-memory-leaks-javascript/)
// leading to more and more RAM used in your HMI until the amount of free RAM will be exhausted and the browser will crash
// The WebIQ Visuals framework always calls the onDisable function automatically when your LocalScript should not be running anymore,
// e.g. when it has been included in a screen view and the user switches to another screen.
subscriptionToken = im.subscribeItem(observedItemName, myItemHandler);
/* called when this local-script is disabled */
self.onDisable = function () {
if (subscriptionToken) {
subscriptionToken.unlisten(); // Remove the listener and tell WebIQ Server to stop sending us item updates
}
self.run = false; /* from original .onDisable function of LocalScript control */
}; And if your item does not have the type integer in your PLC you can of course cast it with JavaScripts parseInt() method into an integer value. I am sorry for the things I said while i was pretending to be a programmer. this was certainly the fix for everything i was fighting. i had tried to implement this yesterday but must have really messed it up. my second attempt today went much better. it works, does exactly what I need it to do. I am now in the refinement process and will start add additional features. i appropriate the guidance.
... View more