private void AddLoadToLog( DateTime timeToSkip, IDictionary <int, PalletLocation> devices, MakinoDB.WorkSetResults w) { //find the location PalletLocation loc; if (devices.ContainsKey(w.DeviceID)) { loc = devices[w.DeviceID]; } else { loc = new PalletLocation(PalletLocationEnum.Buffer, "Unknown", 1); } if (loc.Location != PalletLocationEnum.LoadUnload) { Log.Error("Creating machine cycle for device that is not a load: " + loc.Location.ToString()); } //calculate the elapsed time var elapsed = w.EndDateTimeUTC.Subtract(w.StartDateTimeUTC); elapsed = new TimeSpan(elapsed.Ticks / 2); //count the number of unloaded parts int numParts = 0; foreach (var i in w.UnloadNormalQuantities) { numParts += i; } //Only process unload cycles if remachine is false if (numParts > 0 && !w.Remachine) { //create the material for unload var matList = FindOrCreateMaterial(w.PalletID, w.FixtureNumber, w.EndDateTimeUTC, w.UnloadOrderName, w.UnloadPartName, w.UnloadProcessNum, numParts); //check if the cycle already exists if (timeToSkip == w.EndDateTimeUTC && _log.CycleExists(w.EndDateTimeUTC, w.PalletID.ToString(), LogType.LoadUnloadCycle, "L/U", loc.Num)) { return; } _log.RecordUnloadEnd( mats: matList, pallet: w.PalletID.ToString(), lulNum: loc.Num, timeUTC: w.EndDateTimeUTC, elapsed: elapsed, active: elapsed); } //Pallet Cycle _log.CompletePalletCycle(w.PalletID.ToString(), w.EndDateTimeUTC, ""); //now the load cycle numParts = 0; foreach (var i in w.LoadQuantities) { numParts += i; } if (numParts > 0) { //create the material var matList = CreateMaterial(w.PalletID, w.FixtureNumber, w.EndDateTimeUTC.AddSeconds(1), w.LoadOrderName, w.LoadPartName, w.LoadProcessNum, numParts); _log.RecordLoadEnd( mats: matList, pallet: w.PalletID.ToString(), lulNum: loc.Num, timeUTC: w.EndDateTimeUTC.AddSeconds(1), elapsed: elapsed, active: elapsed); } }
private void HandleMessage(MessageState state, CincronMessage msg, int repeatCount) { var queueChange = msg as CincronMessage.QueuePositionChange; //machine cycle start. For now it is pallet rotating into machine if (queueChange != null && queueChange.CurrentLocation.Location == PalletLocationEnum.Machine && queueChange.NewQueuePosition == "10010") { _log.RecordMachineStart( mats: FindMaterial(queueChange.Pallet), pallet: queueChange.Pallet, statName: "MC", statNum: queueChange.CurrentLocation.Num, program: "", timeUTC: queueChange.TimeUTC, foreignId: ForeignId(msg), originalMessage: msg.LogMessage ); } //machine cycle end. StepNo changing to 5 signals cycle end. var stepChange = msg as CincronMessage.PartNewStep; if (stepChange != null && stepChange.StepNo == 5) { var machineCycleStart = FindMachineStart(_log.CurrentPalletLog(stepChange.Pallet)); if (machineCycleStart != null) { _log.RecordMachineEnd( mats: machineCycleStart.Material.Select(JobLogDB.EventLogMaterial.FromLogMat), pallet: stepChange.Pallet, statName: "MC", statNum: machineCycleStart.LocationNum, program: "", timeUTC: stepChange.TimeUTC, result: "", elapsed: stepChange.TimeUTC.Subtract(machineCycleStart.EndTimeUTC), active: TimeSpan.Zero, foreignId: ForeignId(msg), originalMessage: msg.LogMessage ); } } //program end. FindMachineStart correctly returns null if we have already recorded //cycle end. var progEnd = msg as CincronMessage.ProgramFinished; if (progEnd != null) { var machineCycleStart = FindMachineStart(_log.CurrentPalletLog(progEnd.Pallet)); if (machineCycleStart != null) { _log.RecordMachineEnd( mats: machineCycleStart.Material.Select(JobLogDB.EventLogMaterial.FromLogMat), pallet: progEnd.Pallet, statName: "MC", statNum: machineCycleStart.LocationNum, program: "", timeUTC: progEnd.TimeUTC, result: "", elapsed: progEnd.TimeUTC.Subtract(machineCycleStart.EndTimeUTC), active: TimeSpan.Zero, foreignId: ForeignId(msg), originalMessage: msg.LogMessage ); } } //part completed message. Store in memory since typically there is an Unload Start event //which happens right afterwords. var comp = msg as CincronMessage.PartCompleted; if (comp != null) { for (int i = 0; i < repeatCount; i++) { if (!state.PartCompletedMessagesBySetup.ContainsKey(comp.Setup)) { state.PartCompletedMessagesBySetup[comp.Setup] = new List <CincronMessage.PartCompleted>(); } state.PartCompletedMessagesBySetup[comp.Setup].Add(comp); } } //move to unload. Store in memory, typically there is an UnloadStart event soon if (queueChange != null && queueChange.CurrentLocation.Location == PalletLocationEnum.LoadUnload && queueChange.NewQueuePosition == "10010") { _log.RecordGeneralMessage( mat: null, pallet: queueChange.Pallet, program: "PalletMoveToLoad", result: queueChange.CurrentLocation.Num.ToString(), timeUTC: queueChange.TimeUTC, foreignId: ForeignId(msg), originalMessage: msg.LogMessage); } //unload start. Use the completed parts and last unload station from the state. var unloadStart = msg as CincronMessage.PartUnloadStart; if (unloadStart != null) { var oldEvts = _log.CurrentPalletLog(unloadStart.Pallet); var lul = FindLastLoadStation(oldEvts); _log.RecordUnloadStart( mats: CreateUnloadMaterial(state, unloadStart.Pallet, oldEvts), pallet: unloadStart.Pallet, lulNum: lul, timeUTC: unloadStart.TimeUTC, foreignId: ForeignId(msg), originalMessage: msg.LogMessage ); state.PartCompletedMessagesBySetup.Clear(); } var loadStart = msg as CincronMessage.PartLoadStart; if (loadStart != null) { var oldEvts = _log.CurrentPalletLog(loadStart.Pallet); var lul = FindLastLoadStation(oldEvts); _log.RecordLoadStart( mats: CreateLoadMaterial(loadStart), pallet: loadStart.Pallet, lulNum: lul, timeUTC: loadStart.TimeUTC, foreignId: ForeignId(msg), originalMessage: msg.LogMessage ); } //end of load and unload on step change to 2 if (stepChange != null && stepChange.StepNo == 2) { //create end unload, then pallet cycle, then end load. var oldEvts = _log.CurrentPalletLog(stepChange.Pallet); var loadStartCycle = FindLoadStart(oldEvts); var unloadStartCycle = FindUnloadStart(oldEvts); if (unloadStartCycle != null) { _log.RecordUnloadEnd( mats: unloadStartCycle.Material.Select(JobLogDB.EventLogMaterial.FromLogMat), pallet: stepChange.Pallet, lulNum: unloadStartCycle.LocationNum, timeUTC: stepChange.TimeUTC, elapsed: stepChange.TimeUTC.Subtract(unloadStartCycle.EndTimeUTC), active: TimeSpan.Zero, foreignId: ForeignId(msg), originalMessage: msg.LogMessage ); } var mats = new Dictionary <string, IEnumerable <JobLogDB.EventLogMaterial> >(); if (loadStartCycle != null) { _log.AddPendingLoad( pal: stepChange.Pallet, key: stepChange.Pallet, load: loadStartCycle.LocationNum, elapsed: stepChange.TimeUTC.Subtract(loadStartCycle.EndTimeUTC), active: TimeSpan.Zero, foreignID: ForeignId(msg) ); mats[stepChange.Pallet] = loadStartCycle.Material.Select(JobLogDB.EventLogMaterial.FromLogMat); } _log.CompletePalletCycle(stepChange.Pallet, stepChange.TimeUTC, ForeignId(msg), mats, generateSerials: false); } }