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.

Error in script
#1
Good morning,
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)
end
The first time (i = 1) it works, then it broken and says this error
Code:
Power_one 10.09.2025 13:10:53
Resident script:164: attempt to call global 'crc_calc' (a string value)
stack traceback:
I can't understand what is it the problem.

Can someone help me? Please

B.R. Cristian
Reply


Messages In This Thread
Error in script - by CristianAgata - Yesterday, 11:13
RE: Error in script - by hocine - Yesterday, 11:27
RE: Error in script - by CristianAgata - Yesterday, 11:34
RE: Error in script - by Daniel - Yesterday, 11:48
RE: Error in script - by CristianAgata - Yesterday, 12:00
RE: Error in script - by Daniel - Yesterday, 13:32
RE: Error in script - by CristianAgata - Yesterday, 15:22

Forum Jump: