void ptl900U_Pressed(object sender, Ptl900UPressedEventArgs e, bool pickAll) { while (true) { try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CFG_WorkStation cfgWorkStation = dbContext.CFG_WorkStations .First(ws => ws.Id == this.CFG_WorkStationId); ASM_TaskItem asmTaskItem = dbContext.ASM_TaskItems .First(ti => ti.Id == this.CurrentAsmTaskItemId.Value); ASM_AssembleIndicationItem asmAssembleIndicationItem = asmTaskItem.ASM_AssembleIndicationItem; ASM_AssembleIndication asmAssembleIndication = asmAssembleIndicationItem.ASM_AssembleIndication; List <ASM_TaskItem> otherAsmTaskItems = asmAssembleIndicationItem.ASM_TaskItems .Where(ti => ti.Id != asmTaskItem.Id) .ToList(); CFG_Cart cfgCart = asmTaskItem.CFG_Cart; List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = cfgCart.CFG_CartCurrentMaterials .OrderBy(ccm => ccm.Position) .ToList(); CFG_CartCurrentMaterial cfgCartCurrentMaterial = cfgCartCurrentMaterials.First(ccm => ccm.Position == asmTaskItem.CartPosition); CFG_WorkStationCurrentCart cfgWorkStationCurrentCart = dbContext.CFG_WorkStationCurrentCarts .FirstOrDefault(wscc => wscc.CFG_WorkStationId == this.CFG_WorkStationId && wscc.CFG_CartId == cfgCart.Id); if (asmTaskItem.AssembledQuantity == null) { asmTaskItem.AssembledQuantity = 0; } int pickedCount = 1; if (pickAll) { pickedCount = asmTaskItem.ToAssembleQuantity - asmTaskItem.AssembledQuantity.Value; } asmTaskItem.AssembledQuantity += pickedCount; asmTaskItem.AssembledTime = DateTime.Now; if (asmAssembleIndicationItem.AssembledQuantity == null) { asmAssembleIndicationItem.AssembledQuantity = 0; } asmAssembleIndicationItem.AssembledQuantity += pickedCount; asmAssembleIndicationItem.AssembledTime = DateTime.Now; bool currentItemFinished = asmTaskItem.AssembledQuantity == asmTaskItem.ToAssembleQuantity; if (currentItemFinished) { asmTaskItem.AssembleStatus = AssembleStatus.Finished; if (otherAsmTaskItems.All(ti => ti.AssembleStatus == AssembleStatus.Finished)) { asmAssembleIndicationItem.AssembleStatus = AssembleStatus.Finished; } } if (cfgCartCurrentMaterial.Quantity != null && cfgCartCurrentMaterial.Quantity > 0) { cfgCartCurrentMaterial.Quantity -= pickedCount; } //料车上物料消耗完则施放料车并通知 AGV 回收,再尝试补充一辆料车 if (cfgCartCurrentMaterials.All(ccm => ccm.Quantity == null || ccm.Quantity == 0)) { cfgCart.CartStatus = CartStatus.Free; foreach (CFG_CartCurrentMaterial innerCfgCartCurrentMaterial in cfgCartCurrentMaterials) { innerCfgCartCurrentMaterial.AST_CartTaskItemId = null; innerCfgCartCurrentMaterial.ProjectCode = null; innerCfgCartCurrentMaterial.WbsId = null; innerCfgCartCurrentMaterial.ProjectStep = null; innerCfgCartCurrentMaterial.CFG_WorkStationId = null; innerCfgCartCurrentMaterial.BatchCode = null; innerCfgCartCurrentMaterial.CFG_ChannelId = null; innerCfgCartCurrentMaterial.CFG_PalletId = null; innerCfgCartCurrentMaterial.BoxCode = null; innerCfgCartCurrentMaterial.FromPalletPosition = null; innerCfgCartCurrentMaterial.MaterialCode = null; innerCfgCartCurrentMaterial.MaterialName = null; innerCfgCartCurrentMaterial.MaterialBarcode = null; innerCfgCartCurrentMaterial.Quantity = null; innerCfgCartCurrentMaterial.AssortedTime = null; innerCfgCartCurrentMaterial.CFG_EmployeeId = null; if (innerCfgCartCurrentMaterial.Usability != CartPositionUsability.DisableByOffLineDevice) { innerCfgCartCurrentMaterial.Usability = CartPositionUsability.Enable; } } if (cfgWorkStationCurrentCart != null) { //通知 AGV 回收当前车,尝试空满切换下一辆车 DST_AgvSwitch dstAgvSwitch = dbContext.DST_AgvSwitchs.FirstOrDefault(t => t.isOpen); if (dstAgvSwitch != null) { int nCurPosition = cfgWorkStationCurrentCart.Position; string sWorkStationCode = cfgWorkStationCurrentCart.CFG_WorkStation.Code; if (nCurPosition <= 4) //内侧 { //如果对应外侧没有正在执行的物料超市配送任务,才生成里侧的线边配送任务 string sOutPosition = sWorkStationCode + "-" + (nCurPosition + 4); DST_DistributeTask outDistributeTask = dbContext.DST_DistributeTasks.FirstOrDefault(t => t.DistributeReqTypes == DistributeReqTypes.MaterialMarketDistribute && t.endPosition.Equals(sOutPosition) && t.sendErrorCount < 5 && t.arriveTime == null); if (outDistributeTask == null) { CFG_WorkStationCurrentCart cfgOutWorkStationCurrentCart = dbContext.CFG_WorkStationCurrentCarts .FirstOrDefault(wscc => wscc.CFG_WorkStationId == this.CFG_WorkStationId && wscc.Position == nCurPosition + 4 && wscc.CFG_CartId != null); if (cfgOutWorkStationCurrentCart != null) { //生成料架转换任务 List <DST_DistributeTask> distributeTasks = DistributingTaskGenerator.Instance.GenerateProductCartSwitchTask(cfgCart); foreach (DST_DistributeTask distributeTask in distributeTasks) { dbContext.DST_DistributeTasks.Add(distributeTask); } } else { //生成线边自动清线配送任务 List <DST_DistributeTask> distributeTasks = DistributingTaskGenerator.Instance.GenerateProductAreaAutoClearTask(sWorkStationCode, nCurPosition.ToString(), cfgCart.Code); foreach (DST_DistributeTask distributeTask in distributeTasks) { dbContext.DST_DistributeTasks.Add(distributeTask); } } } } else //外侧 { //如果对应里侧没有正在执行的空满转换任务,才生成外侧的线边配送任务 string sInPosition = sWorkStationCode + "-" + (nCurPosition - 4); DST_DistributeTask inDistributeTask = dbContext.DST_DistributeTasks.FirstOrDefault(t => t.DistributeReqTypes == DistributeReqTypes.ProductCartSwitch && t.startPosition.Equals(sInPosition) && t.sendErrorCount < 5 && t.arriveTime == null); if (inDistributeTask == null) { //生成线边配送任务 string sTaskSendType = "自动"; List <DST_DistributeTask> distributeTasks = DistributingTaskGenerator.Instance.GenerateProductAreaDistributeTask(sWorkStationCode, nCurPosition.ToString(), cfgCart.Code, sTaskSendType, true, dbContext); foreach (DST_DistributeTask distributeTask in distributeTasks) { dbContext.DST_DistributeTasks.Add(distributeTask); } } } } else { //解除停靠 cfgWorkStationCurrentCart.CFG_CartId = null; cfgWorkStationCurrentCart.DockedTime = null; } } //尝试发起下一车的拉料任务 CFG_Cart nextCfgCart = dbContext.CFG_Carts .FirstOrDefault(c => c.CartStatus == CartStatus.ArrivedAtBufferArea && c.CFG_CartCurrentMaterials.Any(ccm => ccm.CFG_WorkStationId == this.CFG_WorkStationId && ccm.Quantity > 0)); if (nextCfgCart != null) { nextCfgCart.CartStatus = CartStatus.NeedToWorkStation; CFG_CartCurrentMaterial firstCfgCartFirstCartCurrentMaterial = nextCfgCart.CFG_CartCurrentMaterials .First(ccm => ccm.Quantity > 0); FND_Task fndTask = new FND_Task(); fndTask.ProjectCode = firstCfgCartFirstCartCurrentMaterial.ProjectCode; fndTask.ProjectStep = firstCfgCartFirstCartCurrentMaterial.ProjectStep; fndTask.BatchCode = firstCfgCartFirstCartCurrentMaterial.BatchCode; fndTask.MaxNeedArrivedTime = DateTime.Now.AddHours(1); fndTask.RequestTime = DateTime.Now; fndTask.CFG_WorkStationId = firstCfgCartFirstCartCurrentMaterial.CFG_WorkStationId.Value; fndTask.CFG_CartId = nextCfgCart.Id; fndTask.LightColor = (byte)LightColor.Off; fndTask.FindingStatus = FindingStatus.New; dbContext.FND_Tasks.Add(fndTask); } } dbContext.SaveChanges(); CartPtl cartPtl = CartPtlHost.Instance.GetCartPtl(asmTaskItem.CFG_CartId); Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher(); Ptl900U ptl900U = cartPtl.GetPtl900UByPosition(asmTaskItem.CartPosition); Ptl900U ptl900ULight = cartPtl.GetPtl900ULight(); if (currentItemFinished) { Display900UItem cartPublisherDisplay900UItem = new Display900UItem(); cartPublisherDisplay900UItem.Name = "抵达工位 " + cfgWorkStation.Name; cartPublisherDisplay900UItem.Description = string.Format(CultureInfo.InvariantCulture, @"项目:{0} 阶段:{1} 批次:{2}", cfgCartCurrentMaterial.ProjectCode, cfgCartCurrentMaterial.ProjectStep, cfgCartCurrentMaterial.BatchCode); if (cfgWorkStationCurrentCart != null) { cartPublisherDisplay900UItem.Count = (ushort)cfgWorkStationCurrentCart.Position; } cartPublisherDisplay900UItem.Unit = "位"; ptl900UPublisher.Pressed -= this.ptl900UPublisher_Pressed; ptl900UPublisher.Clear(true); ptl900UPublisher.Lock(); ptl900UPublisher.Display(cartPublisherDisplay900UItem, LightColor.Off); ptl900U.Pressed -= this.ptl900U_Pressed; ptl900ULight.Clear(); this.CurrentAsmTaskItemId = null; } else { Display900UItem publisherDisplay900UItem = new Display900UItem(); publisherDisplay900UItem.Name = asmAssembleIndicationItem.MaterialName; publisherDisplay900UItem.Description = string.Format(CultureInfo.InvariantCulture, @"项目:{0},{1} 车号:{2} 量产工位:{3}", asmAssembleIndicationItem.ProjectCode, asmAssembleIndicationItem.ProjectStep, asmAssembleIndication.ProductSequence, asmAssembleIndicationItem.Gzz); publisherDisplay900UItem.LongSubLocation = asmTaskItem.ToAssembleQuantity.ToString(CultureInfo.InvariantCulture); publisherDisplay900UItem.Count = (ushort)asmTaskItem.AssembledQuantity.Value; Display900UItem display900UItem = new Display900UItem(); display900UItem.Count = (ushort)(asmTaskItem.ToAssembleQuantity - asmTaskItem.AssembledQuantity.Value); LightMode lightMode = new LightMode(); lightMode.Color = LightColor.Green; if (asmAssembleIndicationItem.Qtxbs == "1") { lightMode.Color = LightColor.Magenta; lightMode.Ratio = LightOnOffRatio.RatioP1V1; lightMode.Period = LightOnOffPeriod.Period500; } ptl900UPublisher.Clear(true); //ptl900UPublisher.Unlock(); ptl900UPublisher.Lock(); ptl900UPublisher.Display(publisherDisplay900UItem, LightColor.Off, true); ptl900U.Display(display900UItem, lightMode, true); //如果长时间无法交互,则自动交互 this.AutoPressByDeviceErrorAsync(this.CurrentAsmTaskItemId.Value, ptl900U, display900UItem); } string logMessage = (pickAll ? " 拣选所有:" : " 拣选一个:") + asmAssembleIndication.ProductSequence + ", " + asmAssembleIndication.GzzList + ", " + asmAssembleIndicationItem.MaterialCode + ", " + asmAssembleIndicationItem.MaterialName + ", " + cfgCart.Name + ", " + asmTaskItem.CartPosition; if (currentItemFinished) { logMessage += ", 明细完成"; } Logger.Log(this.GetType().Name + "." + cfgWorkStation.Code, DateTime.Now.ToString("HH:mm:ss") + logMessage + Environment.NewLine); } break; } catch (Exception ex) { string message = ex.Message; DbEntityValidationException dbEntityValidationException = ex as DbEntityValidationException; if (dbEntityValidationException != null) { foreach (DbEntityValidationResult validationResult in dbEntityValidationException.EntityValidationErrors) { foreach (DbValidationError validationError in validationResult.ValidationErrors) { message += Environment.NewLine + validationError.ErrorMessage; } } } message += Environment.NewLine + ex.StackTrace; Logger.Log("IndicatingExecutor.ptl900U_Pressed", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine + message + Environment.NewLine + Environment.NewLine); Thread.Sleep(1000); } } }
/// <summary> /// 如果新底盘抵达,则自动完成之前的。 /// </summary> void AutoPressByNewCarArrivedAsync(long capturedCurrentAsmTaskId, long capturedCurrentAsmTaskItemId, Ptl900U ptl900U, Display900UItem display900UItem) { ThreadPool.QueueUserWorkItem(_ => { Thread.CurrentThread.Name = "IndicatingExecutor.AutoPressByNewCarArrivedAsync_" + this.CFG_WorkStationId; while (true) { if (this.CurrentAsmTaskItemId != capturedCurrentAsmTaskItemId) { break; } try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { bool hasOtherTask = dbContext.ASM_Tasks .Any(t => t.ASM_AssembleIndication.CFG_WorkStationId == this.CFG_WorkStationId && t.AssembleStatus != AssembleStatus.Finished && t.Id != capturedCurrentAsmTaskId); if (hasOtherTask && this.CurrentAsmTaskItemId == capturedCurrentAsmTaskItemId) { CFG_WorkStation cfgWorkStation = dbContext.CFG_WorkStations .First(ws => ws.Id == this.CFG_WorkStationId); ASM_TaskItem asmTaskItem = dbContext.ASM_TaskItems .First(ti => ti.Id == capturedCurrentAsmTaskItemId); ASM_AssembleIndicationItem asmAssembleIndicationItem = asmTaskItem.ASM_AssembleIndicationItem; ASM_AssembleIndication asmAssembleIndication = asmAssembleIndicationItem.ASM_AssembleIndication; CFG_Cart cfgCart = asmTaskItem.CFG_Cart; Logger.Log(this.GetType().Name + "." + cfgWorkStation.Code, DateTime.Now.ToString("HH:mm:ss") + " 新底盘抵达,自动完成之前的:" + asmAssembleIndication.ProductSequence + ", " + asmAssembleIndication.GzzList + ", " + asmAssembleIndicationItem.MaterialCode + ", " + asmAssembleIndicationItem.MaterialName + ", " + cfgCart.Name + ", " + asmTaskItem.CartPosition + Environment.NewLine); ptl900U.Clear(true); Ptl900UPressedEventArgs ptl900UPressedEventArgs = new Ptl900UPressedEventArgs(); ptl900UPressedEventArgs.ResultByItem.Add(display900UItem, display900UItem.Count); this.ptl900U_Pressed(ptl900U, ptl900UPressedEventArgs, true); break; } } } catch (Exception ex) { string message = ex.Message; DbEntityValidationException dbEntityValidationException = ex as DbEntityValidationException; if (dbEntityValidationException != null) { foreach (DbEntityValidationResult validationResult in dbEntityValidationException.EntityValidationErrors) { foreach (DbValidationError validationError in validationResult.ValidationErrors) { message += Environment.NewLine + validationError.ErrorMessage; } } } message += Environment.NewLine + ex.StackTrace; Logger.Log("IndicatingExecutor.AutoPressByNewCarArrivedAsync", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine + message + Environment.NewLine + Environment.NewLine); } finally { Thread.Sleep(1000); } } }); }
/// <summary> /// 按拣选标签表示拣选一个。 /// </summary> void ptl900U_Pressed(object sender, Ptl900UPressedEventArgs e) { this.ptl900U_Pressed(sender, e, false); }
void CallButton_Pressed(object sender, Ptl900UPressedEventArgs e) { //灭灯 var targetDevice = this.devices.FirstOrDefault(x => x.CallButton == sender); if (targetDevice != null) { targetDevice.CallButton.Clear(true); ThreadPool.QueueUserWorkItem(new WaitCallback(_ => { dictBool[targetDevice.AreaId] = true; using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { using (var dbContextTransaction = dbContext.Database.BeginTransaction()) { try { //灭交互灯 var item = dbContext.CacheRegions.Where(x => x.Id == targetDevice.Id).FirstOrDefault(); if (item != null) { item.Status = 0;//灭灯 //灭柱灯,吴恺补充 var m3Item = dbContext.CacheRegions .Where(x => (x.Material_A == item.Material_A || x.Material_B == item.Material_B || x.Material_C == item.Material_C) && x.IsInteractive == false) .FirstOrDefault(); //删除缓存区的绑定关系,在装配区插入绑定关系 var assemblings = dbContext.Assemblings.Where(x => x.AreaId == item.AreaId).ToList(); foreach (var assembling in assemblings) { switch (assembling.Type) { case "A": assembling.MaterialId = item.Material_A; break; case "B": assembling.MaterialId = item.Material_B; break; case "C": assembling.MaterialId = item.Material_C; break; default: break; } dbContext.SaveChanges(); } item.Material_A = null; item.Material_B = null; item.Material_C = null; if (m3Item != null) { m3Item.Status = 0; m3Item.Material_A = null; m3Item.Material_B = null; m3Item.Material_C = null; // dbContext.Update(m3Item); } //dbContext.Update<CacheRegion>(item); dbContext.SaveChanges(); } // dbContext.Session.CommitTransaction(); dbContextTransaction.Commit(); } catch { //if (dbContext.Session.IsInTransaction) //{ // dbContext.Session.RollbackTransaction(); //} dbContextTransaction.Rollback(); } } } dictBool[targetDevice.AreaId] = false; })); } }