(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.Thanks for the help
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
Checksum XOR 4 bytes
|
|
« Next Oldest | Next Newest »
|
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
|