private void button1_Click(object sender, EventArgs e)
        {
            melsec_net.IpAddress = textBox1.Text;
            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show(DemoUtils.PortInputWrong);
                return;
            }

            melsec_net.Port = port;
            melsec_net.ConnectClose( );

            try
            {
                OperateResult connect = melsec_net.ConnectServer( );
                if (connect.IsSuccess)
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedSuccess);
                    button2.Enabled = true;
                    button1.Enabled = false;
                    panel2.Enabled  = true;
                    userControlReadWriteOp1.SetReadWriteNet(melsec_net, "D100", true);
                }
                else
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedFailed);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #2
0
        public override void DeviceConn(MelsecA1EAsciiNetConfig config)
        {
            melsec_net           = new MelsecA1EAsciiNet();
            melsec_net.IpAddress = config.IP;
            melsec_net.Port      = config.Port;
            if (!System.Net.IPAddress.TryParse(config.IP, out System.Net.IPAddress address))
            {
                throw new Exception("IpAddress input wrong");
            }

            melsec_net.ConnectClose();
            OperateResult connect = melsec_net.ConnectServer();

            if (!connect.IsSuccess)
            {
                throw new Exception("Connect Failed");
            }
        }