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; } melsecSerial?.ConnectClose( ); melsecSerial = new MelsecFxLinksOverTcp( ); melsecSerial.IpAddress = textBox1.Text; melsecSerial.Port = port; try { melsecSerial.Station = byte.Parse(textBox15.Text); melsecSerial.WaittingTime = byte.Parse(textBox18.Text); melsecSerial.SumCheck = checkBox1.Checked; OperateResult connect = melsecSerial.ConnectServer( ); if (connect.IsSuccess) { MessageBox.Show(HslCommunication.StringResources.Language.ConnectedSuccess); button2.Enabled = true; button1.Enabled = false; panel2.Enabled = true; userControlCurve1.ReadWriteNet = melsecSerial; } else { MessageBox.Show(HslCommunication.StringResources.Language.ConnectedFailed); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public override void DeviceConn(MelsecLinksOverTcpConfig config) { MelsecFxLinksOverTcp linksOverTcp = new MelsecFxLinksOverTcp(); linksOverTcp.IpAddress = config.IP; linksOverTcp.Port = config.Port; linksOverTcp.SumCheck = config.SumCheck; linksOverTcp.Station = config.StationNo; linksOverTcp.WaittingTime = config.WaittingTime; OperateResult connect = linksOverTcp.ConnectServer(); NetworkDevice = linksOverTcp; if (!connect.IsSuccess) { throw new Exception("Connect Failed"); } }
public FormMelsecLinksOverTcp( ) { InitializeComponent( ); melsecSerial = new MelsecFxLinksOverTcp( ); }