Пример #1
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            try
            {
                Dictionary<string, string> msg = (Dictionary<string, string>)stateItem.State;
                object o = WriteToService("StockPLC", "PLCFree");
                switch (stateItem.ItemName)
                {

                    case "ARQ": //入库申请
                        if (o.ToString() == "1")
                        {
                            //入库写入
                            BLL.BLLBase bll = new BLL.BLLBase();
                            DataTable dtTask = bll.FillDataTable("WCS.SelectTask", new DataParameter[] { new DataParameter("@TaskNo", msg["TaskNo"]) });

                            int TaskType = int.Parse(dtTask.Rows[0]["TaskType"].ToString());
                            string TaskNo = msg["TaskNo"];
                            string CellCode = dtTask.Rows[0]["CellCode"].ToString();

                            //写入任务号
                            WriteToService("StockPLC", "TaskNo1", int.Parse(TaskNo.Substring(0, 4)));
                            WriteToService("StockPLC", "TaskNo2", int.Parse(TaskNo.Substring(4, 4)));
                            WriteToService("StockPLC", "TaskNo3", int.Parse(TaskNo.Substring(8)));
                            //写入起始位,结束位
                            if (TaskType == 3)
                            {
                                WriteToService("StockPLC", "FromStation1", 0);
                                WriteToService("StockPLC", "FromStation2", 0);
                                WriteToService("StockPLC", "FromStation3", 0);
                            }
                            else
                            {
                                WriteToService("StockPLC", "FromStation1", int.Parse(CellCode.Substring(0, 3)));
                                WriteToService("StockPLC", "FromStation2", int.Parse(CellCode.Substring(0, 3)));
                                WriteToService("StockPLC", "FromStation3", 68);
                            }

                            WriteToService("StockPLC", "ToStation1", int.Parse(CellCode.Substring(0, 3)));
                            WriteToService("StockPLC", "ToStation2", int.Parse(CellCode.Substring(3, 3)));
                            WriteToService("StockPLC", "ToStation3", int.Parse(CellCode.Substring(6)));
                            //写入标识
                            WriteToService("StockPLC", "WriteFinished", 1);

                            WriteToService("PDATcp", "msg", "1");
                        }
                        else
                        {
                            WriteToService("PDATcp", "msg", "0");
                        }
                        break;

                }
            }
            catch (Exception ex)
            {

            }
        }
Пример #2
0
 public void Process(StateItem item)
 {
     lock (queue)
     {
         queue.Enqueue(item);
     }
     resetEvent.Set();
 }
Пример #3
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            //object obj = ObjectUtil.GetObject(stateItem.State);
            //if (obj == null)
            //    return;

            switch (stateItem.ItemName)
            {
                case "CraneTaskFinished":
                    object obj = ObjectUtil.GetObject(stateItem.State);
                    if (obj.ToString() == "50")
                    {

                        string TaskNo = Util.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(stateItem.Name, "CraneTaskNo")));
                        //存储过程处理
                        Logger.Info(stateItem.ItemName + "完成标志,任务号:" + TaskNo);
                        //更新任务状态
                        DataParameter[] param = new DataParameter[] { new DataParameter("@TaskNo", TaskNo)};
                        bll.ExecNonQueryTran("WCS.Sp_TaskProcess", param);

                        WriteToService(stateItem.Name, "ReplyFinished", 49);
                    }
                    break;
                case "Run":
                    blRun = (int)stateItem.State == 1;
                    break;
                default:
                    break;
            }
            if (blRun)
            {
                tmWorkTimer.Start();
                Logger.Info("堆垛机联机");
            }
            else
            {
                tmWorkTimer.Stop();
                Logger.Info("堆垛机脱机");
            }

            return;
        }
Пример #4
0
        public void DispatchState(StateItem item)
        {
            try
            {
                if (item == null)
                {
                    throw new Exception("DispatchState item = null.");
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.TargetSite + "|" + e.Message + "|" + e.StackTrace);
                return;
            }

            lock (queue)
            {
                queue.Enqueue(item);
            }
            resetEvent.Set();
        }
Пример #5
0
 public void DispatchState(StateItem item)
 {
     System.Diagnostics.Debug.WriteLine(string.Format("[����״̬] [{0} {1} {2}]", item.Name, item.ItemName, item.State));
 }
