Ejemplo n.º 1
0
        /// <summary>
        /// 小车在线状态切换。
        /// </summary>
        void rs485Bus_CommunicationClient_ConnectedChanged(object sender, EventArgs e)
        {
            ICommunicationClient communicationClient = (ICommunicationClient)sender;

            if (communicationClient.Connected != true && DateTime.Now - this.lastConnectionErrorTime < this.continuousConnectionErrorTimeout)
            {
                return;
            }

            this.lastConnectionErrorTime = DateTime.Now;

            while (true)
            {
                try
                {
                    using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                    {
                        CFG_Cart cfgCart = dbContext.CFG_Carts
                                           .First(c => c.Id == this.CFG_CartId);

                        cfgCart.OnLine = communicationClient.Connected == true;

                        dbContext.SaveChanges();
                    }

                    break;
                }
                catch
                {
                    Thread.Sleep(1000);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 刷新视图模型。
        /// </summary>
        public void Refresh()
        {
            this.Items.Clear();

            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                List <CFG_WorkStation> cfgWorkStations = dbContext.CFG_WorkStations
                                                         .OrderBy(c => c.Code)
                                                         .ToList();
                foreach (CFG_WorkStation cfgWorkStation in cfgWorkStations)
                {
                    WorkStationModel workStationModel = new WorkStationModel();
                    workStationModel.CFG_WorkStation = cfgWorkStation;

                    CFG_Cart cfgCart1 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 1).Select(wscc => wscc.CFG_Cart).FirstOrDefault();
                    CFG_Cart cfgCart2 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 2).Select(wscc => wscc.CFG_Cart).FirstOrDefault();
                    CFG_Cart cfgCart3 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 3).Select(wscc => wscc.CFG_Cart).FirstOrDefault();
                    CFG_Cart cfgCart4 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 4).Select(wscc => wscc.CFG_Cart).FirstOrDefault();
                    CFG_Cart cfgCart5 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 5).Select(wscc => wscc.CFG_Cart).FirstOrDefault();
                    CFG_Cart cfgCart6 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 6).Select(wscc => wscc.CFG_Cart).FirstOrDefault();
                    CFG_Cart cfgCart7 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 7).Select(wscc => wscc.CFG_Cart).FirstOrDefault();
                    CFG_Cart cfgCart8 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 8).Select(wscc => wscc.CFG_Cart).FirstOrDefault();

                    if (cfgCart1 != null)
                    {
                        workStationModel.CurrentCartName1 = cfgCart1.Name;
                    }
                    if (cfgCart2 != null)
                    {
                        workStationModel.CurrentCartName2 = cfgCart2.Name;
                    }
                    if (cfgCart3 != null)
                    {
                        workStationModel.CurrentCartName3 = cfgCart3.Name;
                    }
                    if (cfgCart4 != null)
                    {
                        workStationModel.CurrentCartName4 = cfgCart4.Name;
                    }
                    if (cfgCart5 != null)
                    {
                        workStationModel.CurrentCartName5 = cfgCart5.Name;
                    }
                    if (cfgCart6 != null)
                    {
                        workStationModel.CurrentCartName6 = cfgCart6.Name;
                    }
                    if (cfgCart7 != null)
                    {
                        workStationModel.CurrentCartName7 = cfgCart7.Name;
                    }
                    if (cfgCart8 != null)
                    {
                        workStationModel.CurrentCartName8 = cfgCart8.Name;
                    }

                    this.Items.Add(workStationModel);
                }
            }
        }
