FrmMesConfig.cs 5.9 KB

using LineSoldering.Common;
using LineSoldering.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 LineSoldering.Client
{
    public partial class FrmMesConfig : FrmBase
    {
        public FrmMesConfig()
        {
            InitializeComponent();
        }

        private void btnSaveSetting_Click(object sender, EventArgs e)
        {
            saveValue();
        }


        private void getValue()
        {
            this.txtEMSIP.Text = RobotManager.SolderingRobot.MesIp.ToString();
            this.txtPort.Text = RobotManager.SolderingRobot.MesPort.ToString();
        }

        private void saveValue()
        {
            try
            { 
                int port = FormUtil.GetIntValue(txtPort); 
                string ip = FormUtil.getValue(txtEMSIP);  
                if (!FormUtil.IsIp(ip))
                {
                    MessageBox.Show("请输入正确IP");
                    txtEMSIP.Focus();
                    txtEMSIP.SelectAll();
                    return;
                }
                 
                if (port <= 0)
                {
                    MessageBox.Show("请输入正确端口号");
                    txtPort.Focus();
                    txtPort.SelectAll();
                    return;
                }
                ConfigAppSettings.SaveValue(Setting_Init.Mes_IP, ip);
                ConfigAppSettings.SaveValue(Setting_Init.Mes_Port, port);
                ConfigAppSettings.SaveValue(Setting_Init.Mes_IsConnect, chbIsConnect.Checked);
                MesUtil.NeedConnect = chbIsConnect.Checked;
                RobotManager.SolderingRobot.MesIp = ip;
                RobotManager.SolderingRobot.MesPort = port;
                MessageBox.Show("保存成功!");
                this.Close();
            }
            catch
            {
                MessageBox.Show("保存失败!");
            }
        }

        private void FrmRobotSetting_Load(object sender, EventArgs e)
        {
            LogUtil.logBox = this.richTextBox1;
            this.chbIsConnect.Checked = MesUtil.NeedConnect;
            getValue(); 
        } 
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnConnect_Click(object sender, EventArgs e)
        {
            MesUtil.RivetInit(RobotManager.SolderingRobot.MesIp, RobotManager.SolderingRobot.MesPort);

        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            MesUtil.Close();
        }

        private void FrmConfig_FormClosed(object sender, FormClosedEventArgs e)
        {
            MesUtil.Close();
            LogUtil.logBox = null;
        }
        string preCode = "";
        private void btnCheckCode_Click(object sender, EventArgs e)
        {
            string code = FormUtil.getValue(txtCode);
            LogUtil.info("铆压发送二维码验证: 【" + code + "】 ");
            MesUtil.ConfirmCode(code, CodeResult);
            preCode = code;
        }
        private void CodeResult(string code1, string result1, string code2, string result2)
        { 
            LogUtil.info(  "收到验证结果, 【" + code1 + "】【" + result1 + "】【" + code2 + "】【" + result2 + "】 ");
            preCode = code1;
        }

        private void btnSendResult_Click(object sender, EventArgs e)
        {
            int result = FormUtil.GetIntValue(txtResult);
            double value = FormUtil.getDoubleValue(txtPressValue);
            MesUtil.UploadRivetResult(preCode, result, value);
            LogUtil.info("上传铆压结果, 二维码【" + preCode + "】结果【" + result + "】压力值【"+value+"】 ");
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Clear();
        }

        private void btnSConnect_Click(object sender, EventArgs e)
        {
            MesUtil.SolderInit(RobotManager.SolderingRobot.MesIp, RobotManager.SolderingRobot.MesPort);
        }

        private void btnSStop_Click(object sender, EventArgs e)
        {
            MesUtil.Close();
        }

        private void btnSCheck_Click(object sender, EventArgs e)
        {
            string code = FormUtil.getValue(txtCode);
            string code2 = FormUtil.getValue(txtSCode2);
            LogUtil.info("焊接发送二维码验证: 【" + code + "】【"+code2+"】 ");
            MesUtil.ConfirmSolderCode(code,code2, CodeResult);
            preCode = code2;
        }

        private void btnSSend_Click(object sender, EventArgs e)
        {
            int result = FormUtil.GetIntValue(txtResult );
            MesUtil.UploadSolderResult(FormUtil.getValue(txtCode), FormUtil.getValue(txtSCode2), result);
            LogUtil.info("上传焊接结果, 二维码【" + preCode + "】结果【" + result + "】  ");
        }

        private void btnScrewStop_Click(object sender, EventArgs e)
        { 
            MesUtil.Close();
        }

        private void btnScrewConnect_Click(object sender, EventArgs e)
        {
            MesUtil.ScrewInit(RobotManager.SolderingRobot.MesIp, RobotManager.SolderingRobot.MesPort);
        }

        private void btnScrewCheck_Click(object sender, EventArgs e)
        {
            string code = FormUtil.getValue(txtCode);

            LogUtil.info("锁付发送二维码验证: 【" + code + "】  ");
            MesUtil.ConfirmCode(code, CodeResult);
            preCode = code;
        }

        private void btnScrewSend_Click(object sender, EventArgs e)
        {
            int result = FormUtil.GetIntValue(txtResult);
            MesUtil.UploadScrewResult(preCode, RESULT.OK, new List<double> { 11.1, 22.2, 33.3, 44.4, 55.5 });
            LogUtil.info("上传焊接结果, 二维码【" + preCode + "】结果【" + result + "】  ");
        }
    }
}