10.09.2025, 12:00 
		
	
	(10.09.2025, 11:48)Daniel Wrote: Where did you get this function from? crc16(data)
sorry i forget to attached a part...... here for you
Code:
--funzione calcolo CRC16
function crc16(data)
  log('valore passato = ',data)
  local crc = 0xFFFF
 for i = 1, #data do
    crc = bit.bxor(crc, data:byte(i))
    for j = 1, 8 do
      local k = bit.band(crc, 1)
      crc = bit.rshift(crc, 1)
      if k ~= 0 then
        crc = bit.bxor(crc, 0x8408)
        end
      end
    end
    --return bit.bxor(crc, 0xFFFF)
  result = string.format("%04X",bit.bxor(crc, 0xFFFF))
  result_low = string.sub(result, 3 , 4)
  result_high = string.sub(result, 1 , 2)
  crc_calc = (',0x'..result_low..',0x'..result_high)
  return crc_calc
end