예제 #1
0
 //执行人工上下料时AGV收到消息的处理方法
 private void ManualOperate()
 {
     if (package.Head == 10003)   //收到消息
     {
         ExecuteOrder.SendAGVCmdEnable         = false;
         MainWindow.agvUIHandle.AGV_POS_ACTION = "AGV已收到消息";
         DataBaseHandle db  = new DataBaseHandle();
         SqlConnection  con = new SqlConnection();
         db.UpdateAGVComState(con, package.TaskID);   //更新AGV指令表中的通讯状态为【已收到】
         return;
     }
     if (package.Head == 10005)       //执行指令完成
     {
         if (package.TaskStepID == 0) //执行取货任务完成
         {
             //得到AGV的起点和终点
             int            StartPoint, EndPoint = 0;
             DataBaseHandle db  = new DataBaseHandle();
             SqlConnection  con = new SqlConnection();
             StartPoint = db.SelectAGVStartEndPoint(con, package.TaskID, ref EndPoint);
             MainWindow.agvUIHandle.AGV_POS_ACTION = ConfigClass.GetMapString(StartPoint) + "取货完毕";
             LogInfoHelp.GetInstance().WriteInfoToLogFile(MainWindow.agvUIHandle.AGV_POS_ACTION, LogInfoHelp.LOG_TYPE.LOG_INFO);
         }
         if (package.TaskStepID == 1)
         {
             DataBaseHandle db  = new DataBaseHandle();
             SqlConnection  con = new SqlConnection();
             //得到AGV的起点和终点
             int StartPoint, EndPoint = 0;
             StartPoint = db.SelectAGVStartEndPoint(con, package.TaskID, ref EndPoint);
             MainWindow.agvUIHandle.AGV_POS_ACTION = ConfigClass.GetMapString(EndPoint) + "卸货完毕";
             LogInfoHelp.GetInstance().WriteInfoToLogFile(MainWindow.agvUIHandle.AGV_POS_ACTION, LogInfoHelp.LOG_TYPE.LOG_INFO);
             db.UpdateAGVWorkState(con, package.TaskID);   //更新AGV指令表中的通讯状态为【完成】
             ExecuteOrder.SendAGVCmdEnable = true;
             //AGV的起点是立库人工上料区,终点是立库入库区,则是人工上料任务,此时通知立库入库
             if (StartPoint == ConfigClass.HandUpArea && EndPoint == ConfigClass.WHInlibArea)
             {
                 //这里用线程,是为了防止接收到多次一样的消息从而重复通知立库的bug。
                 if (InformWHThreadState == false)  //防止线程重复创建
                 {
                     InformWHThread = new Thread(new ParameterizedThreadStart(InformInlib));
                     InformWHThread.IsBackground = true;
                     InformWHThreadState         = true;
                     InformWHThread.Start(package.TaskID);
                     InformWHThread.Priority = ThreadPriority.AboveNormal;
                 }
                 return;
             }
             //AGV的起点是立库出库区,终点是人工下料区,则是人工下料任务,则AGV完成完成了任务后什么也不需要干了
             if (StartPoint == ConfigClass.WHOutlibArea1 && EndPoint == ConfigClass.HandDownArea)
             {
                 //当前人工下料订单完成 恢复上下料的按钮功能。
                 UDDelegate();
                 return;
             }
         }
     }
 }
