Пример #1
0
        /// <summary>
        /// 堆垛机任务完成处理
        /// </summary>
        private void TaskFinishProcess(StateItem Item)
        {
            object obj = ObjectUtil.GetObject(Item.State);

            if (obj == null)
            {
                return;
            }
            string TaskFinish = obj.ToString();

            if (TaskFinish.Equals("False") || TaskFinish.Equals("0"))
            {
                return;
            }

            int CraneNo = int.Parse(Item.Name.Replace("CranePLC", ""));

            try
            {
                string TaskNo = ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService(Item.Name, "ReadTaskNo")));

                if ((TaskFinish.Equals("True") || TaskFinish.Equals("1")) && TaskNo != "")
                {
                    DataTable dtTask = bll.FillDataTable("WCS.SelectWCSTask", new DataParameter[] { new DataParameter("{0}", string.Format("TASKID='{0}' and ASRSID='{1}'", TaskNo, CraneNo)) });
                    if (dtTask.Rows.Count > 0)
                    {
                        DataRow dr         = dtTask.Rows[0];
                        string  TaskType   = dtTask.Rows[0]["TASKTYPE"].ToString();
                        string  PalletCode = dtTask.Rows[0]["PALLETID"].ToString();
                        if (TaskType == "IB")//入库
                        {
                            //更新入库完成
                            bll.ExecNonQueryTran("WCS.SpTaskFinished", new DataParameter[] { new DataParameter("VTaskNo", TaskNo) });
                            sbyte[] taskNo = new sbyte[20];
                            ConvertStringChar.stringToBytes("", 20).CopyTo(taskNo, 0);
                            WriteToService(Item.Name, "GetRequest", false);
                            WriteToService(Item.Name, "PutRequest", false);
                            WriteToService(Item.Name, "ClearTaskNo", taskNo);
                            WriteToService(Item.Name, "TaskFinish", false);
                            Logger.Info("第" + CraneNo + "堆垛机入库任务:" + TaskNo + "托盘编号:" + PalletCode + "任务完成!");
                        }
                        else if (TaskType == "OB")//出库
                        {
                            //更新任务状态
                            bll.ExecNonQuery("WCS.UpdateWCSTaskState", new DataParameter[] { new DataParameter("{0}", 2), new DataParameter("{1}", TaskNo) });

                            //更新堆垛机PLC
                            sbyte[] taskNo = new sbyte[20];
                            ConvertStringChar.stringToBytes("", 20).CopyTo(taskNo, 0);

                            WriteToService(Item.Name, "GetRequest", false);
                            WriteToService(Item.Name, "PutRequest", false);
                            WriteToService(Item.Name, "ClearTaskNo", taskNo);
                            WriteToService(Item.Name, "TaskFinish", false);
                            Logger.Info("第" + CraneNo + "堆垛机出库任务:" + TaskNo + "托盘编号:" + PalletCode + "堆垛机任务完成!");
                            //下载任务到输送线。
                            int CarItem = 104 + (CraneNo - 1) * 4;

                            sbyte[]  staskNo = new sbyte[26];
                            string[] LedMsgs = dtTask.Rows[0]["LEDNO"].ToString().Split(',');
                            ConvertStringChar.stringToBytes(TaskNo, 10).CopyTo(staskNo, 0);
                            ConvertStringChar.stringToBytes(LedMsgs[0], 8).CopyTo(staskNo, 10);
                            ConvertStringChar.stringToBytes(LedMsgs[1], 8).CopyTo(staskNo, 18);
                            WriteToService("CarPLC", CarItem + "_WriteTaskNo", staskNo);

                            if (WriteToService("CarPLC", CarItem + "_WriteFinished", 1))
                            {
                                bll.ExecNonQuery("WCS.UpdateWCSTaskState", new DataParameter[] { new DataParameter("{0}", 3), new DataParameter("{1}", TaskNo) });
                                Logger.Info("出库任务:" + TaskNo + "托盘编号:" + PalletCode + "任务下达" + CarItem + "输送线!");
                            }
                        }
                        else
                        {
                            //更新入库完成
                            bll.ExecNonQueryTran("WCS.SpTaskFinished", new DataParameter[] { new DataParameter("VTaskNo", TaskNo) });
                            sbyte[] taskNo = new sbyte[20];
                            WriteToService(Item.Name, "GetRequest", false);
                            WriteToService(Item.Name, "PutRequest", false);
                            ConvertStringChar.stringToBytes("", 20).CopyTo(taskNo, 0);
                            WriteToService(Item.Name, "ClearTaskNo", taskNo);
                            WriteToService(Item.Name, "TaskFinish", false);
                            Logger.Info("第" + CraneNo + "堆垛机任务:" + TaskNo + "托盘编号:" + PalletCode + "任务完成!");
                        }
                    }
                    else
                    {
                        WriteToService(Item.Name, "TaskFinish", false);
                        Logger.Error("CraneProcess第" + CraneNo + "堆垛机任务号:" + TaskNo + "在任务表中没有找到,请查询任务!");
                    }
                }
                else
                {
                    Logger.Error("CraneProcess第" + CraneNo + "堆垛机任务号为空!");
                }
            }
            catch (Exception ex)
            {
                Logger.Error("CraneProcess 第" + CraneNo + "堆垛机Finish:" + ex.Message);
            }
        }
