private void AddMachineToLog( DateTime timeToSkip, IDictionary <int, PalletLocation> devices, MakinoDB.MachineResults m) { //find the location PalletLocation loc; if (devices.ContainsKey(m.DeviceID)) { loc = devices[m.DeviceID]; } else { loc = new PalletLocation(PalletLocationEnum.Buffer, "Unknown", 0); } if (loc.Location != PalletLocationEnum.Machine) { Log.Error("Creating machine cycle for device that is not a machine: " + loc.Location.ToString()); } //count the number of parts int numParts = 0; foreach (var i in m.OperQuantities) { numParts += i; } if (numParts <= 0) { return; } //create the material var matList = FindOrCreateMaterial(m.PalletID, m.FixtureNumber, m.EndDateTimeUTC, m.OrderName, m.PartName, m.ProcessNum, numParts); var elapsed = m.EndDateTimeUTC.Subtract(m.StartDateTimeUTC); //check if the cycle already exists if (timeToSkip == m.EndDateTimeUTC && _log.CycleExists(m.EndDateTimeUTC, m.PalletID.ToString(), LogType.MachineCycle, "MC", loc.Num)) { return; } var extraData = new Dictionary <string, string>(); if (matList.Count > 0) { var matID1 = matList[0].MaterialID; Log.Debug( "Starting load of common values between the times of {start} and {end} on DeviceID {deviceID}." + "These values will be attached to part {part} with serial {serial}", m.StartDateTimeLocal, m.EndDateTimeLocal, m.DeviceID, m.PartName, Settings.ConvertMaterialIDToSerial(matID1)); foreach (var v in _makinoDB.QueryCommonValues(m)) { Log.Debug("Common value with number {num} and value {val}", +v.Number, v.Value); extraData[v.Number.ToString()] = v.Value; } } _log.RecordMachineEnd( mats: matList, pallet: m.PalletID.ToString(), statName: "MC", statNum: loc.Num, program: m.Program, result: "", timeUTC: m.EndDateTimeUTC, elapsed: elapsed, active: TimeSpan.FromSeconds(m.SpindleTimeSeconds), extraData: extraData); AddInspection(m, matList); }
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); } }