21.12.2021, 13:22
Hello. Please tell me how you can summarize 4 bytes with the XOR operation. I have 5 bytes should have this amount
I have 17 devices, 3 bytes is the address of the device, which changes, respectively, and the XOR checksum will also change
Code:
addr = {'0x01','0x03','0x05','0x07','0x09','0x0b','0x0d','0x0f','0x11','0x13','0x15','0x17','0x19','0x1b','0x1d','0x1f','0x21'}
checksum = {'0xd3','0xd1','0xd7','0xd5','0xdb','0xd9','0xdf','0xdd','0xc3','0xc1','0xc7','0xc5','0xcb','0xc9','0xcf','0xcd','0xf3'}
for i=1,17,1 do
command = string.char(0x04,0x04,addr[i],0xd2,checksum[i])
reply = writetoport(port, 0.2, command)
decoded = str2hex(reply)
log('Device address: eA'.. i-1 .. ', Result: ' .. decoded)
end
I have 17 devices, 3 bytes is the address of the device, which changes, respectively, and the XOR checksum will also change