Пример #2
0
 protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
 {
     try
     {
         object obj = ObjectUtil.GetObject(stateItem.State);
         if (obj == null)
         {
             return;
         }
         if (obj.ToString() == "0")
         {
             return;
         }
         string ItemNo     = stateItem.ItemName.Substring(0, 3);
         string PalletCode = ConvertStringChar.BytesToString((byte[])WriteToService(stateItem.Name, ItemNo + "_PalletCode"));
         string RoadNo     = GetRoadNo(ItemNo);
         if (PalletCode.Length > 0)
         {
             BLL.BLLBase bll    = new BLL.BLLBase();
             DataTable   dtTask = bll.FillDataTable("WCS.SelectWMSTask", new DataParameter[] { new DataParameter("{0}", string.Format("TASKSTATUS in ('0','3') AND TASKTYPE='IB' AND PALLETID='{1}' ", RoadNo, PalletCode)) });
             if (dtTask.Rows.Count > 0)
             {
                 string ASRSID = dtTask.Rows[0]["ASRSID"].ToString();
                 if (ASRSID == RoadNo)
                 {
                     string   TaskNo     = dtTask.Rows[0]["TASKID"].ToString();
                     string   TaskStatus = dtTask.Rows[0]["TASKSTATUS"].ToString();
                     sbyte[]  staskNo    = new sbyte[26];
                     string[] LedMsgs    = dtTask.Rows[0]["LEDNO"].ToString().Split(',');
                     ConvertStringChar.stringToBytes(TaskNo, 10).CopyTo(staskNo, 0);
                     ConvertStringChar.stringToBytes(LedMsgs[0], 8).CopyTo(staskNo, 10);
                     ConvertStringChar.stringToBytes(LedMsgs[1], 8).CopyTo(staskNo, 18);
                     WriteToService(stateItem.Name, ItemNo + "_WriteTaskNo", staskNo);
                     if (WriteToService(stateItem.Name, ItemNo + "_WriteFinished", 1))
                     {
                         //插入WCS_Task
                         if (TaskStatus == "0")
                         {
                             bll.ExecNonQueryTran("WCS.SPReciveWmsTask", new DataParameter[] { new DataParameter("VTASKNO", TaskNo) });
                         }
                         Logger.Info("第" + RoadNo.ToString() + "排托盘编号:" + PalletCode + "开始入库");
                     }
                 }
                 else
                 {
                     if (WriteToService(stateItem.Name, ItemNo + "_WriteFinished", 2))
                     {
                         // Logger.Error("第" + RoadNo.ToString() + "排托盘编号:" + PalletCode + "巷道不符!");
                     }
                 }
             }
             else
             {
                 if (WriteToService(stateItem.Name, ItemNo + "_WriteFinished", 6))
                 {
                 }
             }
         }
     }
     catch (Exception e)
     {
         Logger.Error("CarProcess:" + e.Message);
     }
 }