In the editor you can see word, dword and float values, but in some apps like a CoDeSys it is possible to configure a smaller variables like 1 byte.
In the Modbus table of PLC with CoDeSys and any other Modbus-compatible PLC all the data stored in the universal table. This table includes bytes, and when you need to get a 16-bit, you just get 2 slots of this table. So, if you have a 16-bit variable in iRidium and need to read it, you just get 2 bytes and parse it to 1 byte + 1 byte by the next way:
CoDeSys: | FF | FF | - two separated registers (addresses)
iRidium got: | FF FF | - only one register (address).
iRidium automaticly converting this data from HEX to DEC, so we get | 255 | 255 |
We have to parse this data back to HEX,
divide the low and high byte and convert it back to DEC.
Example:
IR.AddListener(IR.EVENT_TAG_CHANGE,IR.GetDevice("Modbus TCP"),function(item,value) // listener of tag changes for ModBus TCP
{
if (item == "Feedback 1") //set the name of register which should be parsed
{
// It was DEC value made of 2 bytes in the string format
var dec2byte = "27542";
// convert it to number, and then in string of 16-bit
var hex2byte = parseInt(dec2byte).toString(16);
// get the first byte from the string
var hexfirst = hex2byte.charAt(0) + hex2byte.charAt(1);
// get the second byte drom the string
var hexsecond = hex2byte.charAt(2) + hex2byte.charAt(3);
// get the DEC number from the HEX bytes in string
decfirst = parseInt(hexfirst, 16); decsecond = parseInt(hexsecond, 16);
IR.Log(decfirst); // first byte
IR.Log(decsecond); // second byte
});