private void button1_Click(object sender, EventArgs e) { keyence_net.IpAddress = textBox1.Text; if (!int.TryParse(textBox2.Text, out int port)) { MessageBox.Show(DemoUtils.PortInputWrong); return; } keyence_net.Port = port; keyence_net.ConnectClose( ); try { OperateResult connect = keyence_net.ConnectServer( ); if (connect.IsSuccess) { MessageBox.Show(HslCommunication.StringResources.Language.ConnectedSuccess); button2.Enabled = true; button1.Enabled = false; panel2.Enabled = true; userControlReadWriteOp1.SetReadWriteNet(keyence_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; } keyence_net.IpAddress = textBox1.Text; if (!int.TryParse(textBox2.Text, out int port)) { MessageBox.Show("端口输入格式不正确!"); return; } keyence_net.Port = port; keyence_net.ConnectClose( ); try { OperateResult connect = keyence_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); } }