Community discussions

MikroTik App
 
teretere
just joined
Topic Author
Posts: 2
Joined: Wed Oct 08, 2014 3:35 pm

KNOT modbus 64-bit

Thu Jan 23, 2025 5:38 pm

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?
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 4494
Joined: Sun May 01, 2016 7:12 pm
Location: California
Contact:

Re: KNOT modbus 64-bit

Thu Jan 23, 2025 6:59 pm

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