FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
06-23-2023 08:03 PM
I am following this guide on using unit classes for unit conversion. When I cycle power the unit selection is lost. Is there a way to retain the unit selection?
Solved! Go to Solution.
06-26-2023 08:11 AM
Unit classes exist only in the frontend, i.e. the browser. Therefore, even if you open the HMI on another system and have changed the unit classes on the first system before the second one will still show the defaults.
You could in theory simply create a LocalScript that does this:
- listen constantly to all virtual:unitclass-1-adapter item changes
- write the value on change to a non-virtual item
- in that same LocalScript initially read the value of that non-virtual item and set the unit class virtual items accordingly
- put the LocalScript inside your HMI so that it is always executed when the HMI is started
This however would result in all HMIs always showing the same unit classes on load that were last selected in any other browser and not allow different unit classes per instance.
If you want to use the same unit classes by default on all browsers anyway you could simply change the order of the elements in "unitClasses" in the JSON file so that the defaults are listed first.
Alternatively, you could bind it to the browser itself using localStorage: https://www.digitalocean.com/community/tutorials/js-introduction-localstorage-sessionstorage