예제 #2
0
        //执行订单(自动操作)AGV时收到消息的处理方法
        private void AutoOperate()
        {
            if (package.Head == 10003)   //收到消息
            {
                ExecuteOrder.SendAGVCmdEnable         = false;
                MainWindow.agvUIHandle.AGV_POS_ACTION = "AGV已收到消息";
                LogInfoHelp.GetInstance().WriteInfoToLogFile("AGV已收到消息", LogInfoHelp.LOG_TYPE.LOG_INFO);
                DataBaseHandle db  = new DataBaseHandle();
                SqlConnection  con = new SqlConnection();
                db.UpdateAGVComState(con, package.TaskID);   //更新AGV指令表中的通讯状态为【已收到】
                return;
            }
            if (package.Head == 10005)       //执行指令完成
            {
                if (package.TaskStepID == 0) //执行取货任务完成
                {
                    //得到AGV的起点和终点
                    int            StartPoint, EndPoint = 0;
                    DataBaseHandle db  = new DataBaseHandle();
                    SqlConnection  con = new SqlConnection();
                    StartPoint = db.SelectAGVStartEndPoint(con, package.TaskID, ref EndPoint);
                    MainWindow.agvUIHandle.AGV_POS_ACTION = ConfigClass.GetMapString(StartPoint) + "取货完毕";
                    LogInfoHelp.GetInstance().WriteInfoToLogFile(MainWindow.agvUIHandle.AGV_POS_ACTION, LogInfoHelp.LOG_TYPE.LOG_INFO);
                    //如过是送往立库入库区来的,向加工PLC  装配PLC  检测PLC发布当前状态
                    //AGV在各个机构区域取托盘完毕
                    if (EndPoint == ConfigClass.WHInlibArea)
                    {
                        PublishAGVState(StartPoint, EndPoint);
                        Thread t = new Thread(delegate()
                        {
                            Thread.Sleep(new TimeSpan(0, 0, 5));
                            SetNull();
                        });
                        t.Start();
                        t.Priority     = ThreadPriority.AboveNormal;
                        t.IsBackground = true;
                        //判断立库表指令是否超过两条,如果超过两条则挂起,否则不挂起
                        Thread th = new Thread(delegate()
                        {
                            SendPackage pac = new SendPackage();
                            while (true)
                            {
                                bool IsNoPause = db.SelectWHCmdNum(con); //查询立库指令表是否具备AGV挂起的条件
                                if (IsNoPause == false)                  //如果指令没超过一条
                                {
                                    pac.Head     = 10012;
                                    pac.ESSignal = 6;       //解急停
                                    sendESDelegate(pac);
                                    break;
                                }
                                //如果超过两条
                                pac.Head     = 10012;
                                pac.ESSignal = 5;      //急停
                                sendESDelegate(pac);
                                Thread.Sleep(TimeSpan.FromSeconds(3));
                            }
                        });
                        th.Start();
                        th.Priority     = ThreadPriority.AboveNormal;
                        th.IsBackground = true;
                    }
                    return;
                }
                if (package.TaskStepID == 1)  //执行卸货任务完成
                {
                    DataBaseHandle db  = new DataBaseHandle();
                    SqlConnection  con = new SqlConnection();
                    //得到AGV的起点和终点
                    int StartPoint, EndPoint = 0;
                    StartPoint = db.SelectAGVStartEndPoint(con, package.TaskID, ref EndPoint);
                    MainWindow.agvUIHandle.AGV_POS_ACTION = ConfigClass.GetMapString(EndPoint) + "卸货完毕";
                    LogInfoHelp.GetInstance().WriteInfoToLogFile(MainWindow.agvUIHandle.AGV_POS_ACTION, LogInfoHelp.LOG_TYPE.LOG_INFO);
                    db.UpdateAGVWorkState(con, package.TaskID);   //更新AGV指令表中的通讯状态为【完成】
                    ExecuteOrder.SendAGVCmdEnable = true;
                    //如果是从立库出库区来的,向加工PLC  装配PLC  检测PLC发布当前状态

                    //AGV在各个机构区域放托盘完毕
                    if (StartPoint == ConfigClass.WHOutlibArea1)
                    {
                        //发布AGV的状态给各个PLC
                        PublishAGVState(StartPoint, EndPoint);
                        //AGV在各工作区卸货完成后,检查是否还有订单,并且检查每个工作区是否有空闲,
                        //如果两个条件都满足,我们就通知立库继续出库(向立库指令表中插入出库信息)
                        //这里用线程,是为了防止接收到多次一样的消息从而重复通知立库的bug。
                        if (InformWHThreadState == false)  //防止线程重复创建
                        {
                            InformWHThread = new Thread(new ParameterizedThreadStart(CheckAndInformWH));
                            InformWHThread.IsBackground = true;
                            InformWHThreadState         = true;
                            InformWHThread.Start(EndPoint);
                            InformWHThread.Priority = ThreadPriority.AboveNormal;
                        }
                        return;
                    }
                    //如过是送往立库入库区来的,则向立库表中插入入库指令信息
                    if (EndPoint == ConfigClass.WHInlibArea)
                    {
                        //AGV在立库入库区卸货完成,然后向立库表中插入入库指令信息
                        if (InformWHThreadState == false)  //防止线程重复创建
                        {
                            InformWHThread = new Thread(new ParameterizedThreadStart(InformWHInlib));
                            InformWHThread.IsBackground = true;
                            InformWHThreadState         = true;
                            InformWHThread.Start(StartPoint);
                            InformWHThread.Priority = ThreadPriority.AboveNormal;
                        }
                        return;
                    }
                }
            }
        }