FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
04-25-2022 05:04 PM
How can I change the notation of a Integer value, t.e.:
(Integer -> hexadecimal notation)
Solved! Go to Solution.
04-26-2022 06:34 AM
Two possible ways:
1. Have the value stored/converted in the PLC already
2. Convert it using a LocalScript that subscribes to the item, converts it to hexadecimal and emits it as a virtual item that will then be connected to the desired widget
08-01-2022 03:31 PM - edited 08-03-2022 02:59 PM
There is another way, with the iq-text element which support the execution of JS functions.
/**
Converts an interger number to a HEX string
* @example
* x = Int2Hex(255, 4)); // x = "00FF"
*
* @param {number} iVal Number to convert
* @param {number} iLen length of converted string
* @returns {string} HEX string of iVal
*/
function Int2Hex(iVal, iLen) {
return iVal.toString(16).toUpperCase().padStart(iLen, "0");
}
/**
* Converts iVal into binary string
* @example
* x = Int2Bin(3, 4)); // x = "0011"
*
* @param {number} iVal Number to convert
* @param {number} iLen length of converted string
* @returns {string} HEX string of iVal
*/
function Int2Bin(iVal, iLen) {
return iVal.toString(2).padStart(iLen, "0");
}
08-02-2024 03:29 PM
Thank you for this function ! I just used it. Works fine.
I had some troubles first because I used the wrong iq-text...
Therfore for beginners like me 🙂