Пример #6
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            //object obj = ObjectUtil.GetObject(stateItem.State);
            //if (obj == null)
            //    return;

            switch (stateItem.ItemName)
            {
                case "CraneTaskFinished":
                    try
                    {
                        object obj = ObjectUtil.GetObject(stateItem.State);
                        string TaskFinish = obj.ToString();
                        if (TaskFinish.Equals("True") || TaskFinish.Equals("1"))
                        {
                            string TaskNo = Util.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(stateItem.Name, "CraneTaskNo")));

                            if (TaskNo.Length <= 0)
                                return;
                            sbyte[] taskNo = new sbyte[10];
                            object[] objRow = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService("CranePLC1", "CraneAlarmCode"));
                            int Column = int.Parse(objRow[2].ToString());
                            int Height = int.Parse(objRow[3].ToString());
                            int Row = int.Parse(objRow[4].ToString());

                            //更新任务状态
                            DataParameter[] param = new DataParameter[] { new DataParameter("@TaskNo", TaskNo) };
                            //bll.ExecNonQueryTran("WCS.Sp_TaskProcess", param);
                            DataTable dtXml = bll.FillDataTable("WCS.Sp_TaskProcess", param);

                            //判断任务号是什么类型,如果是盘点另外处理
                            param = new DataParameter[] { new DataParameter("{0}", string.Format("WCS_Task.TaskNo='{0}'", TaskNo)) };
                            DataTable dt = bll.FillDataTable("WCS.SelectTask", param);

                            string Flag = "BatchInStock";
                            string TaskType = "";
                            string CellCode = "";
                            string strState = "";
                            if (dt.Rows.Count > 0)
                            {
                                TaskType = dt.Rows[0]["TaskType"].ToString();
                                CellCode = dt.Rows[0]["CellCode"].ToString();
                                strState = dt.Rows[0]["State"].ToString();
                                if (TaskType == "12")
                                    Flag = "BatchOutStock";
                                else if (TaskType == "14")
                                    Flag = "BatchCheckStock";
                            }
                            if (dtXml.Rows.Count > 0)
                            {
                                string BillNo = dtXml.Rows[0][0].ToString();
                                if (BillNo.Trim().Length > 0)
                                {

                                    string xml = Util.ConvertObj.ConvertDataTableToXmlOperation(dtXml, Flag);
                                    WriteToService("ERP", "ACK", xml);
                                    Logger.Info("单号" + dtXml.Rows[0][0].ToString() + "已完成,开始上报ERP系统");
                                }
                            }

                            string[] str = new string[3];
                            str[0] = "6";
                            string strValue = "";
                            if (TaskType == "14" && strState == "4")
                            {
                                while ((strValue = FormDialog.ShowDialog(str, dt)) != "")
                                {
                                    if (strValue != "1")
                                    {
                                        //更新货位信息
                                        bll.ExecNonQuery("WCS.UpdateErrCell", new DataParameter[] { new DataParameter("@CellCode", CellCode) });
                                    }
                                    bll.ExecNonQuery("WCS.UpdateTaskStateByTaskNo", new DataParameter[] { new DataParameter("@State", 5), new DataParameter("@TaskNo", TaskNo) });

                                    //线程继续。
                                    break;
                                }
                            }
                            //清除堆垛机任务号

                            if (Column == 1 && Height == 1)
                            {
                                int[] cellAddr = new int[9];
                                cellAddr[0] = 0;
                                cellAddr[1] = 0;
                                cellAddr[2] = 0;

                                cellAddr[3] = 1;
                                cellAddr[4] = 1;
                                cellAddr[5] = Row * 2 - 1;
                                cellAddr[6] = 1;
                                cellAddr[7] = 2;
                                cellAddr[8] = Row * 2 - 1;
                                Util.ConvertStringChar.stringToBytes("", 10).CopyTo(taskNo, 0);
                                Context.ProcessDispatcher.WriteToService("CranePLC1", "TaskAddress", cellAddr);
                                Context.ProcessDispatcher.WriteToService("CranePLC1", "TaskNo", taskNo);
                                Context.ProcessDispatcher.WriteToService("CranePLC1", "WriteFinished", 2);
                                Logger.Info(stateItem.ItemName + "完成标志,任务号:" + TaskNo);
                                return;
                            }
                            else
                            {
                                Util.ConvertStringChar.stringToBytes("", 10).CopyTo(taskNo, 0);
                                WriteToService(stateItem.Name, "TaskNo", taskNo);
                                Logger.Info(stateItem.ItemName + "完成标志,任务号:" + TaskNo);
                            }

                        }
                    }
                    catch (Exception ex1)
                    {
                        Logger.Info("CraneProcess中CraneTaskFinished出错:" + ex1.Message);
                    }
                    break;
                case "Run":
                    blRun = (int)stateItem.State == 1;
                    if (blRun)
                    {
                        tmWorkTimer.Start();
                        Logger.Info("堆垛机联机");
                    }
                    else
                    {
                        tmWorkTimer.Stop();
                        Logger.Info("堆垛机脱机");
                    }
                    break;
                default:
                    break;
            }

            return;
        }
