Example #1
0
 private void button2_Click(object sender, EventArgs e)
 {
     // 断开连接
     vigor.ConnectClose( );
     button2.Enabled = false;
     button1.Enabled = true;
     panel2.Enabled  = false;
 }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show(DemoUtils.PortInputWrong);
                return;
            }

            vigor?.ConnectClose( );
            vigor           = new VigorSerialOverTcp( );
            vigor.IpAddress = textBox1.Text;
            vigor.Port      = port;

            try
            {
                vigor.Station = byte.Parse(textBox15.Text);
                OperateResult connect = vigor.ConnectServer( );
                if (connect.IsSuccess)
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedSuccess);

                    button2.Enabled = true;
                    button1.Enabled = false;
                    panel2.Enabled  = true;

                    userControlReadWriteOp1.SetReadWriteNet(vigor, "D100", true);
                }
                else
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedFailed);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }