Exemplo n.º 1
0
        private async 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( );

            button1.Enabled           = false;
            melsec_net.ConnectTimeOut = 3000;             // 连接3秒超时
            OperateResult connect = await melsec_net.ConnectServerAsync( );

            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(connect.Message);
                button1.Enabled = true;
            }
        }
Exemplo n.º 2
0
        public override void DeviceConn(MelsecRBinaryConfig config)
        {
            MelsecMcRNet mcRNet = new MelsecMcRNet();

            mcRNet.IpAddress      = config.IP;
            mcRNet.Port           = config.Port;
            mcRNet.ConnectTimeOut = config.ConnectTimeOut;
            OperateResult connect = mcRNet.ConnectServerAsync().Result;

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