예제 #1
0
 //保存修改按钮事件
 private void btn_Save_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (xiugai_position.Text == "")
         {
             MessageBox.Show("请选择库位");
             return;
         }
         if (Convert.ToInt32(xiugai_position.Text) > 80 || Convert.ToInt32(xiugai_position.Text) < 1)
         {
             MessageBox.Show("请选择正确的库位");
             return;
         }
         if (Convert.ToInt32(xiugai_position.Text) == 44 || Convert.ToInt32(xiugai_position.Text) == 45)
         {
             MessageBox.Show("该库位为禁用库位,请选择其他库位");
             return;
         }
         int            position  = Convert.ToInt32(xiugai_position.Text);
         int            TrayStyle = xiugai_traystyle.SelectedIndex;
         DataBaseHandle db        = new DataBaseHandle();
         SqlConnection  con       = new SqlConnection();
         db.SaveKuweiArray(con, position, TrayStyle);
         db.UpdateKuweiArray(con);
         Get_db_CargoInfo();
     }
     catch (Exception ex)
     {
         MessageBox.Show("用户非法输入,请输入数字" + ex.ToString());
     }
 }
예제 #2
0
        private static void InformAGV(ushort StartPoint, byte TrayStyle)
        {
            DataBaseHandle db  = new DataBaseHandle();
            SqlConnection  con = new SqlConnection();

            db.InsertAGVCmd(con, StartPoint, ConfigClass.WHInlibArea, TrayStyle);
        }
예제 #3
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;
             }
         }
     }
 }
예제 #4
0
        private void UpdateOrderTable(object obj)
        {
            int SerialNumber = -1;

            if (obj != null)
            {
                SerialNumber = Convert.ToInt32(obj);
            }
            Thread.Sleep(TimeSpan.FromSeconds(4));
            DataBaseHandle db          = new DataBaseHandle();
            SqlConnection  con         = new SqlConnection();
            string         OrderStyle  = "";
            int            WHTrayStyle = db.SelectOTbySerialNumber(con, SerialNumber, ref OrderStyle);

            if (OrderStyle == "入库订单")
            {
                //更新订单表
                if (WHTrayStyle == ConfigClass.Tray_A2)   //入库加工成品托盘A2
                {
                    db.UpdateOrderNum(con, "加工订单");
                    Thread.Sleep(1);
                    CheckWHNumber("加工订单");
                    UpdateOrderThreadState = false;
                    return;
                }
                if (WHTrayStyle == ConfigClass.Tray_A3)  //入库加工检测托盘A3
                {
                    db.UpdateOrderNum(con, "检测订单");
                    Thread.Sleep(1);
                    CheckWHNumber("检测订单");
                    UpdateOrderThreadState = false;
                    return;
                }
                if (WHTrayStyle == ConfigClass.Tray_B2)   //入库螺钉完成托盘
                {
                    db.UpdateOrderNum(con, "拧螺丝订单");
                    Thread.Sleep(1);
                    CheckWHNumber("拧螺丝订单");
                    UpdateOrderThreadState = false;
                    return;
                }
                if (WHTrayStyle == ConfigClass.Tray_A5)  //入库轴承压装完成托盘
                {
                    db.UpdateOrderNum(con, "轴承压装订单");
                    Thread.Sleep(1);
                    CheckWHNumber("轴承压装订单");
                    UpdateOrderThreadState = false;
                    return;
                }
            }
        }
예제 #5
0
        public static bool RunExecuteWHCmdThread = true;  //运行立库指令表的线程
        public static void ExecuteWHCmd(object obj)       // 执行立库指令表(不断查询数据库AGV指令表中有没有未发送给AGV的指令,然后将其发送出去)
        {
            DataBaseHandle db  = obj as DataBaseHandle;
            SqlConnection  con = new SqlConnection();

            while (RunExecuteWHCmdThread)
            {
                Thread.Sleep(TimeSpan.FromSeconds(3));                                           //3s查询一次
                if ((ExecuteFlag == true || HandAndDownFlag == true) && SendWHCmdEnable == true) //开始执行订单
                {
                    db.SelectWHCmd(con);                                                         //查询立库需要发送的指令
                }
            }
            RunExecuteWHCmdThread = true;
        }
예제 #6
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;
            }
        }
예제 #7
0
        /// <summary>
        /// 人工上料订单,AGV动作执行完毕后,通知立库入库
        /// </summary>
        /// <param name="TaskID"></param>
        private void InformInlib(object TaskID)
        {
            int taskID = -1;

            if (TaskID != null)
            {
                taskID = Convert.ToInt32(TaskID);
            }
            Thread.Sleep(TimeSpan.FromSeconds(2));  ////等待几秒,防止重复接收消息导致重复向立库指令表中插入指令
            DataBaseHandle db        = new DataBaseHandle();
            SqlConnection  con       = new SqlConnection();
            int            TrayStyle = db.SelectTrayStyleByTaskID(con, taskID);

            db.InsertWHCmd(con, "人工订单", "入库", TrayStyle);
            InformWHThreadState = false;
        }
