This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Best way to decode Modbus
#2
The most correct way to do this is via bit shifts (bit.rshift and bit.band) but since you need to split the value into 4 bit values you can simply use the datahex string:
Code:
value = event.datahex

values = {}
for i = 1, 4 do
  char = value:sub(i, i)
  values[ i ] = tonumber(char, 16)
end

log(values)
Reply


Messages In This Thread
Best way to decode Modbus - by gtsamis - 29.06.2021, 09:30
RE: Best way to decode Modbus - by admin - 30.06.2021, 12:48

Forum Jump: