private void button2_Click(object sender, EventArgs e)
 {
     // 断开连接
     panasonicMewtocol.ConnectClose( );
     button2.Enabled = false;
     button1.Enabled = true;
     panel2.Enabled  = false;
 }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!System.Net.IPAddress.TryParse(textBox1.Text, out System.Net.IPAddress address))
            {
                MessageBox.Show(DemoUtils.IpAddressInputWrong);
                return;
            }

            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show(DemoUtils.PortInputWrong);
                return;
            }


            if (!byte.TryParse(textBox15.Text, out byte station))
            {
                MessageBox.Show("Plc Station input wrong!");
                return;
            }

            panasonicMewtocol?.ConnectClose( );
            panasonicMewtocol           = new PanasonicMewtocolOverTcp(station);
            panasonicMewtocol.IpAddress = textBox1.Text;
            panasonicMewtocol.Port      = port;


            try
            {
                OperateResult connect = panasonicMewtocol.ConnectServer( );
                if (connect.IsSuccess)
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedSuccess);
                    button2.Enabled = true;
                    button1.Enabled = false;
                    panel2.Enabled  = true;
                    userControlCurve1.ReadWriteNet = panasonicMewtocol;
                }
                else
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedFailed);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }