AgvControl.cs 7.0 KB
using DeviceLibrary;
using DL.StandardRobot;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AutoScanAndLabel.UC
{
    public partial class AgvControl : UserControl
    {
        public string serverIp = "";
        public AgvControl()
        {
            InitializeComponent();
            serverIp = ConfigAppSettings.GetValue(Setting_Init.STD_IP);
            AGVManager.Connect(serverIp);
            load();
            groupBox2.Text = $"AGV状态[{serverIp}]";
            AGVManager.Register(MissionStateChanged);
            endit(false);
        }
        ~AgvControl()
        {
            AGVManager.UnRegister(MissionStateChanged);
            AGVManager.Close();
        }
        private void load()
        {
            txtEnterId.Text=ConfigAppSettings.GetValue(Setting_Init.ShelfInAGV);
            txtLeaveId.Text = ConfigAppSettings.GetValue(Setting_Init.ShelfOutAGV);
            txtMoveLSTId.Text = ConfigAppSettings.GetValue(Setting_Init.LStation);

            txtMoveRSTId.Text = ConfigAppSettings.GetValue(Setting_Init.RStation);
        }
        private void save()
        {
            ConfigAppSettings.SaveValue(Setting_Init.ShelfInAGV, txtEnterId.Text);
            ConfigAppSettings.SaveValue(Setting_Init.ShelfOutAGV, txtLeaveId.Text);
            ConfigAppSettings.SaveValue(Setting_Init.LStation, $"{txtMoveLSTId.Text}");
            ConfigAppSettings.SaveValue(Setting_Init.RStation, $"{txtMoveRSTId.Text}");
        }
        private void MissionStateChanged(MissionState state)
        {
            if (!this.IsHandleCreated) return;
            this.Invoke(new Action(() =>
            {
                try
                {
                    lblCurMissionId.Text = $"当前任务编号:{state.MissionId}";
                    lblCurRunMissionId.Text = $"运行任务编号:{state.RunMissionId}";
                    lblMissionRunstate.Text = $"任务运行状态:{state.MissionRunState}";
                    lblMissionResult.Text = $"任务运行结果:{state.MissionResult}";
                }
                catch
                {

                }
            }));
        }
        private void button_rightneedempty_Click(object sender, EventArgs e)
        {
            if (!RobotManage.isRunning)
            {
                MessageBox.Show("机器尚未启动不能呼叫Agv");
                return;
            }

            if (RobotManage.mainMachine.IOValue(IO_Type.RightEnd_Check).Equals(IO_VALUE.LOW))
            {
                //请求AGV代码放这里
                //等待agv到位
                RobotManage.mainMachine.RightMoveInfo.NewMove(MoveStep.R40_InShelf);//等待agv到位后执行,启动进入

                Task.Run(() =>
                {
                    while (RobotManage.mainMachine.RightMoveInfo.MoveStep >= MoveStep.R40_InShelf)
                    {
                        Task.Delay(1000).Wait();
                    }
                    //通知agv上料结束, 也可以把上料结束的代码放到 R40_InShelf的结束步骤里去
                });
            }
            else
                MessageBox.Show("当前有料串不能请求进入料串");
        }

        private void button_rightleavefull_Click(object sender, EventArgs e)
        {
            if (!RobotManage.isRunning)
            {
                MessageBox.Show("机器尚未启动不能呼叫Agv");
                return;
            }
            if (RobotManage.mainMachine.IOValue(IO_Type.RightEnd_Check).Equals(IO_VALUE.HIGH))
            {
                //请求AGV代码放这里
                //等待agv到位
                RobotManage.mainMachine.RightMoveInfo.NewMove(MoveStep.R30_OutShelf);//等待agv到位后执行,启动料串离开 
                Task.Run(() =>
                {
                    while (RobotManage.mainMachine.RightMoveInfo.MoveStep >= MoveStep.R30_OutShelf)
                    {
                        Task.Delay(1000).Wait();
                    }
                    //通知agv上料结束, 也可以把上料结束的代码放到R30_OutShelf的结束步骤里去
                });
            }
            else
                MessageBox.Show("当前没有料串不能请求取料串");
        }

        private void button_Leftleavefull_Click(object sender, EventArgs e)
        {
            if (!RobotManage.isRunning)
            {
                MessageBox.Show("机器尚未启动不能呼叫Agv");
                return;
            }
            if (RobotManage.mainMachine.IOValue(IO_Type.LeftEnd_Check).Equals(IO_VALUE.HIGH))
            {
                //请求AGV代码放这里
                //等待agv到位
                RobotManage.mainMachine.LeftMoveInfo.NewMove(MoveStep.L50_OutShelf);//等待agv到位后执行,启动料串离开 
                Task.Run(() =>
                {
                    while (RobotManage.mainMachine.LeftMoveInfo.MoveStep >= MoveStep.L50_OutShelf)
                    {
                        Task.Delay(1000).Wait();
                    }
                    //通知agv上料结束, 也可以把上料结束的代码放到L50_OutShelf的结束步骤里去
                });
            }
            else
                MessageBox.Show("当前没有料串不能请求取料串");
        }

        private void button_leftneedempty_Click(object sender, EventArgs e)
        {
            if (!RobotManage.isRunning)
            {
                MessageBox.Show("机器尚未启动不能呼叫Agv");
                return;
            }
            if (RobotManage.mainMachine.IOValue(IO_Type.LeftEnd_Check).Equals(IO_VALUE.LOW))
            {
                //请求AGV代码放这里
                //等待agv到位
                RobotManage.mainMachine.LeftMoveInfo.NewMove(MoveStep.L60_InShelf);//等待agv到位后执行,启动进入
                Task.Run(() =>
                {
                    while (RobotManage.mainMachine.LeftMoveInfo.MoveStep >= MoveStep.L60_InShelf)
                    {
                        Task.Delay(1000).Wait();
                    }
                    //通知agv上料结束, 也可以把上料结束的代码放到 L60_InShelf的结束步骤里去
                });
            }
            else
                MessageBox.Show("当前有料串不能请求进入料串");
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            save();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            endit(checkBox1.Checked);
        }
        void endit(bool maul)
        {
            groupBox3.Enabled = maul;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int.TryParse(txtMissionId.Text,out int val);
            AGVManager.AddMission(val);
        }
    }
}