dynamic precision on displayed value

Hello all,

I try to design a Web HMI with the WebIQ HMI Designer. I want to have the precision (number of digits) on dsiplayed value according to a process variable. Is that possible?

We have different machines with different speed ranges. Sometimes we want to show 1 digit and sometimes 2 digits on speed value. We have a tag (INT) that tells number of digits.

Greetings

Börje

Best reply by webiq-eg

Hello,
you can do it with a little Script, which you can embed into a 'LocalScrip' Widget. I enclosed an example app which demonstrates it and you can try it out.

 /**
     * 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) {
        const im = shmi.requires("visuals.session.ItemManager");
        let tok = null,
            ctrl=null;
        ctrl = shmi.ctrl(".iq-text-display"); // get the reference to the Widget to apply the dynamic digit position
        if (ctrl) {
            // e.g. 'SInt' is the process data value to switch the digits
            // Subscribe 'SInt', this means the callback function will be called each time, the process value changes
            tok = im.subscribe(["SInt"], (name, value, type) => { 
                if (value) {
                    ctrl.config.precision = 4;
                } else {
                    ctrl.config.precision = 3;
                }
                ctrl.disable(); // reinitialize the Widget
                ctrl.enable();
            });
        } else {
            shmi.notify("Widget not found");
        }
        //Place your Code here

        /* called when this local-script is disabled */
        self.onDisable = function () {
            tok.unlisten(); // free the resources of the subscription
            self.run = false; /* from original .onDisable function of LocalScript control */
        };
    };

Hope that helps.
Regards webiq-eg

dynamic-digits.zip
2.48MB
View original
3 replies