MainMachine _BtnProcess.cs 6.4 KB
using CodeLibrary;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DeviceLibrary
{
    partial class MainMachine
    {
        void BtnProcess()
        { 
            
        }
        void Reset_BTN() {
            if (IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.HIGH))
            {
                Msg.add(crc.GetString(L.reset_press, "按下复位按钮."), MsgLevel.info, ErrInfo.ResetBtn);
                ButtenEvent?.Invoke(null, ErrInfo.ResetBtn);
            }
            else
            {
                Msg.add(crc.GetString(L.reset_press_with_sudden, "急停未解除,按下复位按钮尝试复位安全继电器."), MsgLevel.info, ErrInfo.SuddenStop);
            }

            LogUtil.info("按下复位按钮");
            ProcessMsgEvent?.Invoke(Msg.get());

            //暂停时按下reaet按钮
            if (RobotManage.isRunning && RobotManage.mainMachine.UserPause)
            {
                RobotManage.UserPause("Reset_BTN", false);
            }
        }
        void HomeReset_BTN()
        {
            if (IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.HIGH))
            {
                Msg.add(crc.GetString("Res0009", "按下复位按钮."), MsgLevel.info, ErrInfo.ResetBtn);
            }
            else
            {
                Msg.add(crc.GetString("Res0010", "急停未解除,按下复位按钮尝试复位安全继电器."), MsgLevel.info, ErrInfo.SuddenStop);
            }
            LogUtil.info("长按下复位按钮,系统不在运行,开始启动");
            if (RobotManage.isRunning)
            {
                LogUtil.info("长按下复位按钮,系统正在运行,开始停止");
                ButtenEvent?.Invoke(null, ErrInfo.SuddenStop);
                while (RobotManage.isRunning) { 
                    Thread.Sleep(100);
                }
            }
            if (RobotManage.mainMachine.Loading_Batch_Axis.HasHomeSignal()
                    && (RobotManage.mainMachine.Loading_Batch_Axis.IsInPosition(RobotManage.mainMachine.Config.Loading_Batch_Axis_P1)
                    || RobotManage.mainMachine.Loading_Batch_Axis.IsInPosition(0))
                    )
            {
                LogUtil.info("入口批量轴在待机点或原点可以开始回原");
            }
            else if (RobotManage.mainMachine.LoadingCarOnPosition == MainMachine.CarPosition.OnPosition && RobotManage.mainMachine.IOValue(IO_Type.Loading_Car_Location_Up).Equals(IO_VALUE.HIGH) && RobotManage.mainMachine.Loading_Batch_Axis.HasHomeSignal())
            {
                LogUtil.info("入料车没有离开");
            }
            else
            {
                Msg.add("入料车没有取出,无法回原", MsgLevel.warning);
                return;
            }
            if (RobotManage.mainMachine.Unloading_Batch_Axis.HasHomeSignal()
                && (RobotManage.mainMachine.Unloading_Batch_Axis.IsInPosition(RobotManage.mainMachine.Config.Unloading_Batch_Axis_P1)
                || RobotManage.mainMachine.Unloading_Batch_Axis.IsInPosition(0))
                )
            {
                LogUtil.info("出口批量轴在待机点或原点可以开始回原");
            }
            else if (RobotManage.mainMachine.UnloadingCarOnPosition == MainMachine.CarPosition.OnPosition && RobotManage.mainMachine.IOValue(IO_Type.Unloading_Car_Location_Up).Equals(IO_VALUE.HIGH) && RobotManage.mainMachine.Unloading_Batch_Axis.HasHomeSignal())
            {
                LogUtil.info("出料车没有离开");
            }
            else
            {

                Msg.add("出料车没有取出,无法回原", MsgLevel.warning);
                return;

            }


            Thread.Sleep(1000);
            LogUtil.info("长按下复位按钮,开始清除报警");
            AxisBean.List.ForEach((x) => { AxisManager.AlarmClear(x.Config.DeviceName, x.Config.GetAxisValue()); });
            Thread.Sleep(100);
            LogUtil.info("长按下复位按钮,打开伺服");
            AxisBean.List.ForEach((x) => { x.Open(true,out _); });
            Thread.Sleep(100);
            LogUtil.info("长按下复位按钮,开始回原");

            Loading_UpDown_Axis.HomeMove(null, true);
            Unloading_UpDown_Axis.HomeMove(null, true);
            while (!Loading_UpDown_Axis.IsHomeMoveEnd || !Unloading_UpDown_Axis.IsHomeMoveEnd) {
                Thread.Sleep(500);
            }
            Loading_InOut_Axis.HomeMove(null, true);
            Unloading_InOut_Axis.HomeMove(null, true);
            while (!Loading_InOut_Axis.IsHomeMoveEnd || !Unloading_InOut_Axis.IsHomeMoveEnd)
            {
                Thread.Sleep(500);
            }
            Label_Z_Axis.HomeMove(ResetMoveInfo, forceHome);
            while (!Label_Z_Axis.IsHomeMoveEnd)
            {
                Thread.Sleep(500);
            }
            Label_X_Axis.HomeMove(ResetMoveInfo, forceHome);
            while (!Label_X_Axis.IsHomeMoveEnd)
            {
                Thread.Sleep(500);
            }
            Label_R_Axis.HomeMove(ResetMoveInfo, forceHome);
            while (!Label_R_Axis.IsHomeMoveEnd)
            {
                Thread.Sleep(500);
            }            
            Label_Y_Axis.HomeMove(ResetMoveInfo, forceHome);
            while (!Label_Y_Axis.IsHomeMoveEnd)
            {
                Thread.Sleep(500);
            }
            Thread.Sleep(500);
            AxisBean.List.ForEach((x) => { x.HomeMove(null,true); });
        }
        void Run_BTN() {
            if (IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.HIGH))
            {
                if (!RobotManage.isRunning)
                {
                    Msg.add(crc.GetString(L.runbtn_press, "按下启动按钮,开始启动."), MsgLevel.info, ErrInfo.RunBtn);
                    ButtenEvent?.Invoke(null, ErrInfo.RunBtn);
                }
                else
                    Msg.add(crc.GetString(L.system_is_running, "系统正在运行."), MsgLevel.info);
            }
            else 
            {
                Msg.add(crc.GetString(L.runbtn_press_with_sudden, "急停中,按下启动按钮,无法启动."), MsgLevel.warning);
            }
            LogUtil.info("按下启动按钮");
            ProcessMsgEvent?.Invoke(Msg.get());
        }
    }
}