예제 #8
0
        //AGV在立库入库区卸货完成,然后向立库表中插入入库指令信息
        private void InformWHInlib(object startpoint)
        {
            int StartPoint = 0;

            if (startpoint != null)
            {
                StartPoint = Convert.ToInt32(startpoint);
            }
            Thread.Sleep(TimeSpan.FromSeconds(4));   //等待几秒,防止重复接收消息导致重复向立库指令表中插入指令
            DataBaseHandle db  = new DataBaseHandle();
            SqlConnection  con = new SqlConnection();

            if (StartPoint == ConfigClass.WHOutlibArea2)
            {
                db.InsertWHCmd(con, "入库订单", "入库", ConfigClass.Tray_A0);  //入库加工空托盘
                InformWHThreadState = false;
                return;
            }
            if (StartPoint == ConfigClass.ProcessArea1 || StartPoint == ConfigClass.ProcessArea2)
            {
                db.InsertWHCmd(con, "入库订单", "入库", ConfigClass.Tray_A2); //入库加工成品托盘A2
                InformWHThreadState = false;
                return;
            }
            if (StartPoint == ConfigClass.DetectionArea1 || StartPoint == ConfigClass.DetectionArea2)
            {
                db.InsertWHCmd(con, "入库订单", "入库", ConfigClass.Tray_A3);  //入库加工检测托盘A3
                InformWHThreadState = false;
                return;
            }
            if (StartPoint == ConfigClass.AssemblyArea1)
            {
                db.InsertWHCmd(con, "入库订单", "入库", ConfigClass.Tray_B2);   //入库螺钉完成托盘B2
                InformWHThreadState = false;
                return;
            }
            if (StartPoint == ConfigClass.AssemblyArea2)
            {
                db.InsertWHCmd(con, "入库订单", "入库", ConfigClass.Tray_A5);  //轴承压装完成托盘A5
                InformWHThreadState = false;
                return;
            }
        }
예제 #9
0
        //读取数据库CargoInfo的数据
        private void Get_db_CargoInfo()
        {
            DataBaseHandle db  = new DataBaseHandle();
            SqlConnection  con = new SqlConnection();
            DataTable      dt  = db.GetKuweiArray(con);

            for (int i = 0; i < 80; i++)
            {
                if (Convert.ToInt32(dt.Rows[i][0]) == 0)
                {
                    dt.Rows[i][0] = -10;   //代表-10
                }
            }
            position.POS_1  = Convert.ToInt32(dt.Rows[0][0]);
            position.POS_2  = Convert.ToInt32(dt.Rows[1][0]);
            position.POS_3  = Convert.ToInt32(dt.Rows[2][0]);
            position.POS_4  = Convert.ToInt32(dt.Rows[3][0]);
            position.POS_5  = Convert.ToInt32(dt.Rows[4][0]);
            position.POS_6  = Convert.ToInt32(dt.Rows[5][0]);
            position.POS_7  = Convert.ToInt32(dt.Rows[6][0]);
            position.POS_8  = Convert.ToInt32(dt.Rows[7][0]);
            position.POS_9  = Convert.ToInt32(dt.Rows[8][0]);
            position.POS_10 = Convert.ToInt32(dt.Rows[9][0]);
            position.POS_11 = Convert.ToInt32(dt.Rows[10][0]);
            position.POS_12 = Convert.ToInt32(dt.Rows[11][0]);
            position.POS_13 = Convert.ToInt32(dt.Rows[12][0]);
            position.POS_14 = Convert.ToInt32(dt.Rows[13][0]);
            position.POS_15 = Convert.ToInt32(dt.Rows[14][0]);
            position.POS_16 = Convert.ToInt32(dt.Rows[15][0]);
            position.POS_17 = Convert.ToInt32(dt.Rows[16][0]);
            position.POS_18 = Convert.ToInt32(dt.Rows[17][0]);
            position.POS_19 = Convert.ToInt32(dt.Rows[18][0]);
            position.POS_20 = Convert.ToInt32(dt.Rows[19][0]);
            position.POS_21 = Convert.ToInt32(dt.Rows[20][0]);
            position.POS_22 = Convert.ToInt32(dt.Rows[21][0]);
            position.POS_23 = Convert.ToInt32(dt.Rows[22][0]);
            position.POS_24 = Convert.ToInt32(dt.Rows[23][0]);
            position.POS_25 = Convert.ToInt32(dt.Rows[24][0]);
            position.POS_26 = Convert.ToInt32(dt.Rows[25][0]);
            position.POS_27 = Convert.ToInt32(dt.Rows[26][0]);
            position.POS_28 = Convert.ToInt32(dt.Rows[27][0]);
            position.POS_29 = Convert.ToInt32(dt.Rows[28][0]);
            position.POS_30 = Convert.ToInt32(dt.Rows[29][0]);
            position.POS_31 = Convert.ToInt32(dt.Rows[30][0]);
            position.POS_32 = Convert.ToInt32(dt.Rows[31][0]);
            position.POS_33 = Convert.ToInt32(dt.Rows[32][0]);
            position.POS_34 = Convert.ToInt32(dt.Rows[33][0]);
            position.POS_35 = Convert.ToInt32(dt.Rows[34][0]);
            position.POS_36 = Convert.ToInt32(dt.Rows[35][0]);
            position.POS_37 = Convert.ToInt32(dt.Rows[36][0]);
            position.POS_38 = Convert.ToInt32(dt.Rows[37][0]);
            position.POS_39 = Convert.ToInt32(dt.Rows[38][0]);
            position.POS_40 = Convert.ToInt32(dt.Rows[39][0]);
            position.POS_41 = Convert.ToInt32(dt.Rows[40][0]);
            position.POS_42 = Convert.ToInt32(dt.Rows[41][0]);
            position.POS_43 = Convert.ToInt32(dt.Rows[42][0]);
            position.POS_44 = Convert.ToInt32(dt.Rows[43][0]);
            position.POS_45 = Convert.ToInt32(dt.Rows[44][0]);
            position.POS_46 = Convert.ToInt32(dt.Rows[45][0]);
            position.POS_47 = Convert.ToInt32(dt.Rows[46][0]);
            position.POS_48 = Convert.ToInt32(dt.Rows[47][0]);
            position.POS_49 = Convert.ToInt32(dt.Rows[48][0]);
            position.POS_50 = Convert.ToInt32(dt.Rows[49][0]);
            position.POS_51 = Convert.ToInt32(dt.Rows[50][0]);
            position.POS_52 = Convert.ToInt32(dt.Rows[51][0]);
            position.POS_53 = Convert.ToInt32(dt.Rows[52][0]);
            position.POS_54 = Convert.ToInt32(dt.Rows[53][0]);
            position.POS_55 = Convert.ToInt32(dt.Rows[54][0]);
            position.POS_56 = Convert.ToInt32(dt.Rows[55][0]);
            position.POS_57 = Convert.ToInt32(dt.Rows[56][0]);
            position.POS_58 = Convert.ToInt32(dt.Rows[57][0]);
            position.POS_59 = Convert.ToInt32(dt.Rows[58][0]);
            position.POS_60 = Convert.ToInt32(dt.Rows[59][0]);
            position.POS_61 = Convert.ToInt32(dt.Rows[60][0]);
            position.POS_62 = Convert.ToInt32(dt.Rows[61][0]);
            position.POS_63 = Convert.ToInt32(dt.Rows[62][0]);
            position.POS_64 = Convert.ToInt32(dt.Rows[63][0]);
            position.POS_65 = Convert.ToInt32(dt.Rows[64][0]);
            position.POS_66 = Convert.ToInt32(dt.Rows[65][0]);
            position.POS_67 = Convert.ToInt32(dt.Rows[66][0]);
            position.POS_68 = Convert.ToInt32(dt.Rows[67][0]);
            position.POS_69 = Convert.ToInt32(dt.Rows[68][0]);
            position.POS_70 = Convert.ToInt32(dt.Rows[69][0]);
            position.POS_71 = Convert.ToInt32(dt.Rows[70][0]);
            position.POS_72 = Convert.ToInt32(dt.Rows[71][0]);
            position.POS_73 = Convert.ToInt32(dt.Rows[72][0]);
            position.POS_74 = Convert.ToInt32(dt.Rows[73][0]);
            position.POS_75 = Convert.ToInt32(dt.Rows[74][0]);
            position.POS_76 = Convert.ToInt32(dt.Rows[75][0]);
            position.POS_77 = Convert.ToInt32(dt.Rows[76][0]);
            position.POS_78 = Convert.ToInt32(dt.Rows[77][0]);
            position.POS_79 = Convert.ToInt32(dt.Rows[78][0]);
            position.POS_80 = Convert.ToInt32(dt.Rows[79][0]);
        }
예제 #10
0
 //将装配区的状态赋给上述属性
 public static void Get_A_State(DTURequestInfo requestinfo)
 {
     //状态
     A_System_State     = requestinfo.SystemState;
     A_Assembly_Area1   = (requestinfo.PartState & 1) == 1 ? 1 : 0;
     A_Assembly_Area2   = (requestinfo.PartState & 2) == 2 ? 1 : 0;
     A_Robot_State      = (requestinfo.PartState & 4) == 4 ? 1 : 0;
     A_Cor_State        = (requestinfo.PartState & 8) == 8 ? 1 : 0;
     A_Assembly_InArea1 = (requestinfo.PartState & 16) == 16 ? 1 : 0;
     A_Assembly_InArea2 = (requestinfo.PartState & 32) == 32 ? 1 : 0;
     if (A_System_State != 2)   //如果不是系统正常,已启动这个状态的话,就退出
     {
         return;
     }
     //动作
     A_AGV_Assembly1 = (requestinfo.AGVExecuteCmd & 1) == 1 ? 1 : 0;
     A_AGV_Assembly2 = (requestinfo.AGVExecuteCmd & 2) == 2 ? 1 : 0;
     //RFID
     A_Assembly1_RFID = requestinfo.Assembly_Area1_RFID;
     if (A_Assembly1_RFID == ConfigClass.Tray_B2 && A_OnlyOnce3 == false)
     {
         SqlConnection  con = new SqlConnection();
         DataBaseHandle db  = new DataBaseHandle();
         db.SaveData(con, "拧螺丝订单", ConfigClass.GetTrayString(A_Assembly1_RFID));
         A_OnlyOnce3 = true;
     }
     if (A_Assembly1_RFID != ConfigClass.Tray_B2)
     {
         A_OnlyOnce3 = false;
     }
     A_Assembly2_RFID = requestinfo.Assembly_Area2_RFID;
     if (A_Assembly2_RFID == ConfigClass.Tray_B2 && A_OnlyOnce4 == false)
     {
         SqlConnection  con = new SqlConnection();
         DataBaseHandle db  = new DataBaseHandle();
         db.SaveData(con, "拧螺丝订单", "缺省", ConfigClass.GetTrayString(A_Assembly1_RFID));
         A_OnlyOnce4 = true;
     }
     if (A_Assembly2_RFID != ConfigClass.Tray_B2)
     {
         A_OnlyOnce4 = false;
     }
     //如果动作值为1,则通知AGV(向AGV表中插入命令)且不能重复插入
     if (A_AGV_Assembly1 == 1 && A_OnlyOnce1 == false)
     {
         InformAGV(ConfigClass.AssemblyArea1);
         A_OnlyOnce1 = true;
     }
     if (A_AGV_Assembly1 == 0)
     {
         A_OnlyOnce1 = false;
     }
     if (A_AGV_Assembly2 == 1 && A_OnlyOnce2 == false)
     {
         InformAGV(ConfigClass.AssemblyArea2);
         A_OnlyOnce2 = true;
     }
     if (A_AGV_Assembly2 == 0)
     {
         A_OnlyOnce2 = false;
     }
 }
예제 #11
0
 //将检测区的状态赋给上述属性
 public static void Get_D_State(DTURequestInfo requestinfo)
 {
     //状态
     D_System_State    = requestinfo.SystemState;
     D_Detection_Area1 = (requestinfo.PartState & 1) == 1 ? 1 : 0;
     D_Detection_Area2 = (requestinfo.PartState & 2) == 2 ? 1 : 0;
     D_Marking_State   = (requestinfo.PartState & 4) == 4 ? 1 : 0;
     D_Robot_State     = (requestinfo.PartState & 8) == 8 ? 1 : 0;
     if (D_System_State != 2)   //如果不是系统正常,已启动这个状态的话,就退出
     {
         return;
     }
     //动作
     D_AGV_Detection1 = (requestinfo.AGVExecuteCmd & 1) == 1 ? 1 : 0;
     D_AGV_Detection2 = (requestinfo.AGVExecuteCmd & 2) == 2 ? 1 : 0;
     //RFID
     D_Detection1_RFID = requestinfo.Detection_Area1_RFID;
     if (D_Detection1_RFID == ConfigClass.Tray_A3 && D_OnlyOnce3 == false)
     {
         D_AGV_Detection1_Para1 = requestinfo.Detection_Area1_Parameter1;
         D_AGV_Detection1_Para2 = requestinfo.Detection_Area1_Parameter2;
         D_AGV_Detection1_Para3 = requestinfo.Detection_Area1_Parameter3;
         D_AGV_Detection1_Para4 = requestinfo.Detection_Area1_Parameter4;
         D_AGV_Detection1_Para5 = requestinfo.Detection_Area1_Parameter5;
         SqlConnection  con = new SqlConnection();
         DataBaseHandle db  = new DataBaseHandle();
         db.SaveData(con, "检测订单", ConfigClass.GetTrayString(D_Detection1_RFID),
                     ConfigClass.GetTrayString(D_Detection2_RFID), D_AGV_Detection1_Para1, D_AGV_Detection1_Para2,
                     D_AGV_Detection1_Para3, D_AGV_Detection1_Para4, D_AGV_Detection1_Para5);
         D_OnlyOnce3 = true;
     }
     if (D_Detection1_RFID != ConfigClass.Tray_A3)
     {
         D_OnlyOnce3 = false;
     }
     D_Detection2_RFID = requestinfo.Detection_Area2_RFID;
     if (D_Detection2_RFID == ConfigClass.Tray_A3 && D_OnlyOnce4 == false)
     {
         D_AGV_Detection2_Para1 = requestinfo.Detection_Area2_Parameter1;
         D_AGV_Detection2_Para2 = requestinfo.Detection_Area2_Parameter2;
         D_AGV_Detection2_Para3 = requestinfo.Detection_Area2_Parameter3;
         D_AGV_Detection2_Para4 = requestinfo.Detection_Area2_Parameter4;
         D_AGV_Detection2_Para5 = requestinfo.Detection_Area2_Parameter5;
         SqlConnection  con = new SqlConnection();
         DataBaseHandle db  = new DataBaseHandle();
         db.SaveData(con, "检测订单", ConfigClass.GetTrayString(D_Detection1_RFID),
                     ConfigClass.GetTrayString(D_Detection2_RFID), D_AGV_Detection1_Para1, D_AGV_Detection1_Para2,
                     D_AGV_Detection1_Para3, D_AGV_Detection1_Para4, D_AGV_Detection1_Para5);
         D_OnlyOnce4 = true;
     }
     if (D_Detection2_RFID != ConfigClass.Tray_A3)
     {
         D_OnlyOnce4 = false;
     }
     //如果动作值为1,则通知AGV(向AGV表中插入命令)且不能重复插入
     if (D_AGV_Detection1 == 1 && D_OnlyOnce1 == false)
     {
         InformAGV(ConfigClass.DetectionArea1);
         D_OnlyOnce1 = true;
     }
     if (D_AGV_Detection1 == 0)
     {
         D_OnlyOnce1 = false;
     }
     if (D_AGV_Detection2 == 1 && D_OnlyOnce2 == false)
     {
         InformAGV(ConfigClass.DetectionArea2);
         D_OnlyOnce2 = true;
     }
     if (D_AGV_Detection2 == 0)
     {
         D_OnlyOnce2 = false;
     }
 }
예제 #12
0
        }                                                           //人工下料AGV对接台RFID识别托盘工件相关参数5

        //将加工区的状态赋给上述属性
        public static void Get_P_State(DTURequestInfo requestinfo)
        {
            //状态
            P_System_State     = requestinfo.SystemState;
            P_Manual_Up_Area   = (requestinfo.PartState & 1) == 1 ? 1 : 0;
            P_Manual_Down_Area = (requestinfo.PartState & 2) == 2 ? 1 : 0;
            P_Process_Area1    = (requestinfo.PartState & 4) == 4 ? 1 : 0;
            P_Process_Area2    = (requestinfo.PartState & 8) == 8 ? 1 : 0;
            P_Mazak1_State     = (requestinfo.PartState & 16) == 16 ? 1 : 0;
            P_Mazak2_State     = (requestinfo.PartState & 32) == 32 ? 1 : 0;
            P_Big_State        = (requestinfo.PartState & 64) == 64 ? 1 : 0;
            P_Robot_State      = (requestinfo.PartState & 128) == 128 ? 1 : 0;
            //系统控制
            P_System_Control = requestinfo.SystemControl;
            if (P_System_State != 2)   //如果不是系统正常,已启动这个状态的话,就退出
            {
                return;
            }

            //动作
            P_Raw_Tray_Empty = (requestinfo.Raw_Tray_Empty & 1) == 1 ? 1 : 0;

            P_AGV_Manual_Up   = (requestinfo.AGVExecuteCmd & 1) == 1 ? 1 : 0;
            P_AGV_Manual_Down = (requestinfo.AGVExecuteCmd & 2) == 2 ? 1 : 0;
            P_AGV_Process1    = (requestinfo.AGVExecuteCmd & 4) == 4 ? 1 : 0;
            P_AGV_Process2    = (requestinfo.AGVExecuteCmd & 8) == 8 ? 1 : 0;
            //RFID
            P_Manual_Up_RFID   = requestinfo.Manual_Up_RFID;
            P_Manual_Down_RFID = requestinfo.Manual_Down_RFID;
            P_Process1_RFID    = requestinfo.Process_Area1_RFID;
            if (P_Process1_RFID == ConfigClass.Tray_A2 && P_OnlyOnce5 == false)
            {
                SqlConnection  con = new SqlConnection();
                DataBaseHandle db  = new DataBaseHandle();
                db.SaveData(con, "加工订单", ConfigClass.GetTrayString(P_Process1_RFID));
                P_OnlyOnce5 = true;
            }
            if (P_Process1_RFID != ConfigClass.Tray_A2)
            {
                P_OnlyOnce5 = false;
            }
            P_Process2_RFID = requestinfo.Process_Area2_RFID;
            if (P_Process2_RFID == ConfigClass.Tray_A2 && P_OnlyOnce6 == false)
            {
                SqlConnection  con = new SqlConnection();
                DataBaseHandle db  = new DataBaseHandle();
                db.SaveData(con, "加工订单", "缺省", ConfigClass.GetTrayString(P_Process2_RFID));
                P_OnlyOnce6 = true;
            }
            if (P_Process2_RFID != ConfigClass.Tray_A2)
            {
                P_OnlyOnce6 = false;
            }

            //数据
            UP_C_D_Number   = (int)requestinfo.Manual_Up_CD_Number;
            Down_C_D_Number = (int)requestinfo.Manual_Down_CD_Number;
            Down_RFID_Para1 = requestinfo.Manual_Down_Para1;
            Down_RFID_Para2 = requestinfo.Manual_Down_Para2;
            Down_RFID_Para3 = requestinfo.Manual_Down_Para3;
            Down_RFID_Para4 = requestinfo.Manual_Down_Para4;
            Down_RFID_Para5 = requestinfo.Manual_Down_Para5;

            //如果动作值为1,则通知AGV(向AGV表中插入命令),且不能重复插入
            if (P_Raw_Tray_Empty == 1 && P_OnlyOnce1 == false)
            {
                WHSendPackage package = new WHSendPackage();
                package.Head         = 29000;
                package.TrayID       = 0;
                package.WHPostion    = 0;
                package.SerialNumber = 0;
                if (MainWindow.WHDISCONNECTED == false)
                {
                    sendWHMsgDel(package);
                    P_OnlyOnce1 = true;
                }
            }
            if (P_Raw_Tray_Empty == 0)
            {
                P_OnlyOnce1 = false;
            }
            if (P_AGV_Process1 == 1 && P_OnlyOnce2 == false)
            {
                InformAGV(ConfigClass.ProcessArea1);
                P_OnlyOnce2 = true;
            }
            if (P_AGV_Process1 == 0)
            {
                P_OnlyOnce2 = false;
            }
            if (P_AGV_Process2 == 1 && P_OnlyOnce3 == false)
            {
                InformAGV(ConfigClass.ProcessArea2);
                P_OnlyOnce3 = true;
            }
            if (P_AGV_Process2 == 0)
            {
                P_OnlyOnce3 = false;
            }
            if (P_AGV_Manual_Up == 1 && P_OnlyOnce4 == false)
            {
                InformAGV(ConfigClass.HandUpArea, P_Manual_Up_RFID);
                P_OnlyOnce4 = true;
            }
            if (P_AGV_Manual_Up == 0)
            {
                P_OnlyOnce4 = false;
            }
        }
예제 #13
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;
                    }
                }
            }
        }
예제 #14
0
        /// <summary>
        ///  //AGV在各工作区卸货完成后,检查是否还有订单(如果多于或大于2个,则通知立库出库,有1个说明有一个当前正在操作),并且检查每个工作区是否有空闲,
        //如果两个条件都满足,我们就通知立库继续出库(向立库指令表中插入出库信息)
        /// </summary>
        private void CheckAndInformWH(object endpoint)
        {
            int EndPoint = 0;

            if (endpoint != null)
            {
                EndPoint = Convert.ToInt32(endpoint);
            }
            DataBaseHandle db  = new DataBaseHandle();
            SqlConnection  con = new SqlConnection();

            Thread.Sleep(TimeSpan.FromSeconds(5));  // 发布AGV的状态给各个PLC保持5s
            SetNull();
            if (StateMachine.P_Process_Area1 == 0 && MainWindow.WHMatchingProcess1 == false && StateMachine.P_System_State == 2 && MainWindow.P_Order_Enable == true)
            {
                bool P_Outlib_Can = db.JudgeOutlib(con, "加工订单") && db.JudgePreOutlibNum(con, "加工订单");  //判断加工订单是否还可以出库
                if (P_Outlib_Can == true)
                {
                    db.InsertWHCmd(con, "加工订单", "侧边出库", ConfigClass.Tray_A1);  //侧边出库加工毛坯托盘A1
                    db.InsertWHCmd(con, "加工订单", "出库", ConfigClass.Tray_A0);    //出库加工空托盘A0
                    db.UpdatePreOutlibNum(con, "加工订单");
                    MainWindow.WHMatchingProcess1 = true;
                    RefreshWHMatchingWorkArea(EndPoint);
                    RefreshAGVMatchingWorkArea(EndPoint);
                    InformWHThreadState = false;
                    return;
                }
            }
            if (StateMachine.D_Detection_Area1 == 0 && MainWindow.WHMatchingDetection1 == false && StateMachine.D_System_State == 2 && MainWindow.D_Order_Enable == true)
            {
                bool D_Outlib_Can = db.JudgeOutlib(con, "检测订单") && db.JudgePreOutlibNum(con, "检测订单");  //判断检测订单是否还可以出库
                if (D_Outlib_Can == true)
                {
                    db.InsertWHCmd(con, "检测订单", "出库", ConfigClass.Tray_A2);   //出库加工成品托盘A2托盘
                    db.UpdatePreOutlibNum(con, "检测订单");
                    MainWindow.WHMatchingDetection1 = true;
                    RefreshWHMatchingWorkArea(EndPoint);
                    RefreshAGVMatchingWorkArea(EndPoint);
                    InformWHThreadState = false;
                    return;
                }
            }
            if (StateMachine.A_Assembly_Area1 == 0 && StateMachine.A_Assembly_InArea1 == 0 && MainWindow.WHMatchingAssembly1 == false && StateMachine.A_System_State == 2 && MainWindow.A1_Order_Enable == true)
            {
                bool A1_Outlib_Can = db.JudgeOutlib(con, "拧螺丝订单") && db.JudgePreOutlibNum(con, "拧螺丝订单");  //判断拧螺丝订单是否还可以出库
                if (A1_Outlib_Can == true)
                {
                    db.InsertWHCmd(con, "拧螺丝订单", "出库", ConfigClass.Tray_B1);  //出库拧螺钉打钉托盘B1
                    db.UpdatePreOutlibNum(con, "拧螺丝订单");
                    MainWindow.WHMatchingAssembly1 = true;
                    RefreshWHMatchingWorkArea(EndPoint);
                    RefreshAGVMatchingWorkArea(EndPoint);
                    InformWHThreadState = false;
                    return;
                }
            }
            if (StateMachine.A_Assembly_Area2 == 0 && StateMachine.A_Assembly_InArea2 == 0 && MainWindow.WHMatchingAssembly2 == false && StateMachine.A_System_State == 2 && MainWindow.A2_Order_Enable == true)
            {
                bool A2_Outlib_Can = db.JudgeOutlib(con, "轴承压装订单") && db.JudgePreOutlibNum(con, "轴承压装订单");  //判断轴承压装订单是否还可以出库
                if (A2_Outlib_Can == true)
                {
                    db.InsertWHCmd(con, "轴承压装订单", "出库", ConfigClass.Tray_A4);  //出库轴承压装毛坯托盘A4
                    db.UpdatePreOutlibNum(con, "轴承压装订单");
                    MainWindow.WHMatchingAssembly2 = true;
                    RefreshWHMatchingWorkArea(EndPoint);
                    RefreshAGVMatchingWorkArea(EndPoint);
                    InformWHThreadState = false;
                    return;
                }
            }
            if (StateMachine.P_Process_Area2 == 0 && MainWindow.WHMatchingProcess2 == false && StateMachine.P_System_State == 2 && MainWindow.P_Order_Enable == true)
            {
                bool P_Outlib_Can = db.JudgeOutlib(con, "加工订单") && db.JudgePreOutlibNum(con, "加工订单");  //判断加工订单是否还可以出库
                if (P_Outlib_Can == true)
                {
                    db.InsertWHCmd(con, "加工订单", "侧边出库", ConfigClass.Tray_A1);  //侧边出库加工毛坯托盘A1
                    db.InsertWHCmd(con, "加工订单", "出库", ConfigClass.Tray_A0);    //出库加工空托盘A0
                    db.UpdatePreOutlibNum(con, "加工订单");
                    MainWindow.WHMatchingProcess2 = true;
                    RefreshWHMatchingWorkArea(EndPoint);
                    RefreshAGVMatchingWorkArea(EndPoint);
                    InformWHThreadState = false;
                    return;
                }
            }
            if (StateMachine.D_Detection_Area2 == 0 && MainWindow.WHMatchingDetection2 == false && StateMachine.D_System_State == 2 && MainWindow.D_Order_Enable == true)
            {
                bool D_Outlib_Can = db.JudgeOutlib(con, "检测订单") && db.JudgePreOutlibNum(con, "检测订单");  //判断检测订单是否还可以出库
                if (D_Outlib_Can == true)
                {
                    db.InsertWHCmd(con, "检测订单", "出库", ConfigClass.Tray_A2);  //出库加工成品托盘A2托盘
                    db.UpdatePreOutlibNum(con, "检测订单");
                    MainWindow.WHMatchingDetection2 = true;
                    RefreshWHMatchingWorkArea(EndPoint);
                    RefreshAGVMatchingWorkArea(EndPoint);
                    InformWHThreadState = false;
                    return;
                }
            }
            //上诉if条件都进不去的话,依然要刷新立库和AGV的匹配状态
            RefreshWHMatchingWorkArea(EndPoint);
            RefreshAGVMatchingWorkArea(EndPoint);
        }
예제 #15
0
        private void ManualOperate()
        {
            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);
            }

            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码是否正确,否则RFID读写器可能出现异常");
                    ExecuteOrder.HandAndDownFlag = false;
                    DataBaseHandle db1  = new DataBaseHandle();
                    SqlConnection  con1 = new SqlConnection();
                    db1.DeleteAGVCmdTable(con1);
                    db1.DeleteWHCmdTable(con1);
                }
                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.HandAndDownFlag = 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 (InformAGVThread1State == false)
                {
                    InformAGVThread1 = new Thread(new ParameterizedThreadStart(CheckAndInformAGV1));
                    InformAGVThread1.IsBackground = true;
                    InformAGVThread1State         = true;
                    InformAGVThread1.Start(package);
                }
                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);

                //当前上料订单完成事件,恢复上下料的按钮功能。
                UDDelegate();
            }
        }
