Page 1 of 1

KNOT modbus 64-bit

Posted: Thu Jan 23, 2025 5:38 pm
by teretere
With Mikrotik KNOT, it is possible to successfully read int16 from Modbus RTU. There are devices whose values consist of 64 bits. How can this be read using a script? I understand that it can be done by reading each int16 separately and then combining them, but how can this be implemented in a script? Maybe someone has experience with this?

Re: KNOT modbus 64-bit

Posted: Thu Jan 23, 2025 6:59 pm
by Amm0
If you post the data you're getting or spec, that help...

In 7.16 and above, the :convert can do some of the arithmetic. And all version support bit shifts/OR/XOR/ANDs when dealing a number type. Exactly the right incantation, some recieved output help...

At a high-level, you can do:
:put [:convert from=hex to=num FFFFFFFFFFFFFFFF]
18446744073709551615
:put [:convert from=hex to=num FFFFFFFFFFFFFFFE]
18446744073709551614

And you can also use to=byte-array (or to=bit-array-msb, -lsb), to get an array from the 64-bits - this is useful for flags and "groups of bit" flags.
:put [:convert from=hex to=byte-array FFFFFFFFFFFFFFFF].

I have an rough example of using this things to parse LoRa data here (but it doesn't deal with num types):
viewtopic.php?t=211581&hilit=lora