public override void DeviceConn(PanasonicMewtocolOverTcpConfig config) { PanasonicMewtocolOverTcp panasonicMewtocol = new PanasonicMewtocolOverTcp(config.StationNo); panasonicMewtocol.IpAddress = config.IP; panasonicMewtocol.Port = config.Port; OperateResult connect = panasonicMewtocol.ConnectServer(); NetworkDevice = panasonicMewtocol; if (!connect.IsSuccess) { throw new Exception("Connect Failed"); } }
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); } }