--[[--------------------------------------------------- Procedura calcolo statistiche parametri: Variabili IN: - lastMode - valList(): elenco VALORI double da processare - numRec(int): conteggio numero recorda da processare Variabili OUT: - calcVal(double): valore calcolato finale -----------------------------------------------------]] -- 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 -- se non รจ da NLua inizializzo variabili accessorie local function checkInit() if (callMode ~= 'NLua') then -- imposto valori test dataList = {} dataList["MACHINE STATUS"] = 1 dataList["PROCESS STATUS"] = 2 dataList["PROCESS MODE"] = 2 end numRec = tablelength(dataList) end function tablelength(T) local count = 0 for _ in pairs(T) do count = count + 1 end return count end -- Main function: effettua calcolo stato secondo i parametri ricevuti local function doCalc() -- se ho dati processo if(numRec > 0) then -- /************************************************************************ -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- *************************************************************************/ -- calcolo dello statusId if(dataList["MACHINE STATUS"] == 0) then statusId = 7 else if(dataList["PROCESS MODE"] == 1) then statusId = 8 elseif(dataList["PROCESS MODE"] == 2) then statusId = 2 elseif(dataList["PROCESS MODE"] == 3) then statusId = 9 elseif(dataList["PROCESS MODE"] == 4) then statusId = 5 elseif(dataList["PROCESS MODE"] == 5) then statusId = 10 elseif(dataList["PROCESS MODE"] == 6) then statusId = 11 elseif(dataList["PROCESS MODE"] == 7) then statusId = 12 elseif(dataList["PROCESS MODE"] == 8) then statusId = 13 end end -- calcolo del processId if(dataList["PROCESS STATUS"] == 1) then modeId = 2 elseif(dataList["PROCESS STATUS"] == 2) then modeId = 1 elseif(dataList["PROCESS STATUS"] == 3) then modeId = 3 elseif(dataList["PROCESS STATUS"] == 6) then modeId = 8 elseif(dataList["PROCESS STATUS"] == 8) then modeId = 9 elseif(dataList["PROCESS STATUS"] == 11) then modeId = 10 end calcOk = true -- altrimenti errore else numRec = 1 calcOk = false end end local function displayTestInfo() if (callMode ~= 'NLua') then print('------------------------------') print('calcOk: ' .. tostring(calcOk)) for i,val in pairs(dataList) do print(""..i.." | "..val) end print('statusId: ' .. statusId) print('modeId: ' .. modeId) print('------------------------------') end end -- MAIN function doProcess() -- variabile semaforo callMode (locali o remote da NLua) callMode = callMode or '' numRec = 0 statusId = 0 modeId = 0 dataList = dataList or {} calcOk = false --vero task da eseguire checkInit() doCalc() displayTestInfo() end if (callMode ~= 'NLua') then doProcess() end