FrmSolderingSetting.cs 6.9 KB

using URSoldering.Common;
using URSoldering.DeviceLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;

using System.Windows.Forms;

namespace URSoldering.Client
{
    public partial class FrmSolderingSetting : FrmBase
    {
        public FrmSolderingSetting()
        {
            InitializeComponent();
        } 
        private void btnSaveSetting_Click(object sender, EventArgs e)
        {
            saveValue();
        } 
        private void getValue()
        { 
            int index = -1;
            foreach (BoardInfo obj in BoardManager.boardList)
            {
                index++;
                if (obj.boardId.Equals(BoardManager.CurrBoardId))
                {
                    break;
                } 
            }
            if (index >= 0)
            {
                cmbBoardList.SelectedIndex = index;
            } 
            this.txtOriginX.Text = ConfigAppSettings.GetValue(Setting_Init.BOARD_ORIGIN_X);
            this.txtOriginY.Text = ConfigAppSettings.GetValue(Setting_Init.BOARD_ORIGIN_Y); 
            int ch = WeldRobotBean.SendWireXiShu;
           
            txtLimZ.Text = ((double)ConfigAppSettings.GetNumValue(Setting_Init.Soldering_LIM_Z)).ToString(); 
            txtsendWireSpeed.Text = ConfigAppSettings.GetValue(Setting_Init.ReverseSendWireSpeed);
            txtsendWireTime.Text = ConfigAppSettings.GetValue(Setting_Init.ReverseSendWireTime);

            minControl.ShowPoint(WeldRobotBean.RobotMin);
            maxControl.ShowPoint(WeldRobotBean.RobotMax);

            clear2Control.ShowPoint(WeldRobotBean.Clear2Point);
            clear1Control.ShowPoint(WeldRobotBean.Clear1Point);
            homeControl.ShowPoint(WeldRobotBean.HomePoint);
        }

        private void saveValue()
        {
            try
            { 
                int boardId = ((BoardInfo)cmbBoardList.SelectedItem).boardId;
                BoardManager.UpdateCurrBoard(boardId);
                
                int limz = FormUtil.GetIntValue(txtLimZ);

                List<string> port = new List<string>(SerialPort.GetPortNames());
              
                //if (limz > 0)
                //{
                //    MessageBox.Show("请输入正确的机器人最大Z点(<=0)");
                //    this.txtLimZ.Focus();
                //    txtLimZ.SelectAll();
                //    return; 
                //}
                int sendWireSpeed = FormUtil.GetIntValue(txtsendWireSpeed);
                if (sendWireSpeed >= 0)
                {
                    MessageBox.Show("请输入正确的反转送丝速度!");
                    txtsendWireSpeed.Focus();
                    return;
                }
                int sendWireTime = FormUtil.GetIntValue(txtsendWireTime);
                if (sendWireTime <= 0)
                {
                    MessageBox.Show("请输入正确的反转送丝时间!");
                    txtsendWireTime.Focus();
                    return;
                }


                URPointValue homeP = homeControl.GetPoint();
                //判断原点的Z轴
                if (homeP.Z > limz)
                {
                    MessageBox.Show("待机点Z坐标不能高于最高Z点!");
                    homeControl.Focus(); 
                    return;
                }

                URPointValue clear1P = clear1Control.GetPoint();
                //判断原点的Z轴
                if (clear1P.Z > limz)
                {
                    MessageBox.Show("清洗点1的Z坐标不能高于最高Z点!");
                    clear1Control.Focus(); 
                    return;
                }
                URPointValue clear2P = clear2Control.GetPoint();
                //判断原点的Z轴
                if (clear2P.Z > limz)
                {
                    MessageBox.Show("清洗点2的Z坐标不能高于最高Z点!");
                    clear2Control.Focus(); 
                    return;
                }

                URPointValue minP = minControl.GetPoint();
                URPointValue maxP = maxControl.GetPoint();
 
                //if (XMin > XMax)
                //{
                //    MessageBox.Show("请正确输入机械臂X轴范围!");
                //    txtXMin.Focus();
                //    txtXMin.SelectAll();
                //    return;
                //}
                //if (YMin > YMax)
                //{
                //    MessageBox.Show("请正确输入机械臂Y轴范围!");
                //    txtYMin.Focus();
                //    txtYMin.SelectAll();
                //    return;
                //}
                //if (ZMin > ZMax)
                //{
                //    MessageBox.Show("请正确输入机械臂Z轴范围!");
                //    txtZMin.Focus();
                //    txtZMin.SelectAll();
                //    return;
                //}
                //if (UMin > UMax)
                //{
                //    MessageBox.Show("请正确输入机械臂U轴范围!");
                //    txtUMin.Focus();
                //    txtUMin.SelectAll();
                //    return;
                //}

                WeldRobotBean.UpdateOrgPoint(homeP); 
                WeldRobotBean.UpdateClear1Point(clear1P);
                WeldRobotBean.UpdateClear2Point(clear2P);

                ConfigAppSettings.SaveValue(Setting_Init.Soldering_LIM_Z, limz.ToString());
                URRobotControl.Robot_LIM_Z = limz;

                ConfigAppSettings.SaveValue(Setting_Init.Default_BoardID, boardId);
                BoardManager.UpdateCurrBoard(boardId);

                ConfigAppSettings.SaveValue(Setting_Init.ReverseSendWireSpeed, sendWireSpeed);
                ConfigAppSettings.SaveValue(Setting_Init.ReverseSendWireTime, sendWireTime);
                WeldRobotBean.RobotMin = minP;
                WeldRobotBean.RobotMax = maxP;
                ConfigAppSettings.SaveValue(Setting_Init.Soldering_RobotMin, minP.ToJosonStr());
                ConfigAppSettings.SaveValue(Setting_Init.Soldering_RobotMax, maxP.ToJosonStr());
                
                MessageBox.Show("保存成功,需要重启之后才能生效!");
                this.Close();
            }
            catch
            {
                MessageBox.Show("保存失败!");
            }
        }

        private void FrmRobotSetting_Load(object sender, EventArgs e)
        {
            LoadCom();
            getValue(); 
        }
        private void LoadCom()
        {
            cmbBoardList.DataSource = null;
            cmbBoardList.DataSource = BoardManager.boardList;
            cmbBoardList.DisplayMember = "boardName";
            cmbBoardList.ValueMember = "boardId"; 
        }

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