Пример #7
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            try
            {
                object obj = ObjectUtil.GetObject(stateItem.State);
                if (obj == null)
                    return;
                if (obj.ToString() == "48" || obj.ToString() == "0")
                    return;

                string carNo = stateItem.ItemName.Substring(0, 2);

                Logger.Info("小车" + carNo + "接到入库确认请求");
                string CraneNo = "01";
                if (carNo == "02")
                    CraneNo = "02";

                BLL.BLLBase bll = new BLL.BLLBase();
                //判断堆垛机状态是否可用

                //查找有无请求状态(state='1')的任务,如没有则认为是空托盘回库
                string filter = string.Format("WCS_Task.State='1' and WCS_TASK.TaskType='11' and WCS_TASK.CarNo='{0}'", carNo);
                DataParameter[] parameter = new DataParameter[] { new DataParameter("{0}", filter) };
                DataTable dt = bll.FillDataTable("WCS.SelectTask", parameter);

                int rows = 0;
                if (dt.Rows.Count > 0)
                {
                    rows = bll.ExecNonQuery("WCS.UpdateTaskState", new DataParameter[] { new DataParameter("@State", 2), new DataParameter("@CarNo", carNo) });
                    WriteToService("CarPLC", carNo + "_CarReply", 49);
                    Logger.Info("小车:" + carNo + "收到入库请求,更新任务状态,影响行数" + rows);
                }
                else
                {
                    //判断有无正在执行的任务,如有不做处理,如没有则产生一笔空盘回库任务
                    filter = string.Format("WCS_Task.State='3' and WCS_TASK.TaskType='11' and WCS_TASK.CarNo='{0}'", carNo);
                    parameter = new DataParameter[] { new DataParameter("{0}", filter) };
                    DataTable dting = bll.FillDataTable("WCS.SelectTask", parameter);

                    if (dting.Rows.Count > 0)
                    {
                        WriteToService("CarPLC", carNo + "_CarReply", 50);
                        return;
                    }
                    //有无盘点回库任务
                    filter = string.Format("WCS_Task.State='4' and WCS_TASK.TaskType='14' and WCS_TASK.CarNo='{0}'", carNo);
                    parameter = new DataParameter[] { new DataParameter("{0}", filter) };
                    dting = bll.FillDataTable("WCS.SelectTask", parameter);
                    if (dting.Rows.Count > 0)
                    {
                        //盘点任务改变状态为5,堆垛机调度回库
                        string TaskNo = dting.Rows[0]["TaskNo"].ToString();
                        bll.ExecNonQuery("WCS.UpdateTaskStateByTaskNo", new DataParameter[] { new DataParameter("@State", 5), new DataParameter("@TaskNo", TaskNo) });

                        WriteToService("CarPLC", carNo + "_CarReply", 49);
                        return;
                    }

                    //查找锁定货位,且产品是托盘的货位,如有判断为实托盘出库后,托盘回库
                    string ProductCode = "00" + CraneNo;
                    parameter = new DataParameter[]
                    {
                        new DataParameter("{0}", string.Format("CMD_Cell.ProductCode='{0}' and CMD_Cell.IsActive='1' and CMD_Cell.IsLock='1' and CMD_Cell.ErrorFlag!='1'",ProductCode)),
                        new DataParameter("{1}", carNo)
                    };
                    dt = bll.FillDataTable("CMD.SelectCellByCar", parameter);
                    if (dt.Rows.Count > 0)
                    {
                        //产生一笔空托盘入库任务
                        //锁定货位
                        parameter = new DataParameter[]
                        {
                            new DataParameter("@CarNo", carNo),
                            new DataParameter("@CraneNo", CraneNo),
                            new DataParameter("@CellCode", dt.Rows[0]["CellCode"].ToString())
                        };
                        bll.ExecNonQueryTran("WCS.Sp_RequestPalletInTask", parameter);
                        WriteToService("CarPLC", carNo + "_CarReply", 49);
                        Logger.Info("小车:" + carNo + "接到入库请求,产生一笔托盘回库任务");
                    }
                }
                WriteToService("CarPLC", carNo + "_CarReply", 50);
            }
            catch (Exception e)
            {
                Logger.Error("Dispatching.Process.CarProcess:" + e.Message);
            }
        }
Пример #8
0
 protected abstract void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher);