Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            melsec_net.IpAddress = textBox1.Text;
            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show(DemoUtils.PortInputWrong);
                return;
            }

            melsec_net.Port = port;

            melsec_net.ConnectClose( );

            try
            {
                OperateResult connect = melsec_net.ConnectServer( );
                if (connect.IsSuccess)
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedSuccess);
                    button2.Enabled = true;
                    button1.Enabled = false;
                    panel2.Enabled  = true;
                    userControlReadWriteOp1.SetReadWriteNet(melsec_net, "D100", true);
                }
                else
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedFailed);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            // 连接
            if (!System.Net.IPAddress.TryParse(textBox1.Text, out System.Net.IPAddress address))
            {
                MessageBox.Show("Ip地址输入不正确!");
                return;
            }

            melsec_net.IpAddress = textBox1.Text;

            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show("端口输入格式不正确!");
                return;
            }

            melsec_net.Port = port;

            melsec_net.ConnectClose( );

            try
            {
                OperateResult connect = melsec_net.ConnectServer( );
                if (connect.IsSuccess)
                {
                    MessageBox.Show("连接成功!");
                    button2.Enabled = true;
                    button1.Enabled = false;
                    panel2.Enabled  = true;
                }
                else
                {
                    MessageBox.Show("连接失败!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }