FrmBatchMove.cs 12.0 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.CompilerServices;
using System.Threading;
using System.IO;
using System.Runtime.InteropServices;
using OnlineStore.DeviceLibrary;
using log4net;
using System.Reflection;
using UserFromControl;
using OnlineStore.LoadCSVLibrary;
using OnlineStore.Common;

namespace OnlineStore.XLRStore
{
    internal partial class FrmBatchMove : FrmBase
    {
        private bool IsLoad = false;

        private BatchMoveBean moveBean;
        internal FrmBatchMove(BatchMoveBean moveEquip)
        {
            this.moveBean = moveEquip;
            Control.CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
        }

        private bool IsInCheck = false;
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                if (!this.Visible)
                {
                    return;
                }
                lblWarnMsg.Text = moveBean.WarnMsg;
                lblCurrInfo.Text = moveBean.GetMoveStr();
                string text = "AGV " + moveBean.Config.AgvName + " :" + AgvClient.GetAction(moveBean.Config.AgvName);
                if (StoreManager.XLRStore.inputEquip.runStatus > RunStatus.Wait)
                {
                    btnReset.Enabled = true;
                }
                else
                {
                    btnReset.Enabled = true;
                }

                text += "\r\n" + moveBean.MoveInfo.MoveType + "_" + moveBean.MoveInfo.MoveStep;
                text += "\r\n" + moveBean.CurrShelf?.ToStr();
                lblAgvInfo.Text = text;
            }
            catch (Exception ex)
            {
                LogUtil.error(moveBean.Name + "界面定时器出错:", ex);
            }

        }

        private void FrmTest_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (this.timer1.Enabled)
                {
                    this.timer1.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace, "Exception(异常)", MessageBoxButtons.OK, MessageBoxIcon.Error);
                LogUtil.error("", ex);
            }
        }

        private void FrmStoreIOStatus_Load(object sender, EventArgs e)
        {
            this.chbAutoOut.Checked = moveBean.ShelfAutoOut;
            axisMoveControl1.LoadData(StoreManager.XLRStore.inputEquip, new AxisBean[] { moveBean.BatchAxis });

            batchAxisP1.SetMoveData(moveBean.BatchAxis, StoreManager.XLRStore.inputEquip.Config.BatchAxis_P1Speed, moveBean.Config.BatchAxisP1);
            batchAxisP2.SetMoveData(moveBean.BatchAxis, StoreManager.XLRStore.inputEquip.Config.BatchAxis_P2Speed, moveBean.Config.BatchAxisP2);
            batchAxisP4.SetMoveData(moveBean.BatchAxis, StoreManager.XLRStore.inputEquip.Config.BatchAxis_P4Speed, moveBean.Config.BatchAxisP4, true);

            lblWarnMsg.Text = moveBean.WarnMsg;
            lblCurrInfo.Text = moveBean.GetMoveStr();
            lblAgvInfo.Text = "AGV " + moveBean.Config.AgvName + " :" + AgvClient.GetAction(moveBean.Config.AgvName);
            IsLoad = true;
        }



        private void FrmIOStatus_Shown(object sender, EventArgs e)
        {
            timer1.Start();
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            moveBean.Reset(true);
            LogUtil.info(moveBean.Name + "点击:" + btnReset.Text);
        }


        private void btnSave_Click(object sender, EventArgs e)
        {
            int p1 = batchAxisP1.PointValue;
            int p2 = batchAxisP2.PointValue;
            int p4 = batchAxisP4.PointValue;

            if (p4 < 0)
            {
                MessageBox.Show("扫码时上升高度P4不能小于0 ,请重新设置P4点位置", "保存失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            moveBean.Config.BatchAxisP1 = p1;
            moveBean.Config.BatchAxisP2 = p2;
            moveBean.Config.BatchAxisP4 = p4;
            if (moveBean.ShelfType.Equals(1))
            {
                StoreManager.XLRStore.inputEquip.Config.BatchAxisP1_A = p1;
                StoreManager.XLRStore.inputEquip.Config.BatchAxisP2_A = p2;
                StoreManager.XLRStore.inputEquip.Config.BatchAxisP4_A = p4;

            }
            else
            {

                StoreManager.XLRStore.inputEquip.Config.BatchAxisP1_B = p1;
                StoreManager.XLRStore.inputEquip.Config.BatchAxisP2_B = p2;
                StoreManager.XLRStore.inputEquip.Config.BatchAxisP4_B = p4;
            }
            StoreManager.SaveInputEquipConfig(StoreManager.XLRStore.inputEquip.Config);
            MessageBox.Show("保存成功");
        }
        private int TargetP2;
        private bool StartTest = false;
        private void btnStartTest_Click(object sender, EventArgs e)
        {
            ConfigMoveAxis moveAxis = moveBean.BatchAxis.Config;
            bool isServoOn = AxisManager.instance.IsServeoOn(moveAxis.DeviceName, moveAxis.GetAxisValue());
            if (!isServoOn)
            {
                MessageBox.Show(moveAxis.Explain + " 未打开,请先打开伺服 ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            bool isStop = AxisManager.instance.GetBusyStatus(moveAxis.DeviceName, moveAxis.GetAxisValue()).Equals(0);
            if (isServoOn && isStop)
            {
                //判断提升轴是否停止且到位 
                TargetP2 = moveBean.Config.BatchAxisP2;
                LogUtil.info(moveBean.Name + "点击:" + btnStartTest.Text + ",目标位置:" + moveBean.Config.BatchAxisP2);
                moveBean.BatchAxisToP2(true, false, true);
                lblTestMsg.Text = "开始入料运动,目标位置[" + TargetP2 + "] ,开始位置[" + moveBean.StartMovePosition + "],";
                StartTest = true;
            }
            else
            {
                MessageBox.Show(moveAxis.Explain + " 忙碌中,无法开始运动 ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }

        private void btnTestStop_Click(object sender, EventArgs e)
        {
            LogUtil.info(moveBean.Name + "点击:" + btnTestStop.Text);
            moveBean.BatchAxis.AxisStopCheckMove();
            moveBean.BatchAxis.SuddenStop();
        }

        private void BatchTimerPro()
        {
            if (moveBean.BatchAxis.IsBatchMove())
            {
                btnStartTest.Enabled = false;
                if (moveBean.LastMoveIsTest)
                {
                    ConfigMoveAxis moveAxis = moveBean.BatchAxis.Config;
                    bool countError = false;
                    bool isStop = false;
                    bool result = AxisManager.instance.AbsMoveIsEnd(moveAxis.DeviceName, moveAxis.GetAxisValue(), TargetP2, moveAxis.CanErrorCountMax, out countError);
                    if (result)
                    {
                        isStop = true;
                        LogUtil.info(moveBean.Name + "提升轴上料功能测试,发现提升轴已到达目标位置【" + TargetP2 + "】,停止上料测试 ");
                    }
                    else
                    {
                        bool axisMoveIsEnd = HuichuanLibrary.HCBoardManager.MoveIsEnd(moveBean.BatchAxis.Config.GetAxisValue());
                        if (axisMoveIsEnd)
                        {
                            isStop = true;
                            LogUtil.info(moveBean.Name + "提升轴上料功能测试,发现提升轴已停止运动,停止上料测试");
                        }
                    }
                    if (isStop)
                    {
                        StartTest = false;
                        moveBean.BatchAxis.AxisStopCheckMove();
                        btnStartTest.Enabled = true;
                        btnTestStop.Enabled = false;
                        int height = moveBean.GetHeight();
                        lblTestMsg.Text = "目标位置[" + TargetP2 + "] ,开始位置[" + moveBean.StartMovePosition + "],停止位置[" + moveBean.EndMovePosition + "],高度[" + height + "]mm";
                    }
                    else
                    {
                        btnTestStop.Enabled = true;
                    }
                }
                else
                {
                    btnTestStop.Enabled = false;
                }
            }
            else
            {
                if (StartTest)
                {
                    StartTest = false;
                    int height = moveBean.GetHeight();
                    lblTestMsg.Text = "目标位置[" + TargetP2 + "] ,开始位置[" + moveBean.StartMovePosition + "],停止位置[" + moveBean.EndMovePosition + "],高度[" + height + "]mm";

                }
                btnStartTest.Enabled = true;
                btnTestStop.Enabled = false;
            }
        }

        private void chbAutoOut_CheckedChanged(object sender, EventArgs e)
        {
            if (!IsLoad)
            {
                return;
            }

            moveBean.ShelfAutoOut = chbAutoOut.Checked;
            LogUtil.info(moveBean.Name + "用户切换料架入库完成自动出库: " + moveBean.ShelfAutoOut);
        }

        private void btnShelfOut_Click(object sender, EventArgs e)
        {
            if (!IsLoad)
            {
                return;
            }

            moveBean.ShelfNeedLeave = true;
            LogUtil.info(moveBean.Name + "用户点击:" + btnShelfOut.Text);
        }

        private void btnScanTest_Click(object sender, EventArgs e)
        {
            if (!IsLoad)
            {
                return;
            }
            string camera = moveBean.Config.CameraName;
            List<string> LastCodeList = CodeManager.CameraScan(camera, moveBean.Name.Trim() + "测试");
            string msg = CodeManager.ProcessCode(LastCodeList);
            LogUtil.info(moveBean.Name + "[" + camera + "]扫码测试结果:\r\n" + msg);
            MessageBox.Show(moveBean.Name + "[" + camera + "]扫码测试结果:" + msg);

        }

        private void Shelf_StopUp_A_Click(object sender, EventArgs e)
        {
            LogUtil.info(moveBean.Name + "点击:" + Shelf_StopUp_A.Text);
            moveBean.StopUp();
        }

        private void Shelf_StopDown_A_Click(object sender, EventArgs e)
        {
            LogUtil.info(moveBean.Name + "点击:" + Shelf_StopDown_A.Text);
            moveBean.StopDown();
        }

        private void LineStart_A_Click(object sender, EventArgs e)
        {
            LogUtil.info(moveBean.Name + "点击:" + LineStart_A.Text);
            moveBean.LineRun();
        }

        private void LineBack_A_Click(object sender, EventArgs e)
        {
            LogUtil.info(moveBean.Name + "点击:" + LineBack_A.Text);
            moveBean.LineBack();
        }

        private void LineStop_A_Click(object sender, EventArgs e)
        {
            LogUtil.info(moveBean.Name + "点击:" + LineStop_A.Text);
            moveBean.LineStop();

        }

        private void btnResetShelf_Click(object sender, EventArgs e)
        {
            LogUtil.info(moveBean.Name + "点击:" + btnResetShelf.Text);
            moveBean.Reset(true,true);
        }

        private void chbMoveStop_CheckedChanged(object sender, EventArgs e)
        {
            if (!IsLoad)
            {
                return;
            }

            moveBean.MoveStop = chbMoveStop.Checked;
            LogUtil.info(moveBean.Name + "用户切换是否暂停: " + moveBean.MoveStop);
        }
        public void ShowConfig(bool state)
        {
            axisMoveControl1.Visible = state;
            groupBox1.Visible = state;
            groupBox2.Visible = state;
            groupBox3.Visible = state;
            chbAutoOut.Visible = state;
        }
    }

}