예제 #16
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;
            }
        }
예제 #17
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;
                }
            }
        }
예제 #18
0
 //手动操作AGV时收到消息的处理方法
 private void HandOperate()
 {
     if (package.Head == 10004)
     {
         MainWindow.whUIHandle.WH_OPER_STATE = "已收到出库指令";
         LogInfoHelp.GetInstance().WriteInfoToLogFile("已收到出库指令", LogInfoHelp.LOG_TYPE.LOG_INFO);
         return;
     }
     if (package.Head == 20004)
     {
         if (package.InlibMatchingID == 1)
         {
             MainWindow.whUIHandle.WH_OPER_STATE = "已收到入库指令";
             LogInfoHelp.GetInstance().WriteInfoToLogFile("已收到入库指令", LogInfoHelp.LOG_TYPE.LOG_INFO);
         }
         else
         {
             MainWindow.whUIHandle.WH_OPER_STATE = "入库托盘匹配不成功";
             MessageBox.Show("入库托盘匹配不成功,请选择正确的托盘类型,或者检查托盘RFID码是否正确,否则RFID读写器可能出现异常");
             LogInfoHelp.GetInstance().WriteInfoToLogFile("入库托盘匹配不成功", LogInfoHelp.LOG_TYPE.LOG_ERROR);
         }
         return;
     }
     if (package.Head == 30004)
     {
         MainWindow.whUIHandle.WH_OPER_STATE = "已收到侧边出库指令";
         LogInfoHelp.GetInstance().WriteInfoToLogFile("已收到侧边出库指令", LogInfoHelp.LOG_TYPE.LOG_INFO);
         return;
     }
     if (package.Head == 10005)
     {
         if (package.OutlibMatchingID == 2)
         {
             MainWindow.whUIHandle.WH_OPER_STATE = "出库托盘匹配不成功";
             MessageBox.Show("出库托盘匹配不成功,请检查MES系统的托盘位置和立库实际的托盘位置是否一致,否则RFID读写器可能出现异常");
             LogInfoHelp.GetInstance().WriteInfoToLogFile("出库托盘匹配不成功", LogInfoHelp.LOG_TYPE.LOG_ERROR);
         }
         MainWindow.whUIHandle.WH_OPER_STATE = "已出库";
         LogInfoHelp.GetInstance().WriteInfoToLogFile("已出库", LogInfoHelp.LOG_TYPE.LOG_INFO);
         DataBaseHandle db  = new DataBaseHandle();
         SqlConnection  con = new SqlConnection();
         db.SaveKuweiArray(con, MainWindow.whHandInfo.Position, 0); //更新库位表中的库位信息
         db.UpdateKuweiArray(con);
         MainWindow.WHOperState = 0;                                //一个动作完成后,将手动动作置为默认
         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.SaveKuweiArray(con, MainWindow.whHandInfo.Position, MainWindow.whHandInfo.TrayStyle); //更新库位表中的库位信息
         db.UpdateKuweiArray(con);
         MainWindow.WHOperState = 0;                                                              //一个动作完成后,将手动动作置为默认
         return;
     }
     if (package.Head == 30005)
     {
         if (package.OutlibMatchingID == 1)
         {
             MainWindow.whUIHandle.WH_OPER_STATE = "已侧边出库";
             LogInfoHelp.GetInstance().WriteInfoToLogFile("已侧边出库", LogInfoHelp.LOG_TYPE.LOG_INFO);
             DataBaseHandle db  = new DataBaseHandle();
             SqlConnection  con = new SqlConnection();
             db.SaveKuweiArray(con, MainWindow.whHandInfo.Position, 0); //更新库位表中的库位信息
             db.UpdateKuweiArray(con);
             MainWindow.WHOperState = 0;                                //一个动作完成后,将手动动作置为默认
             return;
         }
         else if (package.OutlibMatchingID == 2)
         {
             MainWindow.whUIHandle.WH_OPER_STATE = "侧边托盘匹配不成功";
             MessageBox.Show("侧边出库托盘匹配不成功,请检查MES系统的托盘位置和立库实际的托盘位置是否一致,否则RFID读写器可能出现异常");
             LogInfoHelp.GetInstance().WriteInfoToLogFile("侧边托盘匹配不成功", LogInfoHelp.LOG_TYPE.LOG_ERROR);
         }
     }
 }
예제 #19
0
        private void CheckWHNumber(string OrderStyle)
        {
            DataBaseHandle db  = new DataBaseHandle();
            SqlConnection  con = new SqlConnection();
            //检查入库数量
            bool P_InlibNum  = db.JudgeCompleteNum(con, "加工订单");  //小于订单数量就返回true
            bool D_InlibNum  = db.JudgeCompleteNum(con, "检测订单");
            bool A1_InlibNum = db.JudgeCompleteNum(con, "拧螺丝订单");
            bool A2_InlibNum = db.JudgeCompleteNum(con, "轴承压装订单");

            if (P_InlibNum == false)
            {
                MainWindow.orderstate.P_Order    = "";
                DTUSendPackage.P_Order_Enable    = 0;
                DTUSendPackage.Hand_Order_Enabel = 1;
                MainWindow.P_Order_Enable        = false;
            }
            if (D_InlibNum == false)
            {
                MainWindow.orderstate.D_Order = "";
                DTUSendPackage.D_Order_Enable = 0;
                MainWindow.D_Order_Enable     = false;
            }
            if (A1_InlibNum == false)
            {
                MainWindow.orderstate.A1_Order = "";
                DTUSendPackage.A1_Order_Enable = 0;
                MainWindow.A1_Order_Enable     = false;
            }
            if (A2_InlibNum == false)
            {
                MainWindow.orderstate.A2_Order = "";
                DTUSendPackage.A2_Order_Enable = 0;
                MainWindow.A2_Order_Enable     = false;
            }
            if (P_InlibNum == false && D_InlibNum == false && A1_InlibNum == false && A2_InlibNum == false)
            {
                //所有订单都完成了
                //对下订单和执行订单两个按钮解禁。
                OCDelegate();   //触发事件
            }
            if (OrderStyle == "加工订单")
            {
                //检查出库数量
                bool P_OutlibNum    = db.JudgeOutlib(con, "加工订单");       //小于订单数量就返回true
                bool P_PreOutlibNum = db.JudgePreOutlibNum(con, "加工订单"); //小于订单数量就返回
                //检查是否可以继续出库
                bool P_Can_Outlib = P_InlibNum && P_OutlibNum && P_PreOutlibNum;
                if (P_Can_Outlib == true && StateMachine.P_Process_Area1 == 0 && MainWindow.WHMatchingProcess1 == false && StateMachine.P_System_State == 2 && MainWindow.P_Order_Enable == true)
                {
                    db.InsertWHCmd(con, "加工订单", "侧边出库", ConfigClass.Tray_A1);  //侧边出库加工毛坯托盘A1
                    db.InsertWHCmd(con, "加工订单", "出库", ConfigClass.Tray_A0);    //出库加工空托盘A0
                    db.UpdatePreOutlibNum(con, "加工订单");
                    MainWindow.WHMatchingProcess1 = true;
                    return;
                }
                if (P_Can_Outlib == true && StateMachine.P_Process_Area2 == 0 && MainWindow.WHMatchingProcess2 == false && StateMachine.P_System_State == 2 && MainWindow.P_Order_Enable == true)
                {
                    db.InsertWHCmd(con, "加工订单", "侧边出库", ConfigClass.Tray_A1);  //侧边出库加工毛坯托盘A1
                    db.InsertWHCmd(con, "加工订单", "出库", ConfigClass.Tray_A0);    //出库加工空托盘A0
                    db.UpdatePreOutlibNum(con, "加工订单");
                    MainWindow.WHMatchingProcess2 = true;
                    return;
                }
                return;
            }
            if (OrderStyle == "检测订单")
            {
                //检查出库数量
                bool D_OutlibNum    = db.JudgeOutlib(con, "检测订单");
                bool D_PreOutlibNum = db.JudgeOutlib(con, "检测订单");
                //检查是否可以继续出库
                bool D_Can_Outlib = D_InlibNum && D_OutlibNum && D_PreOutlibNum;
                if (D_Can_Outlib == true && StateMachine.D_Detection_Area1 == 0 && MainWindow.WHMatchingDetection1 == false && StateMachine.D_System_State == 2 && MainWindow.D_Order_Enable == true)
                {
                    db.InsertWHCmd(con, "检测订单", "出库", ConfigClass.Tray_A2);   //出库加工成品托盘A2托盘
                    db.UpdatePreOutlibNum(con, "检测订单");
                    MainWindow.WHMatchingDetection1 = true;
                    return;
                }
                if (D_Can_Outlib == true && StateMachine.D_Detection_Area2 == 0 && MainWindow.WHMatchingDetection2 == false && StateMachine.D_System_State == 2 && MainWindow.D_Order_Enable == true)
                {
                    db.InsertWHCmd(con, "检测订单", "出库", ConfigClass.Tray_A2);  //出库加工成品托盘A2托盘
                    db.UpdatePreOutlibNum(con, "检测订单");
                    MainWindow.WHMatchingDetection2 = true;
                    return;
                }
                return;
            }
            if (OrderStyle == "拧螺丝订单")
            {
                //检查出库数量
                bool A1_OutlibNum    = db.JudgeOutlib(con, "拧螺丝订单");
                bool A1_PreOutlibNum = db.JudgePreOutlibNum(con, "拧螺丝订单");
                //检查是否可以继续出库
                bool A1_Can_Outlib = A1_InlibNum && A1_OutlibNum && A1_PreOutlibNum;
                if (A1_Can_Outlib == true && StateMachine.A_Assembly_Area1 == 0 && StateMachine.A_Assembly_InArea1 == 0 && MainWindow.WHMatchingAssembly1 == false && StateMachine.A_System_State == 2 && MainWindow.A1_Order_Enable == true)
                {
                    db.InsertWHCmd(con, "拧螺丝订单", "出库", ConfigClass.Tray_B1);  //出库拧螺钉打钉托盘B1
                    db.UpdatePreOutlibNum(con, "拧螺丝订单");
                    MainWindow.WHMatchingAssembly1 = true;
                    return;
                }
                return;
            }
            if (OrderStyle == "轴承压装订单")
            {
                //检查出库数量
                bool A2_OutlibNum    = db.JudgeOutlib(con, "轴承压装订单");
                bool A2_PreOutlibNum = db.JudgePreOutlibNum(con, "轴承压装订单");
                //检查是否可以继续出库
                bool A2_Can_Outlib = A2_InlibNum && A2_OutlibNum && A2_PreOutlibNum;
                if (A2_Can_Outlib == true && StateMachine.A_Assembly_Area2 == 0 && StateMachine.A_Assembly_InArea2 == 0 && MainWindow.WHMatchingAssembly2 == false && StateMachine.A_System_State == 2 && MainWindow.A2_Order_Enable == true)
                {
                    db.InsertWHCmd(con, "轴承压装订单", "出库", ConfigClass.Tray_A4);  //出库轴承压装毛坯托盘A4
                    db.UpdatePreOutlibNum(con, "轴承压装订单");
                    MainWindow.WHMatchingAssembly2 = true;
                    return;
                }
            }
        }