コード例 #1
0
ファイル: DataBaseHandle.cs プロジェクト: return001/MES-1
 /// <summary>
 /// 选择AGV指令表中未通讯完成的指令,将其发给AGV
 /// </summary>
 /// <param name="con"></param>
 public void SelectAGVCmd(SqlConnection con)
 {
     try
     {
         openDatabase(con);
         string        sql_select = "SELECT TaskID,StartMapPoint,EndMapPoint FROM AGVCmdTable WHERE WorkState='未完成' AND ComState='未收到' ORDER BY Priority DESC,TaskID ASC";
         SqlCommand    cmd_select = new SqlCommand(sql_select, con);
         SqlDataReader reader     = cmd_select.ExecuteReader();
         if (reader.Read())
         {
             SendPackage package = new SendPackage();
             package.TaskID = Convert.ToInt32(reader["TaskID"].ToString());
             package.MapID1 = Convert.ToUInt16(reader["StartMapPoint"].ToString());
             package.MapID2 = Convert.ToUInt16(reader["EndMapPoint"].ToString());
             if (ExecuteOrder.SendAGVCmdEnable)
             {
                 SelectAGVCmdEvent(package);  //触发事件
             }
         }
         reader.Close();
         con.Close();
     }
     catch (SqlException ex)
     {
         MessageBox.Show("查询AGV通讯状态失败,请检查数据库是否断开" + ex.ToString());
     }
 }
コード例 #2
0
ファイル: AGVMsgHandle.cs プロジェクト: return001/MES-1
        //执行订单(自动操作)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;
                    }
                }
            }
        }