10.09.2025, 11:13 
		
	
	
		Good morning,
I have a problem in this resident script.
 The first time (i = 1) it works, then it broken and says this error
I can't understand what is it the problem.
Can someone help me? Please
B.R. Cristian
	
	
	
I have a problem in this resident script.
Code:
function calcolo32bit (data)
  if data[3] then
    --log('sono passato', data)
        local byte_1 = data[6]
        local byte_2 = data[5]
        local byte_3 = data[4]
        local byte_4 = data[3]
      byte_received = ((byte_4 * 16777216)+(byte_3 * 65536)+(byte_2 * 256)+byte_1)
        --log(byte_received)
        s = bit.rshift(byte_received, 31)
        --log(s)
        exp1 = bit.rshift(byte_received, 23)
        --log(exp1)
        matissa = bit.band(byte_received , 8388607)
        --log(matissa)
        matissa2 = (matissa * 0.0000001) + 1
        --log(matissa2)
        risultato = (((-1)^s) * (2^(exp1-127))* matissa2)
      return(risultato)
  else
    return(0)
  end
end
function crc_calc(inv,cmd_set)
  
  inv_num = {0x02,0x03,0x04,0x05,0x06,0x07}
  --log('inv_num',inv_num[inv])
  cmd = {{0x32,0x20,0x20,0x20,0x20,0x20,0x20},
      {0x3B,0x01,0x00,0x20,0x20,0x20,0x20},
      {0x3B,0x02,0x00,0x20,0x20,0x20,0x20},
      {0x3B,0x03,0x00,0x20,0x20,0x20,0x20},
      {0x3B,0x04,0x00,0x20,0x20,0x20,0x20},
      {0x3B,0x08,0x00,0x20,0x20,0x20,0x20},
      {0x3B,0x09,0x00,0x20,0x20,0x20,0x20},
      {0x3B,0x1E,0x00,0x20,0x20,0x20,0x20},
      {0x3B,0x31,0x00,0x20,0x20,0x20,0x20},
      {0x4E,0x00,0x20,0x20,0x20,0x20,0x20},
      {0x4E,0x01,0x20,0x20,0x20,0x20,0x20},
      {0x4E,0x03,0x20,0x20,0x20,0x20,0x20},
      {0x4E,0x04,0x20,0x20,0x20,0x20,0x20},
      {0x4E,0x05,0x20,0x20,0x20,0x20,0x20}}
  
data = string.char(inv_num[inv],cmd[cmd_set][1],cmd[cmd_set][2],cmd[cmd_set][3],cmd[cmd_set][4],cmd[cmd_set][5],cmd[cmd_set][6],cmd[cmd_set][7])
  --log('valore grezzo = ',data)
    crc_calc = crc16(data)
  --log(crc_calc)
  return (crc_calc)
end
for i = 1, 6, 1 do
 --log(i)        
 crc = crc_calc(i,1)
 --log(crc)
endCode:
Power_one 10.09.2025 13:10:53
Resident script:164: attempt to call global 'crc_calc' (a string value)
stack traceback:Can someone help me? Please
B.R. Cristian