Ejemplo n.º 3
0
        string GetGzzListFromCfgCartMaterial(CFG_Cart cfgCart)
        {
            List <string> gzzList = new List <string>();

            foreach (CFG_CartCurrentMaterial cfgCartCurrentMateiral in cfgCart.CFG_CartCurrentMaterials)
            {
                if (cfgCartCurrentMateiral.AST_CartTaskItem != null)
                {
                    foreach (AST_LesTaskItem astLesTaskItem in cfgCartCurrentMateiral.AST_CartTaskItem.AST_PalletTaskItem.AST_LesTaskItems)
                    {
                        string[] gzzArray = astLesTaskItem.AST_LesTask.GzzList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string gzz in gzzArray)
                        {
                            if (!gzzList.Contains(gzz))
                            {
                                gzzList.Add(gzz);
                            }
                        }
                    }
                }
            }
            gzzList.Sort();

            return(string.Join(",", gzzList));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 还原系统启动前的状态。
        /// </summary>
        void Restore()
        {
            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                List <FND_Task> ingFndTasks = dbContext.FND_Tasks
                                              .Where(t => t.FindingStatus == FindingStatus.Displaying ||
                                                     t.FindingStatus == FindingStatus.Blinking)
                                              .ToList();
                foreach (FND_Task fndTask in ingFndTasks)
                {
                    if (fndTask.FindingStatus == FindingStatus.Displaying)
                    {
                        fndTask.FindingStatus = FindingStatus.NeedDisplay;
                    }
                    else if (fndTask.FindingStatus == FindingStatus.Blinking)
                    {
                        fndTask.FindingStatus = FindingStatus.NeedBlink;
                    }
                }

                dbContext.SaveChanges();

                List <FND_Task> unfinishedFndTasks = dbContext.FND_Tasks
                                                     .Where(t => t.FindingStatus != FindingStatus.Finished ||
                                                            t.CFG_Cart.CartStatus == CartStatus.InCarriageToWorkStation)
                                                     .ToList();
                foreach (FND_Task fndTask in unfinishedFndTasks)
                {
                    CFG_WorkStation cfgWorkStation = fndTask.CFG_WorkStation;
                    CFG_Cart        cfgCart        = fndTask.CFG_Cart;

                    string gzzList = this.GetGzzListFromCfgCartMaterial(cfgCart);

                    CartPtl cartPtl          = CartPtlHost.Instance.GetCartPtl(fndTask.CFG_CartId);
                    Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher();
                    Ptl900U ptl900ULight     = cartPtl.GetPtl900ULight();

                    Display900UItem publisherDisplay900UItem = new Display900UItem();
                    publisherDisplay900UItem.Name        = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", cfgWorkStation.Name, gzzList);
                    publisherDisplay900UItem.Description = string.Format(CultureInfo.InvariantCulture, @"项目:{0},{1}
批次:{2}
最迟抵达:{3:HH:mm:ss}", fndTask.ProjectCode, fndTask.ProjectStep, fndTask.BatchCode, fndTask.MaxNeedArrivedTime);
                    publisherDisplay900UItem.Count       = (ushort)cfgCart.CFG_CartCurrentMaterials
                                                           .Where(ccm => ccm.Quantity != null)
                                                           .Select(ccm => ccm.Quantity.Value)
                                                           .Sum();
                    publisherDisplay900UItem.Unit = "个";

                    ptl900UPublisher.Clear(true);
                    ptl900UPublisher.Lock();
                    ptl900UPublisher.Display(publisherDisplay900UItem, LightColor.Off);

                    if (fndTask.FindingStatus == FindingStatus.New)
                    {
                        ptl900ULight.Clear();
                        ptl900ULight.Display(new Display900UItem(), LightColor.Cyan);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 刷新视图模型。
        /// </summary>
        public void Refresh()
        {
            this.Items.Clear();

            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                List <CFG_Channel> cfgChannels = dbContext.CFG_Channels
                                                 .OrderBy(c => c.Code)
                                                 .ToList();
                foreach (CFG_Channel cfgChannel in cfgChannels)
                {
                    ChannelModel channelModel = new ChannelModel();
                    channelModel.CFG_Channel = cfgChannel;

                    CFG_Pallet cfgPallet = cfgChannel.CFG_ChannelCurrentPallet.CFG_Pallet;

                    if (cfgPallet != null)
                    {
                        channelModel.CurrentPalletCode = cfgPallet.Code;
                    }

                    CFG_Cart cfgCart1 = cfgChannel.CFG_ChannelCurrentCarts.Where(ccc => ccc.Position == 1).Select(ccc => ccc.CFG_Cart).FirstOrDefault();
                    CFG_Cart cfgCart2 = cfgChannel.CFG_ChannelCurrentCarts.Where(ccc => ccc.Position == 2).Select(ccc => ccc.CFG_Cart).FirstOrDefault();
                    CFG_Cart cfgCart3 = cfgChannel.CFG_ChannelCurrentCarts.Where(ccc => ccc.Position == 3).Select(ccc => ccc.CFG_Cart).FirstOrDefault();
                    CFG_Cart cfgCart4 = cfgChannel.CFG_ChannelCurrentCarts.Where(ccc => ccc.Position == 4).Select(ccc => ccc.CFG_Cart).FirstOrDefault();

                    if (cfgCart1 != null)
                    {
                        channelModel.CurrentCartName1 = cfgCart1.Name;
                    }
                    if (cfgCart2 != null)
                    {
                        channelModel.CurrentCartName2 = cfgCart2.Name;
                    }
                    if (cfgCart3 != null)
                    {
                        channelModel.CurrentCartName3 = cfgCart3.Name;
                    }
                    if (cfgCart4 != null)
                    {
                        channelModel.CurrentCartName4 = cfgCart4.Name;
                    }

                    if (cfgChannel.Code.Equals("8"))
                    {
                        channelModel.Light1OnLine = false;
                        channelModel.Light2OnLine = false;
                        channelModel.Light3OnLine = false;
                    }
                    else
                    {
                        channelModel.Light1OnLine = cfgChannel.CFG_ChannelPtlDevices.Where(cpd => cpd.Position == 3).Select(cpd => cpd.OnLine).First();
                        channelModel.Light2OnLine = cfgChannel.CFG_ChannelPtlDevices.Where(cpd => cpd.Position == 4).Select(cpd => cpd.OnLine).First();
                        channelModel.Light3OnLine = cfgChannel.CFG_ChannelPtlDevices.Where(cpd => cpd.Position == 5).Select(cpd => cpd.OnLine).First();
                    }
                    this.Items.Add(channelModel);
                }
            }
        }
Ejemplo n.º 6
0
        private void buttonOK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                {
                    int from  = int.Parse(this.textBoxFrom.Text, CultureInfo.InvariantCulture);
                    int count = int.Parse(this.textBoxCount.Text, CultureInfo.InvariantCulture);

                    for (int cartNumber = from; cartNumber < from + count; cartNumber++)
                    {
                        CFG_Cart cfgCart = new CFG_Cart();
                        cfgCart.Code       = string.Format(CultureInfo.InvariantCulture, "{0:000000}", 100000 + cartNumber);
                        cfgCart.Name       = string.Format(CultureInfo.InvariantCulture, "料车 {0}", cartNumber);
                        cfgCart.Rfid1      = "AABBCCDDEEFF";
                        cfgCart.XGateIP    = "192.168.0.10";
                        cfgCart.CartStatus = CartStatus.Free;

                        dbContext.CFG_Carts.Add(cfgCart);

                        //小车上的 8 个库位
                        for (int position = 1; position <= 8; position++)
                        {
                            CFG_CartCurrentMaterial cfgCartCurrentMaterial = new CFG_CartCurrentMaterial();
                            cfgCartCurrentMaterial.CFG_Cart  = cfgCart;
                            cfgCartCurrentMaterial.Position  = position;
                            cfgCartCurrentMaterial.Usability = CartPositionUsability.Enable;

                            dbContext.CFG_CartCurrentMaterials.Add(cfgCartCurrentMaterial);
                        }

                        //小车上的 10 个标签
                        for (byte deviceAddress = 1; deviceAddress <= 10; deviceAddress++)
                        {
                            CFG_CartPtlDevice cfgCartPtlDevice = new CFG_CartPtlDevice();
                            cfgCartPtlDevice.CFG_Cart      = cfgCart;
                            cfgCartPtlDevice.DeviceAddress = deviceAddress;

                            dbContext.CFG_CartPtlDevices.Add(cfgCartPtlDevice);
                        }
                    }

                    dbContext.SaveChanges();
                }

                this.DialogResult = true;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 刷新视图模型。
        /// </summary>
        public void Refresh()
        {
            this.Items.Clear();

            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                List <string> listWorkStationCode = dbContext.MarketZones.OrderBy(t => t.AreaId).Select(t => t.AreaId).Distinct().ToList();

                List <MarketZone> marketZones = dbContext.MarketZones.ToList();

                foreach (string workStationCode in listWorkStationCode)
                {
                    MarketModel marketModel = new MarketModel();
                    marketModel.WorkStationCode = workStationCode;

                    List <MarketZone> curMarketZones = marketZones.Where(t => t.AreaId.Equals(workStationCode)).ToList();
                    if (curMarketZones.Count > 0)
                    {
                        foreach (MarketZone marketZone in curMarketZones)
                        {
                            if (marketZone.CFG_CartId != null)
                            {
                                if (marketZone.Position == 1)
                                {
                                    CFG_Cart cfgCart1 = dbContext.CFG_Carts.FirstOrDefault(t => t.Id == marketZone.CFG_CartId);
                                    marketModel.CurrentCartName1 = cfgCart1.Name;
                                }
                                else if (marketZone.Position == 2)
                                {
                                    CFG_Cart cfgCart2 = dbContext.CFG_Carts.FirstOrDefault(t => t.Id == marketZone.CFG_CartId);
                                    marketModel.CurrentCartName2 = cfgCart2.Name;
                                }
                                else if (marketZone.Position == 3)
                                {
                                    CFG_Cart cfgCart3 = dbContext.CFG_Carts.FirstOrDefault(t => t.Id == marketZone.CFG_CartId);
                                    marketModel.CurrentCartName3 = cfgCart3.Name;
                                }
                                else if (marketZone.Position == 4)
                                {
                                    CFG_Cart cfgCart4 = dbContext.CFG_Carts.FirstOrDefault(t => t.Id == marketZone.CFG_CartId);
                                    marketModel.CurrentCartName4 = cfgCart4.Name;
                                }
                            }
                        }
                    }

                    this.Items.Add(marketModel);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 从巷道解除料车的停靠。
        /// </summary>
        /// <param name="cfgChannelId">巷道的主键。</param>
        /// <param name="cfgCartCodeOrRfid">料车编码或 RFID 标签。</param>
        public void UnDockCartFromChannel(int cfgChannelId, string cfgCartCodeOrRfid)
        {
            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                CFG_Cart cfgCart = dbContext.CFG_Carts
                                   .FirstOrDefault(c => c.Code == cfgCartCodeOrRfid ||
                                                   c.Rfid1 == cfgCartCodeOrRfid ||
                                                   c.Rfid2 == cfgCartCodeOrRfid);

                if (cfgCart == null)
                {
                    throw new ArgumentException("没有找到小车:" + cfgCartCodeOrRfid, "cfgCartCodeOrRfid");
                }

                ChannelCurrentCartBinder.Instance.UnDock(cfgChannelId, cfgCart.Id);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 如果长时间无法交互,则自动交互。
        /// </summary>
        void AutoPressByDeviceErrorAsync(long capturedCurrentAsmTaskItemId, Ptl900U ptl900U, Display900UItem display900UItem)
        {
            ThreadPool.QueueUserWorkItem(_ =>
            {
                DateTime beginSleepTime = DateTime.Now;
                while (this.CurrentAsmTaskItemId == capturedCurrentAsmTaskItemId && ptl900U.InError != false && (DateTime.Now - beginSleepTime) < this.autoPressTimeout)
                {
                    Thread.Sleep(1);
                }

                if (this.CurrentAsmTaskItemId == capturedCurrentAsmTaskItemId &&
                    ptl900U.InError != false)
                {
                    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 == 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);
                        }
                    }
                    catch { }

                    ptl900U.Clear(true);

                    Ptl900UPressedEventArgs ptl900UPressedEventArgs = new Ptl900UPressedEventArgs();
                    ptl900UPressedEventArgs.ResultByItem.Add(display900UItem, display900UItem.Count);

                    this.ptl900U_Pressed(ptl900U, ptl900UPressedEventArgs, true);
                }
            });
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 绑定料车的 RFID 标签。
        /// </summary>
        /// <param name="cfgCartCode">料车编码。</param>
        /// <param name="rfid1">RFID 标签一。</param>
        /// <param name="rfid2">RFID 标签二。</param>
        public void BindCartRfid(string cfgCartCode, string rfid1, string rfid2)
        {
            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                CFG_Cart cfgCart = dbContext.CFG_Carts
                                   .FirstOrDefault(c => c.Code == cfgCartCode);

                if (cfgCart == null)
                {
                    throw new ArgumentException("没有找到小车:" + cfgCartCode, "cfgCartCode");
                }

                cfgCart.Rfid1 = rfid1;
                cfgCart.Rfid2 = rfid2;

                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 生产线边空满交换
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnCartSwitch_Click(object sender, RoutedEventArgs e)
 {
     using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
     {
         GeelyPTL.Dialogs.SwitchCartWindow dlg = new GeelyPTL.Dialogs.SwitchCartWindow();
         dlg.ShowDialog();
         if (dlg.DialogResult == false)
         {
             return;
         }
         string sSwitchCartCode = dlg.SwitchCartCode;
         if (string.IsNullOrEmpty(sSwitchCartCode))
         {
             MessageBox.Show("请先填写要进行空满交换的料架编码");
             return;
         }
         CFG_Cart cfgCart = dbContext.CFG_Carts.FirstOrDefault(t => t.Code.Equals(sSwitchCartCode));
         if (cfgCart == null)
         {
             MessageBox.Show("没有找到对应的料架");
             return;
         }
         if (MessageBox.Show("是否要开始生产线边空满交换?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
         {
             ////解除停靠
             //CFG_WorkStationCurrentCart cfgWorkStationCurrentCart = dbContext.CFG_WorkStationCurrentCarts
             //                                                           .FirstOrDefault(wscc => wscc.CFG_CartId == cfgCart.Id);
             //if (cfgWorkStationCurrentCart != null)
             //{
             //    cfgWorkStationCurrentCart.CFG_CartId = null;
             //    cfgWorkStationCurrentCart.DockedTime = null;
             //}
             List <DST_DistributeTask> distributeTasks = DistributingTaskGenerator.Instance.GenerateProductCartSwitchTask(cfgCart);
             foreach (DST_DistributeTask distributeTask in distributeTasks)
             {
                 dbContext.DST_DistributeTasks.Add(distributeTask);
             }
             string result = dbContext.SaveChanges() > 0 ? "生成空满交换任务成功" : "生成空满交换任务失败";
             MessageBox.Show(result);
         }
     }
 }
Ejemplo n.º 12
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                {
                    CFG_Cart cfgCart = dbContext.CFG_Carts
                                       .First(c => c.Id == this.cfgCartId);

                    this.textBoxName.Text     = cfgCart.Name;
                    this.textBoxRfid1.Text    = cfgCart.Rfid1;
                    this.textBoxXGateMAC.Text = cfgCart.XGateMAC;
                    this.textBoxXGateIP.Text  = cfgCart.XGateIP;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                this.Close();
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 还原之前的停靠状态。
        /// </summary>
        void Restore()
        {
            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                CFG_WorkStation cfgWorkStation = dbContext.CFG_WorkStations
                                                 .First(ws => ws.Id == this.CFG_WorkStationId);
                List <CFG_WorkStationCurrentCart> cfgWorkStationCurrentCarts = dbContext.CFG_WorkStationCurrentCarts
                                                                               .Include(wscc => wscc.CFG_WorkStation)
                                                                               .Include(wscc => wscc.CFG_Cart)
                                                                               .Include(wscc => wscc.CFG_Cart.CFG_CartCurrentMaterials)
                                                                               .Where(wscc => wscc.CFG_WorkStationId == this.CFG_WorkStationId && wscc.CFG_CartId != null)
                                                                               .ToList();

                foreach (CFG_WorkStationCurrentCart cfgWorkStationCurrentCart in cfgWorkStationCurrentCarts)
                {
                    CFG_Cart cfgCart = cfgWorkStationCurrentCart.CFG_Cart;
                    CFG_CartCurrentMaterial firstNotEmptyCfgCartCurrentMaterial = cfgCart.CFG_CartCurrentMaterials
                                                                                  .FirstOrDefault(ccm => ccm.AST_CartTaskItemId != null);

                    CartPtl cartPtl = CartPtlHost.Instance.GetCartPtl(cfgCart.Id);
                    Ptl900U cartPtl900UPublisher = cartPtl.GetPtl900UPublisher();

                    Display900UItem cartPublisherDisplay900UItem = new Display900UItem();
                    cartPublisherDisplay900UItem.Name = "抵达工位 " + cfgWorkStation.Name;
                    if (firstNotEmptyCfgCartCurrentMaterial != null)
                    {
                        cartPublisherDisplay900UItem.Description = string.Format(CultureInfo.InvariantCulture, @"项目:{0}
阶段:{1}
批次:{2}", firstNotEmptyCfgCartCurrentMaterial.ProjectCode, firstNotEmptyCfgCartCurrentMaterial.ProjectStep, firstNotEmptyCfgCartCurrentMaterial.BatchCode);
                    }
                    cartPublisherDisplay900UItem.Count = (ushort)cfgWorkStationCurrentCart.Position;
                    cartPublisherDisplay900UItem.Unit  = "位";

                    cartPtl900UPublisher.Lock();
                    cartPtl900UPublisher.Display(cartPublisherDisplay900UItem, LightColor.Off);
                }

                Logger.Log(this.GetType().Name + "." + cfgWorkStation.Code, DateTime.Now.ToString("HH:mm:ss") + " Restore() 完成" + Environment.NewLine);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 解绑小车
        /// </summary>
        /// <param name="nCartID"></param>
        /// <returns></returns>
        public string UnDockCart(int nCartID)
        {
            string result = "Success";

            try
            {
                using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                {
                    CFG_Cart cfgCart = dbContext.CFG_Carts.FirstOrDefault(t => t.Id == nCartID);
                    if (cfgCart != null)
                    {
                        List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = cfgCart.CFG_CartCurrentMaterials.ToList();

                        //设备控制
                        CartPtl cartPtl          = CartPtlHost.Instance.GetCartPtl(nCartID);
                        Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher();
                        Ptl900U ptl900ULight     = cartPtl.GetPtl900ULight();

                        ptl900UPublisher.Clear(true);
                        ptl900UPublisher.Unlock();

                        foreach (CFG_CartCurrentMaterial cfgCartCurrentMaterial in cfgCartCurrentMaterials)
                        {
                            Ptl900U ptl900U = cartPtl.GetPtl900UByPosition(cfgCartCurrentMaterial.Position);

                            ptl900U.Clear(true);
                            ptl900U.Unlock();
                        }

                        ptl900ULight.Clear();
                    }
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return(result);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 停靠料车到巷道。
        /// </summary>
        /// <param name="cfgChannelId">巷道的主键。</param>
        /// <param name="cfgCartCodeOrRfid">料车编码或 RFID 标签。</param>
        public void DockCartToChannel(int cfgChannelId, string cfgCartCodeOrRfid)
        {
            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                CFG_Cart cfgCart = dbContext.CFG_Carts
                                   .FirstOrDefault(c => c.Code == cfgCartCodeOrRfid ||
                                                   c.Rfid1 == cfgCartCodeOrRfid ||
                                                   c.Rfid2 == cfgCartCodeOrRfid);

                if (cfgCart == null)
                {
                    throw new ArgumentException("没有找到小车:" + cfgCartCodeOrRfid, "cfgCartCodeOrRfid");
                }

                int?position = ChannelCurrentCartBinder.Instance.GetFirstEmptyPosition(cfgChannelId);
                if (position == null)
                {
                    throw new ArgumentException("车位已满。", "cfgChannelId");
                }

                ChannelCurrentCartBinder.Instance.Dock(cfgChannelId, position.Value, cfgCart.Id);
            }
        }
Ejemplo n.º 16
0
        private void buttonOK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                {
                    CFG_Cart cfgCart = dbContext.CFG_Carts
                                       .First(c => c.Id == this.cfgCartId);

                    cfgCart.Rfid1    = this.textBoxRfid1.Text.Trim();
                    cfgCart.XGateMAC = this.textBoxXGateMAC.Text.Trim();
                    cfgCart.XGateIP  = this.textBoxXGateIP.Text.Trim();

                    dbContext.SaveChanges();
                }

                this.DialogResult = true;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 17
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                {
                    CFG_Cart cfgCart = dbContext.CFG_Carts
                                       .First(c => c.Id == this.cfgCartId);
                    List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = dbContext.CFG_CartCurrentMaterials
                                                                             .Include(ccm => ccm.CFG_Pallet)
                                                                             .Where(ccm => ccm.CFG_CartId == this.cfgCartId)
                                                                             .OrderBy(ccm => ccm.Position)
                                                                             .ToList();

                    this.textBlockCartName.Text = cfgCart.Name;

                    CFG_CartCurrentMaterial firstNotEmptyCfgCartCurrentMaterial = cfgCartCurrentMaterials
                                                                                  .FirstOrDefault(ccm => ccm.Quantity != null);
                    if (firstNotEmptyCfgCartCurrentMaterial != null)
                    {
                        this.textBoxProjectCode.Text     = firstNotEmptyCfgCartCurrentMaterial.ProjectCode;
                        this.textBoxProjectStep.Text     = firstNotEmptyCfgCartCurrentMaterial.ProjectStep;
                        this.textBoxBatchCode.Text       = firstNotEmptyCfgCartCurrentMaterial.BatchCode;
                        this.textBoxWorkStationCode.Text = firstNotEmptyCfgCartCurrentMaterial.CFG_WorkStation.Code;
                        this.textBoxChannelName.Text     = firstNotEmptyCfgCartCurrentMaterial.CFG_Channel.Name;
                    }

                    this.dataGrid.ItemsSource = cfgCartCurrentMaterials;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                this.Close();
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 测试用方法。
        /// </summary>
        public void TestMethod_ClearCart(string cfgCartCodeOrRfid)
        {
            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                CFG_Cart cfgCart = dbContext.CFG_Carts
                                   .First(c => c.Code == cfgCartCodeOrRfid || c.Rfid1 == cfgCartCodeOrRfid || c.Rfid2 == cfgCartCodeOrRfid);
                List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = cfgCart.CFG_CartCurrentMaterials
                                                                         .ToList();
                List <CFG_ChannelCurrentCart> cfgChannelCurrentCarts = cfgCart.CFG_ChannelCurrentCarts
                                                                       .ToList();
                List <CFG_WorkStationCurrentCart> cfgWorkStationCurrentCarts = cfgCart.CFG_WorkStationCurrentCarts
                                                                               .ToList();

                cfgCart.CartStatus = CartStatus.Free;

                foreach (CFG_CartCurrentMaterial cfgCartCurrentMaterial in cfgCartCurrentMaterials)
                {
                    cfgCartCurrentMaterial.AST_CartTaskItemId = null;
                    cfgCartCurrentMaterial.ProjectCode        = null;
                    cfgCartCurrentMaterial.WbsId              = null;
                    cfgCartCurrentMaterial.ProjectStep        = null;
                    cfgCartCurrentMaterial.CFG_WorkStationId  = null;
                    cfgCartCurrentMaterial.BatchCode          = null;
                    cfgCartCurrentMaterial.CFG_ChannelId      = null;
                    cfgCartCurrentMaterial.CFG_PalletId       = null;
                    cfgCartCurrentMaterial.BoxCode            = null;
                    cfgCartCurrentMaterial.FromPalletPosition = null;
                    cfgCartCurrentMaterial.MaterialCode       = null;
                    cfgCartCurrentMaterial.MaterialName       = null;
                    cfgCartCurrentMaterial.MaterialBarcode    = null;
                    cfgCartCurrentMaterial.Quantity           = null;
                    cfgCartCurrentMaterial.AssortedTime       = null;
                    cfgCartCurrentMaterial.CFG_EmployeeId     = null;
                    if (cfgCartCurrentMaterial.Usability != CartPositionUsability.DisableByOffLineDevice)
                    {
                        cfgCartCurrentMaterial.Usability = CartPositionUsability.Enable;
                    }
                }

                foreach (CFG_ChannelCurrentCart cfgChannelCurrentCart in cfgChannelCurrentCarts)
                {
                    cfgChannelCurrentCart.CFG_CartId = null;
                    cfgChannelCurrentCart.DockedTime = null;
                }

                foreach (CFG_WorkStationCurrentCart cfgWorkStationCurrentCart in cfgWorkStationCurrentCarts)
                {
                    cfgWorkStationCurrentCart.CFG_CartId = null;
                    cfgWorkStationCurrentCart.DockedTime = null;
                }

                dbContext.SaveChanges();

                //设备控制
                CartPtl cartPtl          = CartPtlHost.Instance.GetCartPtl(cfgCart.Id);
                Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher();
                Ptl900U ptl900ULight     = cartPtl.GetPtl900ULight();

                ptl900UPublisher.Clear(true);
                ptl900UPublisher.Unlock();

                foreach (CFG_CartCurrentMaterial cfgCartCurrentMaterial in cfgCartCurrentMaterials)
                {
                    Ptl900U ptl900U = cartPtl.GetPtl900UByPosition(cfgCartCurrentMaterial.Position);

                    ptl900U.Clear(true);
                    ptl900U.Unlock();
                }

                ptl900ULight.Clear();
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 查询当前任务。
        /// </summary>
        /// <param name="cfgChannelId">巷道的主键。</param>
        public AndroidPdaTaskInfo QueryCurrentTaskInfo(int cfgChannelId)
        {
            AssortingExecutor assortingExecutor = AssortingExecutorLoader.Instance.GetByChannelId(cfgChannelId);

            AndroidPdaTaskInfo result = new AndroidPdaTaskInfo();

            result.CFG_ChannelId = cfgChannelId;

            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                if (assortingExecutor.CurrentCfgCartId != null)
                {
                    CFG_Cart cfgCart = dbContext.CFG_Carts
                                       .First(c => c.Id == assortingExecutor.CurrentCfgCartId.Value);
                    result.CFG_CartId = cfgCart.Id;
                    result.CartName   = cfgCart.Name;
                    result.CartOnLine = cfgCart.OnLine;
                }

                if (assortingExecutor.CurrentAstCartTaskItemId == null)
                {
                    if (assortingExecutor.CurrentAstPalletTaskItemId != null)
                    {
                        AST_PalletTaskItem currentAstPalletTaskItem = dbContext.AST_PalletTaskItems
                                                                      .First(pti => pti.Id == assortingExecutor.CurrentAstPalletTaskItemId.Value);
                        List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = dbContext.CFG_CartCurrentMaterials
                                                                                 .Where(ccm => ccm.CFG_CartId == assortingExecutor.CurrentCfgCartId.Value)
                                                                                 .ToList();
                        foreach (CFG_CartCurrentMaterial cfgCartCurrentMaterial in cfgCartCurrentMaterials)
                        {
                            if (cfgCartCurrentMaterial.AST_CartTaskItemId == null)
                            {
                                //整层大件需要同层的两个空库位
                                if (currentAstPalletTaskItem.IsBig)
                                {
                                    if ((cfgCartCurrentMaterial.Position == 1 && cfgCartCurrentMaterials[1].Usability != CartPositionUsability.Enable) ||
                                        (cfgCartCurrentMaterial.Position == 2 && cfgCartCurrentMaterials[0].Usability != CartPositionUsability.Enable) ||
                                        (cfgCartCurrentMaterial.Position == 3 && cfgCartCurrentMaterials[3].Usability != CartPositionUsability.Enable) ||
                                        (cfgCartCurrentMaterial.Position == 4 && cfgCartCurrentMaterials[2].Usability != CartPositionUsability.Enable) ||
                                        (cfgCartCurrentMaterial.Position == 5 && cfgCartCurrentMaterials[5].Usability != CartPositionUsability.Enable) ||
                                        (cfgCartCurrentMaterial.Position == 6 && cfgCartCurrentMaterials[4].Usability != CartPositionUsability.Enable) ||
                                        (cfgCartCurrentMaterial.Position == 7 && cfgCartCurrentMaterials[7].Usability != CartPositionUsability.Enable) ||
                                        (cfgCartCurrentMaterial.Position == 8 && cfgCartCurrentMaterials[6].Usability != CartPositionUsability.Enable))
                                    {
                                        continue;
                                    }
                                }

                                result.CartPositions.Add(cfgCartCurrentMaterial.Position);
                            }
                        }
                    }
                }
                else
                {
                    AST_CartTaskItem astCartTaskItem = dbContext.AST_CartTaskItems
                                                       .First(cti => cti.Id == assortingExecutor.CurrentAstCartTaskItemId.Value);
                    result.CartPositions.Add(astCartTaskItem.CartPosition);
                    result.PickedQuantity  = astCartTaskItem.AssortedQuantity;
                    result.AssortingStatus = astCartTaskItem.AssortingStatus;
                }

                if (assortingExecutor.CurrentAstPalletTaskItemId != null)
                {
                    AST_PalletTaskItem astPalletTaskItem = dbContext.AST_PalletTaskItems
                                                           .First(pti => pti.Id == assortingExecutor.CurrentAstPalletTaskItemId.Value);
                    result.MaterialCode   = astPalletTaskItem.MaterialCode;
                    result.MaterialName   = astPalletTaskItem.MaterialName;
                    result.ToPickQuantity = astPalletTaskItem.ToPickQuantity;
                }
            }

            return(result);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 确保基础数据已经初始化。
        /// </summary>
        public static void EnsureInitialized()
        {
            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                if (!dbContext.CFG_Employees.Any())
                {
                    //操作员
                    CFG_Employee cfgEmployee = new CFG_Employee();
                    cfgEmployee.Code      = "Administrator";
                    cfgEmployee.Name      = "管理员";
                    cfgEmployee.LoginName = "admin";
                    cfgEmployee.Password  = string.Empty;
                    cfgEmployee.IsEnabled = true;

                    dbContext.CFG_Employees.Add(cfgEmployee);

                    //巷道
                    //转台上的标签,托盘有 5 个库位,但只在单侧使用 3 个标签
                    //7 个巷道共用 1 个 4 口 XGate,按现场走线,总线 1 对应 1、2 巷道,总线 2 对应 3 巷道,总线 3 对应 4、5 巷道,总线 4 对应 6、7 巷道
                    //标签地址分别为:1、2、3,4、5、6,51、52、53,101、102、103,104、105、106,151、152、153,154、155、156。
                    //托盘库位定义为:1、2 在远端需旋转,3、4、5 在近段
                    string channelXGateIP = "10.34.36.17";
                    Dictionary <int, byte[]> channelPtl900UAddressesByChannelNumber = new Dictionary <int, byte[]>();
                    channelPtl900UAddressesByChannelNumber.Add(1, new byte[] { 3, 1, 1, 2, 3 });
                    channelPtl900UAddressesByChannelNumber.Add(2, new byte[] { 6, 4, 4, 5, 6 });
                    channelPtl900UAddressesByChannelNumber.Add(3, new byte[] { 53, 51, 51, 52, 53 });
                    channelPtl900UAddressesByChannelNumber.Add(4, new byte[] { 103, 101, 101, 102, 103 });
                    channelPtl900UAddressesByChannelNumber.Add(5, new byte[] { 106, 104, 104, 105, 106 });
                    channelPtl900UAddressesByChannelNumber.Add(6, new byte[] { 153, 151, 151, 152, 153 });
                    channelPtl900UAddressesByChannelNumber.Add(7, new byte[] { 156, 154, 154, 155, 156 });

                    for (int channelNumber = 1; channelNumber <= channelPtl900UAddressesByChannelNumber.Count; channelNumber++)
                    {
                        CFG_Channel cfgChannel = new CFG_Channel();
                        cfgChannel.Code = string.Format(CultureInfo.InvariantCulture, "{0}", channelNumber);
                        cfgChannel.Name = string.Format(CultureInfo.InvariantCulture, "巷道 {0}", channelNumber);

                        dbContext.CFG_Channels.Add(cfgChannel);

                        //转台上的标签
                        byte[] deviceAddresses = channelPtl900UAddressesByChannelNumber[channelNumber];
                        for (int position = 1; position <= 5; position++)
                        {
                            byte deviceAddress = deviceAddresses[position - 1];
                            byte busIndex      = (byte)(deviceAddress / 50);

                            CFG_ChannelPtlDevice cfgChannelPtlDevice = new CFG_ChannelPtlDevice();
                            cfgChannelPtlDevice.CFG_Channel    = cfgChannel;
                            cfgChannelPtlDevice.Position       = position;
                            cfgChannelPtlDevice.XGateIP        = channelXGateIP;
                            cfgChannelPtlDevice.RS485BusIndex  = busIndex;
                            cfgChannelPtlDevice.Ptl900UAddress = deviceAddress;

                            dbContext.CFG_ChannelPtlDevices.Add(cfgChannelPtlDevice);
                        }

                        //巷道边的 4 个车位,多加两个备用车位
                        for (int position = 1; position <= 6; position++)
                        {
                            CFG_ChannelCurrentCart cfgChannelCurrentCart = new CFG_ChannelCurrentCart();
                            cfgChannelCurrentCart.CFG_Channel = cfgChannel;
                            cfgChannelCurrentCart.Position    = position;

                            dbContext.CFG_ChannelCurrentCarts.Add(cfgChannelCurrentCart);
                        }

                        //巷道上的 1 个托盘
                        CFG_ChannelCurrentPallet cfgChannelCurrentPallet = new CFG_ChannelCurrentPallet();
                        cfgChannelCurrentPallet.CFG_Channel = cfgChannel;

                        dbContext.CFG_ChannelCurrentPallets.Add(cfgChannelCurrentPallet);
                    }

                    //小车
                    for (int cartNumber = 1; cartNumber <= 100; cartNumber++)
                    {
                        CFG_Cart cfgCart = new CFG_Cart();
                        cfgCart.Code       = string.Format(CultureInfo.InvariantCulture, "{0:000000}", 100000 + cartNumber);
                        cfgCart.Name       = string.Format(CultureInfo.InvariantCulture, "料车 {0}", cartNumber);
                        cfgCart.Rfid1      = "AABBCCDDEEFF";
                        cfgCart.XGateIP    = "192.168.0.10";
                        cfgCart.CartStatus = CartStatus.Free;

                        dbContext.CFG_Carts.Add(cfgCart);

                        //小车上的 8 个库位
                        for (int position = 1; position <= 8; position++)
                        {
                            CFG_CartCurrentMaterial cfgCartCurrentMaterial = new CFG_CartCurrentMaterial();
                            cfgCartCurrentMaterial.CFG_Cart  = cfgCart;
                            cfgCartCurrentMaterial.Position  = position;
                            cfgCartCurrentMaterial.Usability = CartPositionUsability.Enable;

                            dbContext.CFG_CartCurrentMaterials.Add(cfgCartCurrentMaterial);
                        }

                        //小车上的 10 个标签
                        for (byte deviceAddress = 1; deviceAddress <= 10; deviceAddress++)
                        {
                            CFG_CartPtlDevice cfgCartPtlDevice = new CFG_CartPtlDevice();
                            cfgCartPtlDevice.CFG_Cart      = cfgCart;
                            cfgCartPtlDevice.DeviceAddress = deviceAddress;

                            dbContext.CFG_CartPtlDevices.Add(cfgCartPtlDevice);
                        }
                    }

                    //dbContext.SaveChanges();
                }

                ////线边工位的8个车位
                //List<CFG_WorkStation> cfgWorkStations = dbContext.CFG_WorkStations.ToList();
                //foreach (CFG_WorkStation cfgWorkStation in cfgWorkStations)
                //{
                //    if (cfgWorkStation.CFG_WorkStationCurrentCarts != null && cfgWorkStation.CFG_WorkStationCurrentCarts.Count > 0)
                //    {
                //        continue;
                //    }

                //    for (int position = 1; position <= 8; position++)
                //    {
                //        CFG_WorkStationCurrentCart cfgWorkStationCurrentCart = new CFG_WorkStationCurrentCart();
                //        cfgWorkStationCurrentCart.CFG_WorkStation = cfgWorkStation;
                //        cfgWorkStationCurrentCart.Position = position;

                //        dbContext.CFG_WorkStationCurrentCarts.Add(cfgWorkStationCurrentCart);
                //    }
                //}

                //AGV开关信息
                if (!dbContext.DST_AgvSwitchs.Any())
                {
                    DST_AgvSwitch dstAgvSwitch = new DST_AgvSwitch();
                    dstAgvSwitch.isOpen        = false;
                    dstAgvSwitch.lastCloseTime = DateTime.Now;

                    dbContext.DST_AgvSwitchs.Add(dstAgvSwitch);
                }

                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 21
0
        /// <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);
                    }
                }
            });
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 显式或定时刷新。
        /// </summary>
        public void Refresh()
        {
            lock (this.refreshSyncRoot)
            {
                using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                {
                    List <FND_Task> needToDoFndTasks = dbContext.FND_Tasks
                                                       .Where(t => t.FindingStatus == FindingStatus.NeedDisplay ||
                                                              t.FindingStatus == FindingStatus.NeedBlink ||
                                                              t.FindingStatus == FindingStatus.NeedClear)
                                                       .ToList();

                    //获取是否开启AGV配送PTL料架
                    DST_AgvSwitch dstAgvSwitch = dbContext.DST_AgvSwitchs.FirstOrDefault(t => t.isOpen);

                    foreach (FND_Task fndTask in needToDoFndTasks)
                    {
                        CFG_WorkStation cfgWorkStation = fndTask.CFG_WorkStation;
                        CFG_Cart        cfgCart        = fndTask.CFG_Cart;

                        string gzzList = this.GetGzzListFromCfgCartMaterial(cfgCart);

                        CartPtl cartPtl          = CartPtlHost.Instance.GetCartPtl(fndTask.CFG_CartId);
                        Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher();
                        Ptl900U ptl900ULight     = cartPtl.GetPtl900ULight();

                        Display900UItem publisherDisplay900UItem = new Display900UItem();
                        publisherDisplay900UItem.Name        = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", cfgWorkStation.Name, gzzList);
                        publisherDisplay900UItem.Description = string.Format(CultureInfo.InvariantCulture, @"项目:{0},{1}
批次:{2}
最迟抵达:{3:HH:mm:ss}", fndTask.ProjectCode, fndTask.ProjectStep, fndTask.BatchCode, fndTask.MaxNeedArrivedTime);
                        publisherDisplay900UItem.Count       = (ushort)cfgCart.CFG_CartCurrentMaterials
                                                               .Where(ccm => ccm.Quantity != null)
                                                               .Select(ccm => ccm.Quantity.Value)
                                                               .Sum();
                        publisherDisplay900UItem.Unit = "个";

                        Display900UItem lightDisplay900UItem = new Display900UItem();

                        LightColor lightColor = (LightColor)fndTask.LightColor;

                        LightMode lightMode = new LightMode();
                        lightMode.Color  = lightColor;
                        lightMode.Period = LightOnOffPeriod.Period200;
                        lightMode.Ratio  = LightOnOffRatio.RatioP1V1;

                        if (fndTask.FindingStatus == FindingStatus.NeedDisplay)
                        {
                            //先保证数据库更新成功
                            fndTask.DisplayTime   = DateTime.Now;
                            fndTask.FindingStatus = FindingStatus.Displaying;

                            cfgCart.CartStatus = CartStatus.WaitingToWorkStation;

                            dbContext.SaveChanges();

                            //再控制设备
                            ptl900UPublisher.Clear(true);
                            ptl900UPublisher.Lock();
                            ptl900UPublisher.Display(publisherDisplay900UItem, LightColor.Off);

                            ptl900ULight.Clear();
                            ptl900ULight.Display(lightDisplay900UItem, lightColor);
                        }
                        else if (fndTask.FindingStatus == FindingStatus.NeedBlink)
                        {
                            if (fndTask.DisplayTime == null)
                            {
                                fndTask.CFG_EmployeeId = 1;
                                fndTask.DisplayTime    = DateTime.Now;
                            }
                            fndTask.DepartedTime  = DateTime.Now;
                            fndTask.FindingStatus = FindingStatus.Blinking;

                            if (dstAgvSwitch == null)
                            {
                                cfgCart.CartStatus = CartStatus.InCarriageToWorkStation;
                            }

                            //当前请求可以分小车提交
                            FND_DeliveryResult fndDeliveryResult = new FND_DeliveryResult();
                            fndDeliveryResult.FND_TaskId         = fndTask.Id;
                            fndDeliveryResult.ProjectCode        = fndTask.ProjectCode;
                            fndDeliveryResult.ProjectStep        = fndTask.ProjectStep;
                            fndDeliveryResult.CFG_WorkStationId  = fndTask.CFG_WorkStationId;
                            fndDeliveryResult.BatchCode          = fndTask.BatchCode;
                            fndDeliveryResult.MaxNeedArrivedTime = fndTask.MaxNeedArrivedTime;
                            fndDeliveryResult.CFG_CartId         = fndTask.CFG_CartId;
                            fndDeliveryResult.DepartedTime       = DateTime.Now;
                            fndDeliveryResult.CFG_EmployeeId     = fndTask.CFG_EmployeeId.Value;

                            dbContext.FND_DeliveryResults.Add(fndDeliveryResult);

                            FND_DeliveryResultMessage fndDeliveryResultMessage = new FND_DeliveryResultMessage();
                            fndDeliveryResultMessage.FND_DeliveryResult = fndDeliveryResult;
                            fndDeliveryResultMessage.SentSuccessful     = false;

                            dbContext.FND_DeliveryResultMessages.Add(fndDeliveryResultMessage);

                            List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = fndTask.CFG_Cart.CFG_CartCurrentMaterials
                                                                                     .Where(ccm => ccm.Quantity > 0)
                                                                                     .ToList();
                            foreach (CFG_CartCurrentMaterial cfgCartCurrentMaterial in cfgCartCurrentMaterials)
                            {
                                FND_DeliveryResultItem fndDeliveryResultItem = new FND_DeliveryResultItem();
                                fndDeliveryResultItem.FND_DeliveryResult = fndDeliveryResult;
                                fndDeliveryResultItem.CartPosition       = cfgCartCurrentMaterial.Position;
                                fndDeliveryResultItem.MaterialCode       = cfgCartCurrentMaterial.MaterialCode;
                                fndDeliveryResultItem.MaterialName       = cfgCartCurrentMaterial.MaterialName;
                                fndDeliveryResultItem.MaterialBarcode    = cfgCartCurrentMaterial.MaterialBarcode;
                                fndDeliveryResultItem.Quantity           = cfgCartCurrentMaterial.Quantity.Value;

                                dbContext.FND_DeliveryResultItems.Add(fndDeliveryResultItem);
                            }

                            dbContext.SaveChanges();

                            ptl900ULight.Clear();
                            ptl900ULight.Display(lightDisplay900UItem, lightMode, false);
                        }
                        else if (fndTask.FindingStatus == FindingStatus.NeedClear)
                        {
                            fndTask.FindingStatus = FindingStatus.Finished;

                            dbContext.SaveChanges();

                            ptl900ULight.Clear();
                        }
                    }

                    //运输一段时间后自动进入 NeedClear 状态
                    DateTime        maxBlinkingTime   = DateTime.Now.Subtract(this.autoClearPeriod);
                    List <FND_Task> autoClearFndTasks = dbContext.FND_Tasks
                                                        .Where(t => t.FindingStatus == FindingStatus.Blinking &&
                                                               t.DisplayTime < maxBlinkingTime)
                                                        .ToList();

                    foreach (FND_Task fndTask in autoClearFndTasks)
                    {
                        fndTask.FindingStatus = FindingStatus.NeedClear;
                        dbContext.SaveChanges();
                    }

                    if (dstAgvSwitch == null)
                    {
                        //运输一段时间后自动抵达生产线
                        DateTime        maxCarriageTime     = DateTime.Now.Subtract(this.autoReachedPeriod);
                        List <FND_Task> autoReachedFndTasks = dbContext.FND_Tasks
                                                              .Where(t => t.CFG_Cart.CartStatus == CartStatus.InCarriageToWorkStation &&
                                                                     t.FindingStatus == FindingStatus.Finished &&
                                                                     t.DepartedTime < maxCarriageTime)
                                                              .ToList();

                        foreach (FND_Task fndTask in autoReachedFndTasks)
                        {
                            CFG_WorkStationCurrentCart cfgWorkStationCurrentCart = dbContext.CFG_WorkStationCurrentCarts
                                                                                   .Where(wscc => wscc.CFG_WorkStationId == fndTask.CFG_WorkStationId &&
                                                                                          wscc.CFG_CartId == null)
                                                                                   .OrderBy(wscc => wscc.Position)
                                                                                   .FirstOrDefault();
                            if (cfgWorkStationCurrentCart != null)
                            {
                                CFG_Cart cfgCart = fndTask.CFG_Cart;

                                cfgWorkStationCurrentCart.CFG_CartId = cfgCart.Id;
                                cfgWorkStationCurrentCart.DockedTime = DateTime.Now;

                                cfgCart.CartStatus = CartStatus.ArrivedAtWorkStation;
                            }

                            dbContext.SaveChanges();
                        }
                    }
                }
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 发送生产线边配送任务
        /// </summary>
        /// <returns></returns>
        private bool SendProductAreaDistributeTask()
        {
            bool isSuccess = false;

            try
            {
                ExeConfigurationFileMap map = new ExeConfigurationFileMap {
                    ExeConfigFilename = @"服务控制台.exe.Config"
                };
                Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
                string        StartMaterialMarketDistributeFlag = configuration.AppSettings.Settings["StartMaterialMarketDistribute"].Value;

                using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                {
                    //获取未响应的配送任务
                    List <DST_DistributeTask> distributeTasks = dbContext.DST_DistributeTasks.
                                                                Where(t => !t.isResponse &&
                                                                      (t.DistributeReqTypes == DistributeReqTypes.ProductCartSwitch ||
                                                                       t.DistributeReqTypes == DistributeReqTypes.ProductNullCartBack ||
                                                                       t.DistributeReqTypes == DistributeReqTypes.MaterialMarketDistribute ||
                                                                       t.DistributeReqTypes == DistributeReqTypes.ProductOutToIn ||
                                                                       t.DistributeReqTypes == DistributeReqTypes.ProductInToOut
                                                                      ) && t.sendErrorCount < 5).
                                                                OrderBy(t => t.reqTime).ToList();

                    //List<DST_DistributeTask> distributeTasks = new List<DST_DistributeTask>();

                    if (distributeTasks.Count == 0)
                    {
                        return(false);
                    }

                    //已经设置成运输开始的寻车任务ID集合
                    //List<long> listNeedBlinkFndTask = new List<long>();

                    //发送信息
                    string sendInfo = "";
                    //AGV服务地址
                    string sURL = ptlToAgvServiceUrl + "/genAgvSchedulingTask";
                    //HTTP响应结果
                    string result = "";

                    foreach (DST_DistributeTask distributeTask in distributeTasks)
                    {
                        if (StartMaterialMarketDistributeFlag.Equals("no"))
                        {
                            if (distributeTask.DistributeReqTypes == DistributeReqTypes.MaterialMarketDistribute)
                            {
                                distributeTask.sendErrorCount = 5;
                                continue;
                            }
                        }

                        if (distributeTask.DistributeReqTypes == DistributeReqTypes.MaterialMarketDistribute)
                        {
                            Thread.Sleep(500);
                        }

                        //绑定配送任务
                        DST_DistributeTaskDto distributeTaskDto = new DST_DistributeTaskDto();
                        distributeTaskDto.reqCode          = distributeTask.reqCode;
                        distributeTaskDto.reqTime          = distributeTask.reqTime.ToString("yyyy-MM-dd HH:mm:ss");
                        distributeTaskDto.clientCode       = distributeTask.clientCode;
                        distributeTaskDto.tokenCode        = distributeTask.tokenCode;
                        distributeTaskDto.taskTyp          = distributeTask.taskTyp;
                        distributeTaskDto.userCallCode     = distributeTask.userCallCode;
                        distributeTaskDto.userCallCodePath = new List <string>();
                        distributeTaskDto.userCallCodePath.AddRange(new string[] { distributeTask.startPosition, distributeTask.endPosition });
                        distributeTaskDto.podCode   = distributeTask.podCode;
                        distributeTaskDto.robotCode = distributeTask.robotCode;
                        distributeTaskDto.taskCode  = distributeTask.taskCode;
                        distributeTaskDto.data      = distributeTask.data;

                        //发送信息
                        sendInfo = JsonConvert.SerializeObject(distributeTaskDto);
                        //发送HTTP请求,并返回响应结果
                        result = HttpService.HttpPost(sURL, sendInfo);

                        if (!string.IsNullOrEmpty(result))
                        {
                            //实例化HTTP响应结果
                            DST_DistributeTaskResultDto distributeTaskResultDto = JsonConvert.DeserializeObject <DST_DistributeTaskResultDto>(result);
                            if (distributeTaskResultDto != null)
                            {
                                //新增配送任务结果
                                DST_DistributeTaskResult distributeTaskResult = new DST_DistributeTaskResult();
                                distributeTaskResult.code        = distributeTaskResultDto.code;
                                distributeTaskResult.message     = distributeTaskResultDto.message;
                                distributeTaskResult.reqCode     = distributeTaskResultDto.reqCode;
                                distributeTaskResult.data        = distributeTaskResultDto.data;
                                distributeTaskResult.receiveTime = DateTime.Now;

                                dbContext.DST_DistributeTaskResults.Add(distributeTaskResult);

                                //更新配送任务响应值
                                if (distributeTaskResultDto.code.Equals("0"))
                                {
                                    distributeTask.isResponse = true;

                                    //if (distributeTask.DistributeReqTypes == DistributeReqTypes.MaterialMarketDistribute)
                                    //{
                                    //    string sWorkStationCode = distributeTask.startPosition;
                                    //    //string sWorkStationCode = distributeTask.endPosition.Split('-')[0];
                                    //    FND_Task fndTask = dbContext.FND_Tasks.Where(t => t.CFG_WorkStation.Code.Equals(sWorkStationCode)
                                    //        && (t.FindingStatus == FindingStatus.New || t.FindingStatus == FindingStatus.NeedDisplay || t.FindingStatus == FindingStatus.Displaying)
                                    //        && (t.CFG_Cart.CartStatus == CartStatus.NeedToWorkStation || t.CFG_Cart.CartStatus == CartStatus.WaitingToWorkStation)
                                    //        && !listNeedBlinkFndTask.Contains(t.Id)).
                                    //        OrderBy(t => t.BatchCode).ThenByDescending(t => t.FindingStatus).FirstOrDefault();
                                    //    if (fndTask != null)
                                    //    {
                                    //        if (fndTask.FindingStatus == FindingStatus.New)
                                    //        {
                                    //            fndTask.CFG_EmployeeId = 1;
                                    //            fndTask.DisplayTime = DateTime.Now;

                                    //            fndTask.CFG_Cart.CartStatus = CartStatus.WaitingToWorkStation;
                                    //        }
                                    //        fndTask.FindingStatus = FindingStatus.NeedBlink;
                                    //        fndTask.CFG_Cart.CartStatus = CartStatus.InCarriageToWorkStation;

                                    //        listNeedBlinkFndTask.Add(fndTask.Id);
                                    //    }
                                    //}
                                    if (distributeTask.DistributeReqTypes == DistributeReqTypes.ProductCartSwitch ||
                                        distributeTask.DistributeReqTypes == DistributeReqTypes.ProductNullCartBack ||
                                        distributeTask.DistributeReqTypes == DistributeReqTypes.ProductOutToIn ||
                                        distributeTask.DistributeReqTypes == DistributeReqTypes.ProductInToOut)
                                    {
                                        string[] arrStartPosition = distributeTask.startPosition.Split('-');
                                        string   sWorkStationCode = arrStartPosition[0];
                                        int      nPosition        = Convert.ToInt32(arrStartPosition[1]);

                                        //解除线边停靠
                                        CFG_WorkStationCurrentCart cfgWorkStationCurrentCart = dbContext.CFG_WorkStationCurrentCarts
                                                                                               .FirstOrDefault(wscc => wscc.CFG_WorkStation.Code.Equals(sWorkStationCode) && wscc.Position == nPosition);
                                        if (cfgWorkStationCurrentCart != null)
                                        {
                                            if (distributeTask.DistributeReqTypes == DistributeReqTypes.ProductNullCartBack)
                                            {
                                                //清空小车上的物料
                                                CFG_Cart cfgCart = cfgWorkStationCurrentCart.CFG_Cart;
                                                if (cfgCart != null)
                                                {
                                                    List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = cfgCart.CFG_CartCurrentMaterials.Where(t => t.AST_CartTaskItemId != null).ToList();
                                                    foreach (CFG_CartCurrentMaterial cfgCartCurrentMaterial in cfgCartCurrentMaterials)
                                                    {
                                                        cfgCartCurrentMaterial.AST_CartTaskItemId = null;
                                                        cfgCartCurrentMaterial.ProjectCode        = null;
                                                        cfgCartCurrentMaterial.WbsId              = null;
                                                        cfgCartCurrentMaterial.ProjectStep        = null;
                                                        cfgCartCurrentMaterial.CFG_WorkStationId  = null;
                                                        cfgCartCurrentMaterial.BatchCode          = null;
                                                        cfgCartCurrentMaterial.CFG_ChannelId      = null;
                                                        cfgCartCurrentMaterial.CFG_PalletId       = null;
                                                        cfgCartCurrentMaterial.BoxCode            = null;
                                                        cfgCartCurrentMaterial.FromPalletPosition = null;
                                                        cfgCartCurrentMaterial.MaterialCode       = null;
                                                        cfgCartCurrentMaterial.MaterialName       = null;
                                                        cfgCartCurrentMaterial.MaterialBarcode    = null;
                                                        cfgCartCurrentMaterial.Quantity           = null;
                                                        cfgCartCurrentMaterial.AssortedTime       = null;
                                                        cfgCartCurrentMaterial.CFG_EmployeeId     = null;
                                                        if (cfgCartCurrentMaterial.Usability != CartPositionUsability.DisableByOffLineDevice)
                                                        {
                                                            cfgCartCurrentMaterial.Usability = CartPositionUsability.Enable;
                                                        }
                                                    }
                                                }
                                            }

                                            //解除线边位置停靠
                                            cfgWorkStationCurrentCart.CFG_CartId = null;
                                            cfgWorkStationCurrentCart.DockedTime = null;
                                        }
                                    }
                                }
                                else
                                {
                                    distributeTask.sendErrorCount = distributeTask.sendErrorCount + 1;
                                }
                            }
                        }
                    }

                    //更新数据库
                    isSuccess = dbContext.SaveChanges() > 0 ? true : false;
                }
            }
            catch (Exception)
            {
                isSuccess = false;
            }
            return(isSuccess);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 按发布器表示短拣。
        /// </summary>
        void ptl900UPublisher_Pressed(object sender, Ptl900UPressedEventArgs e)
        {
            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;

                        KeyValuePair <Display900UItem, ushort> display900UitemAndResult = e.ResultByItem.First();

                        asmTaskItem.AssembledQuantity = display900UitemAndResult.Value;
                        asmTaskItem.AssembledTime     = DateTime.Now;
                        asmTaskItem.AssembleStatus    = AssembleStatus.Finished;

                        if (asmAssembleIndicationItem.AssembledQuantity == null)
                        {
                            asmAssembleIndicationItem.AssembledQuantity = 0;
                        }
                        asmAssembleIndicationItem.AssembledQuantity += display900UitemAndResult.Value - display900UitemAndResult.Key.Count;
                        asmAssembleIndicationItem.AssembledTime      = DateTime.Now;

                        if (otherAsmTaskItems.All(ti => ti.AssembleStatus == AssembleStatus.Finished))
                        {
                            asmAssembleIndicationItem.AssembleStatus = AssembleStatus.Finished;
                        }

                        dbContext.SaveChanges();

                        CartPtl cartPtl          = CartPtlHost.Instance.GetCartPtl(asmTaskItem.CFG_CartId);
                        Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher();
                        Ptl900U ptl900U          = cartPtl.GetPtl900UByPosition(asmTaskItem.CartPosition);
                        Ptl900U ptl900ULight     = cartPtl.GetPtl900ULight();

                        ptl900U.Pressed -= this.ptl900U_Pressed;
                        ptl900U.Clear(true);

                        ptl900UPublisher.Pressed -= this.ptl900UPublisher_Pressed;

                        ptl900ULight.Clear();

                        this.CurrentAsmTaskItemId = null;

                        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);
                    }

                    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.ptl900UPublisher_Pressed", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine
                               + message + Environment.NewLine
                               + Environment.NewLine);

                    Thread.Sleep(1000);
                }
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 停靠小车到分拣口。
        /// </summary>
        /// <param name="cfgChannelId">分拣口的主键。</param>
        /// <param name="position">车位。</param>
        /// <param name="cfgCartId">待停靠小车的主键。</param>
        /// <exception cref="System.ArgumentException">position 车位上的小车还未解除绑定。</exception>
        public void Dock(int cfgChannelId, int position, int cfgCartId)
        {
            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                CFG_Channel cfgChannel = dbContext.CFG_Channels
                                         .First(c => c.Id == cfgChannelId);
                CFG_Cart cfgCart = dbContext.CFG_Carts
                                   .First(c => c.Id == cfgCartId);
                CFG_ChannelCurrentCart cfgChannelCurrentCart = dbContext.CFG_ChannelCurrentCarts
                                                               .FirstOrDefault(ccc => ccc.CFG_ChannelId == cfgChannelId && ccc.Position == position);
                if (cfgCart.CartStatus != CartStatus.Free)
                {
                    throw new ArgumentException("小车 " + cfgCart.Code + " 未释放:" + cfgCart.CartStatus + "。");
                }
                if (!cfgCart.OnLine)
                {
                    throw new ArgumentException("小车 " + cfgCart.Code + " 不在线。");
                }
                foreach (CFG_CartPtlDevice cfgCartPtlDevice in cfgCart.CFG_CartPtlDevices)
                {
                    if (!cfgCartPtlDevice.OnLine)
                    {
                        throw new ArgumentException("小车上的 " + cfgCartPtlDevice.DeviceAddress + " 号标签不在线。");
                    }
                }
                if (cfgChannelCurrentCart == null)
                {
                    throw new ArgumentException("车位 " + position + " 不存在。", "position");
                }
                if (cfgChannelCurrentCart.CFG_CartId != null && cfgChannelCurrentCart.CFG_CartId != cfgCartId)
                {
                    throw new ArgumentException("车位 " + position + " 上的小车还未解除绑定。", "position");
                }

                if (cfgChannelCurrentCart.CFG_CartId == null)
                {
                    CFG_ChannelCurrentCart dockedCfgChannelCurrentCart = dbContext.CFG_ChannelCurrentCarts
                                                                         .FirstOrDefault(ccc => ccc.CFG_CartId == cfgCartId);
                    if (dockedCfgChannelCurrentCart != null)
                    {
                        throw new ArgumentException("小车 " + dockedCfgChannelCurrentCart.CFG_Cart.Code + " 已停靠在 " + dockedCfgChannelCurrentCart.CFG_Channel.Name + " 车位 " + dockedCfgChannelCurrentCart.Position + "。", "cfgCartId");
                    }

                    //停靠即开始播种
                    cfgCart.CartStatus = CartStatus.WaitingAssorting;

                    cfgChannelCurrentCart.CFG_CartId = cfgCart.Id;
                    cfgChannelCurrentCart.DockedTime = DateTime.Now;

                    //清空小车上的物料
                    List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = cfgCart.CFG_CartCurrentMaterials
                                                                             .ToList();
                    foreach (CFG_CartCurrentMaterial cfgCartCurrentMaterial in cfgCartCurrentMaterials)
                    {
                        cfgCartCurrentMaterial.AST_CartTaskItemId = null;
                        cfgCartCurrentMaterial.ProjectCode        = null;
                        cfgCartCurrentMaterial.WbsId              = null;
                        cfgCartCurrentMaterial.ProjectStep        = null;
                        cfgCartCurrentMaterial.CFG_WorkStationId  = null;
                        cfgCartCurrentMaterial.BatchCode          = null;
                        cfgCartCurrentMaterial.CFG_ChannelId      = null;
                        cfgCartCurrentMaterial.CFG_PalletId       = null;
                        cfgCartCurrentMaterial.BoxCode            = null;
                        cfgCartCurrentMaterial.FromPalletPosition = null;
                        cfgCartCurrentMaterial.MaterialCode       = null;
                        cfgCartCurrentMaterial.MaterialName       = null;
                        cfgCartCurrentMaterial.MaterialBarcode    = null;
                        cfgCartCurrentMaterial.Quantity           = null;
                        cfgCartCurrentMaterial.AssortedTime       = null;
                        cfgCartCurrentMaterial.CFG_EmployeeId     = null;
                        if (cfgCartCurrentMaterial.Usability != CartPositionUsability.DisableByOffLineDevice)
                        {
                            cfgCartCurrentMaterial.Usability = CartPositionUsability.Enable;
                        }
                    }

                    dbContext.SaveChanges();

                    //设备控制
                    CartPtl cartPtl          = CartPtlHost.Instance.GetCartPtl(cfgCart.Id);
                    Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher();

                    Display900UItem publisherDisplay900UItem = new Display900UItem();
                    publisherDisplay900UItem.Name        = "停靠成功";
                    publisherDisplay900UItem.Description = cfgChannel.Name;
                    publisherDisplay900UItem.Count       = (ushort)position;
                    publisherDisplay900UItem.Unit        = "位";

                    ptl900UPublisher.Clear(true);
                    ptl900UPublisher.Lock();
                    ptl900UPublisher.Display(publisherDisplay900UItem, LightColor.Off);

                    Logger.Log(this.GetType().Name, DateTime.Now.ToString("HH:mm:ss") + "停靠 " + cfgCart.Name + " 到 " + cfgChannel.Name + " 车位 " + position + Environment.NewLine);
                }
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 从分拣口解除小车绑定。
        /// </summary>
        /// <param name="cfgChannelId">分拣口的主键。</param>
        /// <param name="cfgCartId">待移出小车的主键。</param>
        /// <exception cref="System.ArgumentException">position 车位上的小车还未作业完成。</exception>
        public void UnDock(int cfgChannelId, int cfgCartId)
        {
            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                CFG_ChannelCurrentCart cfgChannelCurrentCart = dbContext.CFG_ChannelCurrentCarts
                                                               .FirstOrDefault(ccc => ccc.CFG_ChannelId == cfgChannelId && ccc.CFG_CartId == cfgCartId);
                if (cfgChannelCurrentCart != null && cfgChannelCurrentCart.CFG_CartId != null)
                {
                    CFG_Cart cfgCart = cfgChannelCurrentCart.CFG_Cart;
                    if (cfgCart.CartStatus == CartStatus.Assorting)
                    {
                        throw new ArgumentException("车位 " + cfgChannelCurrentCart.Position + " 上的小车 " + cfgCart.Code + " 还未作业完成。", "position");
                    }

                    //移出
                    cfgChannelCurrentCart.CFG_CartId = null;
                    cfgChannelCurrentCart.DockedTime = null;

                    //准备基础数据
                    AST_PalletTask  astPalletTask  = null;
                    CFG_WorkStation cfgWorkStation = null;
                    List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = cfgCart.CFG_CartCurrentMaterials
                                                                             .ToList();
                    CFG_CartCurrentMaterial firstNotEmptyCfgCartCurrentMaterial = cfgCartCurrentMaterials
                                                                                  .FirstOrDefault(ccm => ccm.AST_CartTaskItemId != null);
                    if (firstNotEmptyCfgCartCurrentMaterial != null)
                    {
                        AST_CartTaskItem astCartTask = firstNotEmptyCfgCartCurrentMaterial.AST_CartTaskItem;
                        astPalletTask  = astCartTask.AST_PalletTaskItem.AST_PalletTask;
                        cfgWorkStation = astCartTask.AST_PalletTaskItem.CFG_WorkStation;
                    }

                    dbContext.SaveChanges();

                    //设备控制
                    CartPtl cartPtl          = CartPtlHost.Instance.GetCartPtl(cfgCart.Id);
                    Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher();
                    Ptl900U ptl900ULight     = cartPtl.GetPtl900ULight();

                    ptl900UPublisher.Clear(true);
                    ptl900UPublisher.Unlock();

                    if (astPalletTask != null)
                    {
                        Display900UItem publisherDisplay900UItem = new Display900UItem();
                        publisherDisplay900UItem.Name        = "已分拣完成";
                        publisherDisplay900UItem.Description = string.Format(CultureInfo.InvariantCulture, @"项目:{0}
阶段:{1}
工位:{2}", astPalletTask.ProjectCode, astPalletTask.ProjectStep, cfgWorkStation.Code);
                        publisherDisplay900UItem.Count       = (ushort)cfgCartCurrentMaterials
                                                               .Where(ccm => ccm.Quantity != null)
                                                               .Select(ccm => ccm.Quantity.Value)
                                                               .Sum();
                        publisherDisplay900UItem.Unit = "个";

                        ptl900UPublisher.Lock();
                        ptl900UPublisher.Display(publisherDisplay900UItem, LightColor.Off);
                    }

                    foreach (CFG_CartCurrentMaterial cfgCartCurrentMaterial in cfgCartCurrentMaterials)
                    {
                        Ptl900U ptl900U = cartPtl.GetPtl900UByPosition(cfgCartCurrentMaterial.Position);

                        ptl900U.Clear(true);
                        ptl900U.Unlock();
                    }

                    ptl900ULight.Clear();
                }
            }
        }
Ejemplo n.º 27
0
        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);
                }
            }
        }
Ejemplo n.º 28
0
        void threadStart(object notUsed)
        {
            while (true)
            {
                //加载线程推动新明细,按钮交互推进明细的进度
                if (this.CurrentAsmTaskId != null && this.CurrentAsmTaskItemId == null)
                {
                    try
                    {
                        using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                        {
                            CFG_WorkStation cfgWorkStation = dbContext.CFG_WorkStations
                                                             .First(ws => ws.Id == this.CFG_WorkStationId);
                            ASM_Task asmTask = dbContext.ASM_Tasks
                                               .First(t => t.Id == this.CurrentAsmTaskId.Value);

                            //因为 IndicatingExecutorLoader 加载和 IndicatingExecutor 是不同线程,所以再次核对状态
                            if (asmTask.AssembleStatus == AssembleStatus.Finished)
                            {
                                this.CurrentAsmTaskId = null;

                                continue;
                            }

                            ASM_AssembleIndication asmAssembleIndication = asmTask.ASM_AssembleIndication;
                            ASM_TaskItem           asmTaskItem           = dbContext.ASM_TaskItems
                                                                           .OrderBy(ti => ti.Gzz)
                                                                           .ThenBy(ti => ti.AssembleSequence)
                                                                           .FirstOrDefault(ti => ti.ASM_TaskId == asmTask.Id &&
                                                                                           ti.AssembleStatus != AssembleStatus.Finished);
                            if (asmTaskItem == null)
                            {
                                asmTask.AssembleStatus = AssembleStatus.Finished;
                                asmAssembleIndication.AssembleStatus = asmTask.AssembleStatus;

                                #region 当前装配可以提交

                                List <ASM_AssembleIndicationItem> asmAssembleIndicatonItems = asmAssembleIndication.ASM_AssembleIndicationItems
                                                                                              .ToList();

                                ASM_AssembleResult asmAssembleResult = new ASM_AssembleResult();
                                asmAssembleResult.ASM_AssembleIndicationId = asmAssembleIndication.Id;
                                asmAssembleResult.FactoryCode        = asmAssembleIndication.FactoryCode;
                                asmAssembleResult.ProductionLineCode = asmAssembleIndication.ProductionLineCode;
                                asmAssembleResult.CFG_WorkStationId  = asmAssembleIndication.CFG_WorkStationId;
                                asmAssembleResult.GzzList            = asmAssembleIndication.GzzList;
                                asmAssembleResult.MONumber           = asmAssembleIndication.MONumber;
                                asmAssembleResult.ProductSequence    = asmAssembleIndication.ProductSequence;
                                asmAssembleResult.BeginTime          = asmTask.ASM_TaskItems.OrderBy(ati => ati.AssembledTime).First().AssembledTime.Value;
                                asmAssembleResult.EndTime            = asmTask.ASM_TaskItems.OrderBy(ati => ati.AssembledTime).Last().AssembledTime.Value;

                                dbContext.ASM_AssembleResults.Add(asmAssembleResult);

                                ASM_AssembleResultMessage asmAssembleResultMessage = new ASM_AssembleResultMessage();
                                asmAssembleResultMessage.ASM_AssembleResult = asmAssembleResult;
                                asmAssembleResultMessage.SentSuccessful     = false;

                                dbContext.ASM_AssembleResultMessages.Add(asmAssembleResultMessage);

                                foreach (ASM_AssembleIndicationItem asmAssembleIndicationItem in asmAssembleIndicatonItems)
                                {
                                    List <ASM_TaskItem> asmTaskItems = asmAssembleIndicationItem.ASM_TaskItems
                                                                       .ToList();
                                    ASM_TaskItem lastAsmTaskItem = asmTaskItems.Last();

                                    ASM_AssembleResultItem asmAssembleResultItem = new ASM_AssembleResultItem();
                                    asmAssembleResultItem.ASM_AssembleResult = asmAssembleResult;
                                    asmAssembleResultItem.CFG_CartId         = lastAsmTaskItem.CFG_CartId;
                                    asmAssembleResultItem.CartPosition       = lastAsmTaskItem.CartPosition;
                                    asmAssembleResultItem.Gzz                = asmAssembleIndicationItem.Gzz;
                                    asmAssembleResultItem.MaterialCode       = asmAssembleIndicationItem.MaterialCode;
                                    asmAssembleResultItem.MaterialName       = asmAssembleIndicationItem.MaterialName;
                                    asmAssembleResultItem.AssembleSequence   = asmAssembleIndicationItem.AssembleSequence;
                                    asmAssembleResultItem.ToAssembleQuantity = asmAssembleIndicationItem.ToAssembleQuantity;
                                    asmAssembleResultItem.AssembledQuantity  = asmTaskItems.Sum(ti => ti.AssembledQuantity.Value);
                                    asmAssembleResultItem.PickedTime         = lastAsmTaskItem.AssembledTime.Value;
                                    asmAssembleResultItem.ProjectCode        = asmAssembleIndicationItem.ProjectCode;
                                    asmAssembleResultItem.ProjectStep        = asmAssembleIndicationItem.ProjectStep;

                                    dbContext.ASM_AssembleResultItems.Add(asmAssembleResultItem);
                                }

                                #endregion

                                dbContext.SaveChanges();

                                this.CurrentAsmTaskId = null;

                                Logger.Log(this.GetType().Name + "." + cfgWorkStation.Code, DateTime.Now.ToString("HH:mm:ss") + " 装配任务完成:"
                                           + asmAssembleIndication.ProductSequence + ", "
                                           + asmAssembleIndication.GzzList + Environment.NewLine);
                            }
                            else
                            {
                                ASM_AssembleIndicationItem asmAssembleIndicationItem = asmTaskItem.ASM_AssembleIndicationItem;
                                CFG_Cart cfgCart = asmTaskItem.CFG_Cart;

                                //先更新数据库
                                asmTask.AssembleStatus                   = AssembleStatus.Assembling;
                                asmTaskItem.AssembleStatus               = AssembleStatus.Assembling;
                                asmAssembleIndication.AssembleStatus     = AssembleStatus.Assembling;
                                asmAssembleIndicationItem.AssembleStatus = AssembleStatus.Assembling;
                                cfgCart.CartStatus = CartStatus.Indicating;

                                dbContext.SaveChanges();

                                //再控制设备
                                CartPtl cartPtl          = CartPtlHost.Instance.GetCartPtl(asmTaskItem.CFG_CartId);
                                Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher();
                                Ptl900U ptl900U          = cartPtl.GetPtl900UByPosition(asmTaskItem.CartPosition);
                                Ptl900U ptl900ULight     = cartPtl.GetPtl900ULight();

                                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           = 0;

                                Display900UItem display900UItem = new Display900UItem();
                                display900UItem.Count = (ushort)asmTaskItem.ToAssembleQuantity;

                                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.Pressed += this.ptl900UPublisher_Pressed;
                                ptl900UPublisher.Clear(true);
                                //ptl900UPublisher.Unlock();
                                ptl900UPublisher.Lock();
                                ptl900UPublisher.Display(publisherDisplay900UItem, LightColor.Off, true);

                                ptl900U.Pressed += this.ptl900U_Pressed;
                                ptl900U.Unlock();
                                ptl900U.Display(display900UItem, lightMode, true);

                                ptl900ULight.Clear();
                                ptl900ULight.Display(new Display900UItem(), lightMode, false);

                                this.CurrentAsmTaskItemId = asmTaskItem.Id;

                                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);

                                //如果新底盘抵达,则自动完成之前的
                                this.AutoPressByNewCarArrivedAsync(this.CurrentAsmTaskId.Value, this.CurrentAsmTaskItemId.Value, ptl900U, display900UItem);
                                //如果长时间无法交互,则自动交互
                                this.AutoPressByDeviceErrorAsync(this.CurrentAsmTaskItemId.Value, ptl900U, display900UItem);
                            }
                        }
                    }
                    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.threadStart", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine
                                   + message + Environment.NewLine
                                   + Environment.NewLine);

                        Thread.Sleep(1000);
                    }
                }

                Thread.Sleep(1);
            }
        }