FrmOrgConfig.cs 4.9 KB

using log4net; 
using URSoldering.Common;
using URSoldering.DeviceLibrary;
using System; 
using System.Reflection; 
using System.Windows.Forms;
using System.Threading.Tasks;

namespace URSoldering.Client
{
    public partial class FrmOrgConfig : FrmBase
    { 
        private bool isAuto = false; 
       
        public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        public FrmOrgConfig( )
        {
            InitializeComponent();
        }
        private System.Timers.Timer timer1 = new System.Timers.Timer();
     
        private void FrmBoardInfo_Load(object sender, EventArgs e)
        {
            //CheckForIllegalCrossThreadCalls = false;  
            if (WeldRobotBean.ISRun)
            {
                LogUtil.error("进入焊接界面,发现WeldRobotBean自动运行中,关闭自动运行");
                WeldRobotBean.StopRun();
            } 
            isAuto = false;

            timer1.Interval = 1000;
            timer1.AutoReset = true;
            timer1.Elapsed += timer_Elapsed;
            timer1.Start(); 
        } 
        private bool isRun = false;
        private void timer_Elapsed(object sender, EventArgs e)
        {
            if (!URRobotControl.IsRun && isRun.Equals(false))
            {
                isRun = true;
                Task.Factory.StartNew(delegate ()
                {
                    bool result = URRobotControl.StartRobot(); 
                }); 
            }
            else
            {
                URPointValue lastP = URRobotControl.GetLastPosition();
                urRobotSControl1.ShowPoint(lastP);
            }
            lblMsg.Text = URRobotControl.GetStatus();
           
        }

        private void FrmBoardInfo_FormClosing(object sender, FormClosingEventArgs e)
        {
            URRobotControl.LockAxis(); 
            timer1.Stop(); 
        }
          
         
        protected override void OnVisibleChanged(EventArgs e)
        {
            base.OnVisibleChanged(e);
            if (this.IsDisposed)
            {
                this.Close();
            }
        }

        private void btnSetOrigin_Click(object sender, EventArgs e)
        {
            //URPointValue point = GetCurrRobotPoint();
            //ConfigAppSettings.SaveValue(Setting_Init.BOARD_ORIGIN_X, point.X.ToString());
            //ConfigAppSettings.SaveValue(Setting_Init.BOARD_ORIGIN_Y, point.Y.ToString()); 
        } 
        private void btnSaveHome_Click(object sender, EventArgs e)
        {
            URPointValue point = GetCurrRobotPoint();

            DialogResult result = ShowConfire(point, "原点");
            if (result.Equals(DialogResult.Yes))
            {
                WeldRobotBean.UpdateOrgPoint(point); 
                MessageBox.Show("保存原点成功!");
            }
        }

        private URPointValue GetCurrRobotPoint()
        {
            return urRobotSControl1.GetPoint();
        }

        private void btnSetClear1_Click(object sender, EventArgs e)
        {
            URPointValue point = GetCurrRobotPoint();
            DialogResult result = ShowConfire(point, "清洗点1");
            if (result.Equals(DialogResult.Yes))
            {
                WeldRobotBean.UpdateClear1Point(point);
                MessageBox.Show("保存清洗点1成功!");
            }
        }

        private DialogResult ShowConfire(URPointValue point, string strMsg)
        {
            //判断原点的Z轴
            //if (point.Z > URRobotControl.Robot_LIM_Z)
            //{
            //    MessageBox.Show("保存失败,"+ strMsg + "的Z坐标(" + point.Z + ")不能高于最高Z点(" + URRobotControl.Robot_LIM_Z + ")");
            //    return DialogResult.Cancel;
            //}
            if (!URRobotControl.IsValidZ(point.Z))
            {
                MessageBox.Show("保存失败,焊点Z坐标(" + point.Z + ")不能低于最低Z点(" + URRobotControl.Robot_LIM_Z + ")");
                return DialogResult.Cancel;
            }

            DialogResult result = MessageBox.Show("是否将当前位置:" + point.ToShowStr() + "保存为" + strMsg + "?", "提示", MessageBoxButtons.YesNo);
            return result;
        }

        private void btnSetClear2_Click(object sender, EventArgs e)
        {
            URPointValue point = GetCurrRobotPoint();

            DialogResult result = ShowConfire(point, "清洗点2");
            if (result.Equals(DialogResult.Yes))
            {
                WeldRobotBean.UpdateClear2Point(point);
                MessageBox.Show("保存清洗点2成功!");
            }
        }  

        private void btnBack_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnMore_Click(object sender, EventArgs e)
        {  
            FrmPwd frmOrgConfig = new FrmPwd(3);
            this.Visible = false;
            frmOrgConfig.ShowDialog();
            this.Visible = true;
        }
    }
}