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.

Checksum XOR 4 bytes
#3
(21.12.2021, 13:49)admin Wrote: Use bit.bxor() and don't use quotes around numbers because not all functions will convert strings to numbers automatically.
Code:
function encode(...)
  local checksum = bit.bxor(...)
  return string.char(...) .. string.char(checksum)
end

addrs = {0x01,0x03,0x05,0x07,0x09,0x0b,0x0d,0x0f,0x11,0x13,0x15,0x17,0x19,0x1b,0x1d,0x1f,0x21}

for _, addr in ipairs(addrs) do
  command = encode(0x04,0x04,addr,0xd2)
  reply = writetoport(port, 0.2, command)
  decoded = str2hex(reply)
  log('Device address: eA'.. i-1 .. ', Result: ' .. decoded)
end
Thanks for the help Smile
Reply


Messages In This Thread
Checksum XOR 4 bytes - by sashhun - 21.12.2021, 13:22
RE: Checksum XOR 4 bytes - by admin - 21.12.2021, 13:49
RE: Checksum XOR 4 bytes - by sashhun - 21.12.2021, 14:52
RE: Checksum XOR 4 bytes - by sashhun - 21.12.2021, 20:23
RE: Checksum XOR 4 bytes - by admin - 22.12.2021, 08:00
RE: Checksum XOR 4 bytes - by sashhun - 22.12.2021, 08:24
RE: Checksum XOR 4 bytes - by admin - 22.12.2021, 08:45
RE: Checksum XOR 4 bytes - by sashhun - 22.12.2021, 09:51

Forum Jump: