--[[--------------------------------------------------- Procedura calcolo STATUS: Variabili IN: - delta(double): delta-time (minuti) - dataList(string,string): tab stati (previus) - countAcc(string,double): tab accumulatori Variabili OUT: - countAcc(string,double): tab accumulatori -----------------------------------------------------]] -- Per eventuale debug local ZBS = "c:/ZeroBraneStudio" if not package.path:find(ZBS,1,true) then package.path = ZBS .. "/lualibs/?/?.lua;" .. ZBS .. "/lualibs/?.lua;" .. package.path package.cpath = ZBS .. "/bin/?.dll;" .. ZBS .. "/bin/clibs53/?.dll;" .. package.cpath end local function addDelta(key, value) if(value == nil) then return end -- controllo esistenza if(countAcc[key] ~= nil) then countAcc[key] = countAcc[key] + value else countAcc[key] = value end end local function tablelength(T) local count = 0 for _ in pairs(T) do count = count + 1 end return count end -- se non รจ da NLua inizializzo variabili accessorie local function checkInit() if (callMode ~= 'NLua') then -- imposto valore delta delta = 0.5 -- imposto valori (precedenti allo stato attuale) dataList = {} dataList["MACHINE STATUS"] = "1" dataList["PROCESS STATUS"] = "2" dataList["SPINDLE 1 LOAD"] = "1" dataList["SPINDLE 2 LOAD"] = "0" dataList["SPINDLE 3 LOAD"] = "3" dataList["SPINDLE 4 LOAD"] = "0" end -- init variabili contatori (just in case) addDelta("MacPowerOn",0) addDelta("CycleProc01",0) addDelta("SpindleTorque01",0) addDelta("SpindleTorque02",0) addDelta("SpindleTorque03",0) addDelta("SpindleTorque04",0) -- verifico di avere record x processare numRec = tablelength(dataList) end local function displayTestInfo() if (callMode ~= 'NLua') then print('------------------------------') print('calcOk: ' .. tostring(calcOk)) print('------------------------------') print('countAcc:') print('---------') for i,val in pairs(countAcc) do print(""..i.." | "..val) end print('------------------------------') end end -- Main function: effettua calcolo stato secondo i parametri ricevuti local function doCalc() -- se ho dati processo if(numRec > 0) then -- se era poweron --> controllo ed eventualmente conto! if(dataList["MACHINE STATUS"] ~= nil and dataList["MACHINE STATUS"] == "1" ) then addDelta("MacPowerOn",delta) -- se era ANCHE AUTO --> conto if(dataList["PROCESS STATUS"] ~= nil and dataList["PROCESS STATUS"] == "2") then addDelta("CycleProc01",delta) end -- se erano spindle > 0 --> conto if(dataList["SPINDLE 1 LOAD"] ~= nil and dataList["SPINDLE 1 LOAD"] ~= "0" ) then addDelta("SpindleTorque01",delta) end if(dataList["SPINDLE 2 LOAD"] ~= nil and dataList["SPINDLE 2 LOAD"] ~= "0" ) then addDelta("SpindleTorque02",delta) end if(dataList["SPINDLE 3 LOAD"] ~= nil and dataList["SPINDLE 3 LOAD"] ~= "0" ) then addDelta("SpindleTorque03",delta) end if(dataList["SPINDLE 4 LOAD"] ~= nil and dataList["SPINDLE 4 LOAD"] ~= "0" ) then addDelta("SpindleTorque04",delta) end end -- salvo calcolo eseguito calcOk = true -- altrimenti errore else numRec = 1 calcOk = false end end -- Funct da chiamare da ext function doProcess() -- variabile semaforo callMode (locali o remote da NLua) callMode = callMode or '' dataList = dataList or {} countAcc = countAcc or {} calcOk = false numRec = 0 --vero task da eseguire checkInit() doCalc() displayTestInfo() end -- MAIN if (callMode ~= 'NLua') then doProcess() end