예제 #1
0
        private static void InformAGV(ushort StartPoint, byte TrayStyle)
        {
            DataBaseHandle db  = new DataBaseHandle();
            SqlConnection  con = new SqlConnection();

            db.InsertAGVCmd(con, StartPoint, ConfigClass.WHInlibArea, TrayStyle);
        }
예제 #2
0
        private void CheckAndInformAGV1(object obj)
        {
            Thread.Sleep(2);  //防止由于连续接收到相同信息,从而导致连续插入相同的指令
            WHPackageInfo  package     = obj as WHPackageInfo;
            SqlConnection  con         = new SqlConnection();
            DataBaseHandle db          = new DataBaseHandle();
            string         OrderStyle  = "";
            int            WHTrayStyle = db.SelectOTbySerialNumber(con, package.SerialNumber, ref OrderStyle);

            if (OrderStyle == "人工订单")   //如果是人工订单,则需要将其运送到人口下料区
            {
                db.InsertAGVCmd(con, ConfigClass.WHOutlibArea1, ConfigClass.HandDownArea);
                InformAGVThread1State = false;
                return;
            }
        }
예제 #3
0
        //通知AGV的线程执行的函数
        //通知AGV来取货物,并送往指定位置
        //(根据当前出库的托盘类型和订单类型和各个工作区的PLC状态来判断应该将货物送往哪里,然后向AGV指令表中插入数据)
        private void CheckAndInformAGV(object obj)
        {
            Thread.Sleep(TimeSpan.FromSeconds(4));  //防止由于连续接收到相同信息,从而导致连续插入相同的指令
            WHPackageInfo  package     = obj as WHPackageInfo;
            SqlConnection  con         = new SqlConnection();
            DataBaseHandle db          = new DataBaseHandle();
            string         OrderStyle  = "";
            int            WHTrayStyle = db.SelectOTbySerialNumber(con, package.SerialNumber, ref OrderStyle);

            //更新订单表的出库数量
            db.UpdateOutlibNum(con, OrderStyle);
            if (OrderStyle == "加工订单" && WHTrayStyle == ConfigClass.Tray_A0)  //如果是加工订单,且是加工空托盘A0的话
            {
                //AGV应该有从立库出口处前往加工区
                if (StateMachine.P_Process_Area1 == 0 && MainWindow.WHMatchingProcess1 == true && MainWindow.AGVMatchingProcess1 == false)
                {
                    db.InsertAGVCmd(con, ConfigClass.WHOutlibArea1, ConfigClass.ProcessArea1);
                    MainWindow.AGVMatchingProcess1 = true;
                    InformAGVThread1State          = false;
                    return;
                }
                if (StateMachine.P_Process_Area2 == 0 && MainWindow.WHMatchingProcess2 == true && MainWindow.AGVMatchingProcess2 == false)
                {
                    db.InsertAGVCmd(con, ConfigClass.WHOutlibArea1, ConfigClass.ProcessArea2);
                    MainWindow.AGVMatchingProcess2 = true;
                    InformAGVThread1State          = false;
                    return;
                }
                return;
            }
            if (OrderStyle == "检测订单" && WHTrayStyle == ConfigClass.Tray_A2) //如果是检测订单,且是加工成品托盘A2
            {
                //AGV应该从立库出口处前往检测区
                if (StateMachine.D_Detection_Area1 == 0 && MainWindow.WHMatchingDetection1 == true && MainWindow.AGVMatchingDetection1 == false)
                {
                    db.InsertAGVCmd(con, ConfigClass.WHOutlibArea1, ConfigClass.DetectionArea1);
                    MainWindow.AGVMatchingDetection1 = true;
                    InformAGVThread1State            = false;
                    return;
                }
                if (StateMachine.D_Detection_Area2 == 0 && MainWindow.WHMatchingDetection2 == true && MainWindow.AGVMatchingDetection2 == false)
                {
                    db.InsertAGVCmd(con, ConfigClass.WHOutlibArea1, ConfigClass.DetectionArea2);
                    MainWindow.AGVMatchingDetection2 = true;
                    InformAGVThread1State            = false;
                    return;
                }
                return;
            }
            if (OrderStyle == "拧螺丝订单" && WHTrayStyle == ConfigClass.Tray_B1)  //如果是拧螺丝订单,且是拧螺丝打钉托盘B1
            {
                if (StateMachine.A_Assembly_Area1 == 0 && MainWindow.WHMatchingAssembly1 == true && MainWindow.AGVMatchingAssembly1 == false)
                {
                    //AGV应该从立库出口处前往拧螺丝区(装配区1)
                    db.InsertAGVCmd(con, ConfigClass.WHOutlibArea1, ConfigClass.AssemblyArea1);
                    MainWindow.AGVMatchingAssembly1 = true;
                    InformAGVThread1State           = false;
                    return;
                }
            }
            if (OrderStyle == "轴承压装订单" && WHTrayStyle == ConfigClass.Tray_A4)  //如果是轴承压装订单,且是轴承压装毛坯托盘A4
            {
                if (StateMachine.A_Assembly_Area2 == 0 && MainWindow.WHMatchingAssembly2 == true && MainWindow.AGVMatchingAssembly2 == false)
                {
                    //AGV应该从立库出口处前往轴承压装区(装配区2)
                    db.InsertAGVCmd(con, ConfigClass.WHOutlibArea1, ConfigClass.AssemblyArea2);
                    MainWindow.AGVMatchingAssembly2 = true;
                    InformAGVThread1State           = false;
                    return;
                }
            }
        }
