diff --git a/BeamRESTPipe.lua b/BeamRESTPipe.lua index 3aaaf1e..8351625 100644 --- a/BeamRESTPipe.lua +++ b/BeamRESTPipe.lua @@ -203,41 +203,120 @@ local function Calc_Estimate( QuestionArgs) return 0, { Error = sErrorMsg} end --local MachinesDir = EgtFindAllFiles( MachineDirPath .. '\\*.*') - local MachinesDir = { MachineDirPath .. '\\Saomad-KAIROS', MachineDirPath .. '\\Essetre-PF1250' } + local MachinesDir = { MachineDirPath .. '\\Saomad-Kairos', MachineDirPath .. '\\Essetre-FAST', MachineDirPath .. '\\Essetre-PF1250MAX' } + --local MachinesDir = { MachineDirPath .. '\\Essetre-FAST'} local BeamMachineList = {} + local AnswerChannelList = {} for nMachineIndex = 1, #MachinesDir do local _, sMachineName, _ = EgtSplitPath( MachinesDir[nMachineIndex]) local sMaterial = EgtGetStringFromIni( 'General', 'Material', '', MachineDirPath .. '\\' .. sMachineName .. '\\' .. sMachineName .. '.ini') if sMaterial == 'Beam' then - local CurrMachine = { Name = sMachineName, PartList = { }} + local sMachineOrderDirPath = sOrderDirPath .. '\\' .. sMachineName + -- creo cartella per macchina + if EgtExistsDirectory( sMachineOrderDirPath) then + if not EgtEmptyDirectory( sMachineOrderDirPath) then + local sErrorMsg = 'Errore! Impossibile svuotare cartella ' .. sMachineOrderDirPath .. ' per il progetto ' .. sOrderUID .. '!' + EgtOutLog(sErrorMsg) + return 0, { Error = sErrorMsg} + end + else + if not EgtCreateDirectory( sMachineOrderDirPath) then + local sErrorMsg = 'Errore! Impossibile creare cartella ' .. sMachineOrderDirPath .. ' per il progetto ' .. sOrderUID .. '!' + EgtOutLog(sErrorMsg) + return 0, { Error = sErrorMsg} + end + end + local sMachineNgeFilePath = sMachineOrderDirPath .. '\\' .. sUID .. '.nge' + -- e copio file nge + if not EgtCopyFile( sNgeFilePath, sMachineNgeFilePath) then + local sErrorMsg = 'Errore! Copia del file nge per macchina ' .. sMachineName .. ' e progetto ' .. sUID .. ' fallita!' + EgtOutLog(sErrorMsg) + return 0, { Error = sErrorMsg} + end + if not EgtOpenFile( sMachineNgeFilePath) then + local sErrorMsg = 'Errore! Fallita apertura del file per macchina ' .. sMachineName .. '!' + EgtOutLog(sErrorMsg) + return 0, { Error = sErrorMsg} + end -- creo i singoli bwe e li mando da eseguire via redis - --BeamWallPipeLib.VerifyBtlPart( nPartId, BarPath, ProjType, sMachineName, GlobState) local nPartId = EgtGetFirstPart() local AnswerArgs = {} local TagTimeList = {} local dTotTime = 0 local nNotMachinedPart = 0 while nPartId do - local BarPath = sOrderDirPath + local BarPath = sMachineOrderDirPath local ProjType = BWTYPES.BEAM local GlobState = CALCSTATES.NOTCALCULATED - local nResult, PartAnswerArgs = BeamWallPipeLib.VerifyBtlPart( nPartId, BarPath, ProjType, sMachineName, GlobState) - local sTagList = EgtGetInfo( nPartId, 'LuxTagList') - local TagList = EgtSplitString( sTagList, ',') - local CalcResult - if nResult == 1 then - CalcResult = EgtIf( tonumber( PartAnswerArgs.MachiningOk) == 1, PART_VERIFICATION_RESULTS.MACHINABLE, PART_VERIFICATION_RESULTS.NOTMACHINABLE) + local bResult, AnswerChannel = BeamWallPipeLib.AsyncVerifyBtlPartCalc( nPartId, BarPath, ProjType, sMachineName, GlobState) + if bResult then + table.insert( AnswerChannelList, { Channel = AnswerChannel, PartId = nPartId, Machine = sMachineName}) else - CalcResult = PART_VERIFICATION_RESULTS.CALCULATIONFAILED - local sErrorMsg = 'Errore! Verifica sul pezzo ' .. nPartId .. ' fallita!' + local sErrorMsg = 'Errore! Tentativo di verifica del pezzo ' .. nPartId .. ' fallito!' EgtOutLog(sErrorMsg) end - for nTagIndex = 1, #TagList do - table.insert( CurrMachine.PartList, { Tag = TagList[nTagIndex], CalcResult = CalcResult, Time = ( PartAnswerArgs.Time or 0)}) - end nPartId = EgtGetNextPart( nPartId) end - table.insert( BeamMachineList, CurrMachine) + table.insert( BeamMachineList, { Name = sMachineName, PartList = { }}) + end + end + local nTimeCount = 0 + local nTimeClock = 100 + while nTimeCount < 1200 and #AnswerChannelList > 0 do + local RemoveAnswerList = {} + for nAnswerIndex = 1, #AnswerChannelList do + local AnswerChannel = AnswerChannelList[nAnswerIndex] + -- verifico se ci sono i risultati e aspetto che arrivino tutti + local bOk, bAnswerReceived, PartAnswerArgs = BeamWallPipeLib.AsyncVerifyBtlPartResult( AnswerChannel.Channel) + if bOk then + if bAnswerReceived then + if PartAnswerArgs then + local sTagList = EgtGetInfo( AnswerChannel.PartId, 'LuxTagList') + local TagList = EgtSplitString( sTagList, ',') + local CalcResult + CalcResult = EgtIf( tonumber( PartAnswerArgs.MachiningOk) == 1, PART_VERIFICATION_RESULTS.MACHINABLE, PART_VERIFICATION_RESULTS.NOTMACHINABLE) + local BeamMachine = '' + for nMachineIndex = 1, #BeamMachineList do + if BeamMachineList[nMachineIndex].Name == AnswerChannel.Machine then + BeamMachine = BeamMachineList[nMachineIndex] + end + end + for nTagIndex = 1, #TagList do + table.insert( BeamMachine.PartList, { Tag = TagList[nTagIndex], CalcResult = CalcResult, Time = ( PartAnswerArgs.Time or 0)}) + end + table.insert( RemoveAnswerList, nAnswerIndex) + else + local sErrorMsg = 'Errore! Tentativo di verifica del pezzo sul canale' .. AnswerChannel.Channel .. ' fallito!' + EgtOutLog(sErrorMsg) + end + end + elseif bOk then + local sErrorMsg = 'Errore! Funzione di lettura risultato sul canale ' .. AnswerChannel.Channel .. ' fallita!' + EgtOutLog(sErrorMsg) + end + end + for nRemoveAnswerCount = #RemoveAnswerList, 1, -1 do + table.remove( AnswerChannelList, RemoveAnswerList[nRemoveAnswerCount]) + end + EgtPause( nTimeClock, true) + nTimeCount = nTimeCount + 1 + end + if #AnswerChannelList > 0 then + for nAnswerCount = 1, #AnswerChannelList do + local sTagList = EgtGetInfo( AnswerChannelList[nAnswerCount].PartId, 'LuxTagList') + local TagList = EgtSplitString( sTagList, ',') + CalcResult = PART_VERIFICATION_RESULTS.CALCULATIONFAILED + local sErrorMsg = 'Errore! Verifica sul pezzo ' .. AnswerChannelList[nAnswerCount].PartId .. ' fallita!' + EgtOutLog(sErrorMsg) + local BeamMachine + for nMachineIndex = 1, #BeamMachineList do + if BeamMachineList[nMachineIndex].Name == AnswerChannelList[nAnswerCount].Machine then + BeamMachine = BeamMachineList[nMachineIndex] + end + end + for nTagIndex = 1, #TagList do + table.insert( BeamMachine.PartList, { Tag = TagList[nTagIndex], CalcResult = CalcResult, Time = 0}) + end end end -- do risultato