예제 #4
0
        //执行订单(自动操作)AGV时收到消息的处理方法
        private void AutoOperate()
        {
            if (package.Head == 30000)
            {
                MainWindow.whUIHandle.WH_OPER_STATE = "写码完成";
                LogInfoHelp.GetInstance().WriteInfoToLogFile("写码完成", LogInfoHelp.LOG_TYPE.LOG_INFO);
                DataBaseHandle db  = new DataBaseHandle();
                SqlConnection  con = new SqlConnection();
                db.InsertAGVCmd(con, ConfigClass.WHOutlibArea2, ConfigClass.WHInlibArea);
                return;
            }
            if (package.Head == 10004)
            {
                MainWindow.whUIHandle.WH_OPER_STATE = "已收到出库指令";
                ExecuteOrder.SendWHCmdEnable        = false;
                LogInfoHelp.GetInstance().WriteInfoToLogFile("已收到出库指令", LogInfoHelp.LOG_TYPE.LOG_INFO);
                //更新立库表通信状态为【已收到】
                DataBaseHandle db  = new DataBaseHandle();
                SqlConnection  con = new SqlConnection();
                db.UpdateWHComState(con, package.SerialNumber);
                return;
            }

            if (package.Head == 20004)
            {
                if (package.InlibMatchingID == 1)  // 与预期的托盘号一致,匹配成功
                {
                    MainWindow.whUIHandle.WH_OPER_STATE = "已收到入库指令";
                    ExecuteOrder.SendWHCmdEnable        = false;
                    LogInfoHelp.GetInstance().WriteInfoToLogFile("已收到入库指令", LogInfoHelp.LOG_TYPE.LOG_INFO);
                    //更新立库表通信状态为【已收到】
                    DataBaseHandle db  = new DataBaseHandle();
                    SqlConnection  con = new SqlConnection();
                    db.UpdateWHComState(con, package.SerialNumber);
                }
                else
                {
                    MainWindow.whUIHandle.WH_OPER_STATE = "入库托盘匹配不成功";
                    LogInfoHelp.GetInstance().WriteInfoToLogFile("入库托盘匹配不成功", LogInfoHelp.LOG_TYPE.LOG_ERROR);
                    MessageBox.Show("入库托盘匹配不成功,RFID读写器可能出现异常或者出现一些不可预见因素");
                    ExecuteOrder.ExecuteFlag = false;
                    DataBaseHandle db  = new DataBaseHandle();
                    SqlConnection  con = new SqlConnection();
                    db.DeleteAGVCmdTable(con);
                    db.DeleteWHCmdTable(con);
                }
                return;
            }
            if (package.Head == 30004)
            {
                MainWindow.whUIHandle.WH_OPER_STATE = "已收到侧边出库命令";
                ExecuteOrder.SendWHCmdEnable        = false;
                LogInfoHelp.GetInstance().WriteInfoToLogFile("已收到侧边出库命令", LogInfoHelp.LOG_TYPE.LOG_INFO);
                //更新立库表通信状态为【已收到】
                DataBaseHandle db  = new DataBaseHandle();
                SqlConnection  con = new SqlConnection();
                db.UpdateWHComState(con, package.SerialNumber);
                return;
            }
            if (package.Head == 10005)
            {
                if (package.OutlibMatchingID == 2)
                {
                    MainWindow.whUIHandle.WH_OPER_STATE = "出库托盘匹配不成功";
                    LogInfoHelp.GetInstance().WriteInfoToLogFile("出库托盘匹配不成功", LogInfoHelp.LOG_TYPE.LOG_ERROR);
                    MessageBox.Show("出库托盘匹配不成功,请检查MES系统的托盘位置和立库实际的托盘位置是否一致,否则RFID读写器可能出现异常");
                    ExecuteOrder.ExecuteFlag = false;
                    DataBaseHandle db1  = new DataBaseHandle();
                    SqlConnection  con1 = new SqlConnection();
                    db1.DeleteAGVCmdTable(con1);
                    db1.DeleteWHCmdTable(con1);
                    return;
                }
                MainWindow.whUIHandle.WH_OPER_STATE = "已出库";
                LogInfoHelp.GetInstance().WriteInfoToLogFile("已出库", LogInfoHelp.LOG_TYPE.LOG_INFO);
                //更新立库表工作状态为【完成】
                DataBaseHandle db  = new DataBaseHandle();
                SqlConnection  con = new SqlConnection();
                db.UpdateWHWorkState(con, package.SerialNumber);
                ExecuteOrder.SendWHCmdEnable = true;
                //更新库位表(根据流水号得到出库的货位ID,然后将此ID号对应的货位类型置为0,选中状态置为未选中)
                db.UpdateCargoInfo(con, package.SerialNumber);

                //通知AGV来取货物,并送往指定位置
                //(根据当前出库的托盘类型和订单类型和各个工作区的PLC状态来判断应该将货物送往哪里,然后向AGV指令表中插入数据)

                //防止由于连续接收到相同信息,从而导致连续插入相同的指令以及防止线程重复创建
                if (InformAGVThreadState == false)
                {
                    InformAGVThread = new Thread(new ParameterizedThreadStart(CheckAndInformAGV));
                    InformAGVThread.IsBackground = true;
                    InformAGVThread1State        = true;
                    InformAGVThread.Start(package);
                    InformAGVThread.Priority = ThreadPriority.AboveNormal;
                }
                return;
            }
            if (package.Head == 20005)
            {
                MainWindow.whUIHandle.WH_OPER_STATE = "已入库";
                LogInfoHelp.GetInstance().WriteInfoToLogFile("已入库", LogInfoHelp.LOG_TYPE.LOG_INFO);
                //更新立库表工作状态为【完成】
                DataBaseHandle db  = new DataBaseHandle();
                SqlConnection  con = new SqlConnection();
                db.UpdateWHWorkState(con, package.SerialNumber);
                ExecuteOrder.SendWHCmdEnable = true;
                //更新库位表(根据流水号得出入库的货位ID,然后根据得到的托盘类型,将货位类型置为相应的类型。选中状态置为未选中)
                db.UpdateCargoInfo(con, package.SerialNumber, package.TrayStyle);

                //如果订单类型是入库订单的话,我们就根据其托盘类型更新订单表 ,然后判断立库中订单表的数量,
                //如果为0停止响应的机器工作
                //不为0的话则通知出库。
                if (UpdateOrderThreadState == false)
                {
                    UpdateOrderThread = new Thread(new ParameterizedThreadStart(UpdateOrderTable));
                    UpdateOrderThread.IsBackground = true;
                    UpdateOrderThreadState         = true;
                    UpdateOrderThread.Start(package.SerialNumber);
                    UpdateOrderThread.Priority = ThreadPriority.AboveNormal;
                }
            }

            if (package.Head == 30005)
            {
                if (package.OutlibMatchingID == 2)
                {
                    MainWindow.whUIHandle.WH_OPER_STATE = "托盘匹配不成功";
                    LogInfoHelp.GetInstance().WriteInfoToLogFile("侧边托盘匹配不成功", LogInfoHelp.LOG_TYPE.LOG_ERROR);
                    MessageBox.Show("侧边出库托盘匹配不成功,请检查MES系统的托盘位置和立库实际的托盘位置是否一致,否则RFID读写器可能出现异常");
                    ExecuteOrder.ExecuteFlag = false;
                    DataBaseHandle db1  = new DataBaseHandle();
                    SqlConnection  con1 = new SqlConnection();
                    db1.DeleteAGVCmdTable(con1);
                    db1.DeleteWHCmdTable(con1);
                    return;
                }
                MainWindow.whUIHandle.WH_OPER_STATE = "已侧边出库";
                LogInfoHelp.GetInstance().WriteInfoToLogFile("已侧边出库", LogInfoHelp.LOG_TYPE.LOG_INFO);
                //更新立库表工作状态为【完成】
                DataBaseHandle db  = new DataBaseHandle();
                SqlConnection  con = new SqlConnection();
                db.UpdateWHWorkState(con, package.SerialNumber);
                ExecuteOrder.SendWHCmdEnable = true;
                //更新库位表(根据流水号得到出库的货位ID,然后将此ID号对应的货位类型置为0,选中状态置为未选中)
                db.UpdateCargoInfo(con, package.SerialNumber);

                //通知加工区机器人来取货物
                DTUSendPackage.Raw_Tray_Out = 1;

                return;
            }
        }