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);
            }
        }
Esempio n. 2
0
        public override void DeviceConn(KeyenceMcNetConfig config)
        {
            KeyenceMcNet keyenceMc = new KeyenceMcNet();

            keyenceMc.IpAddress = config.IP;
            keyenceMc.Port      = config.Port;
            OperateResult connect = keyenceMc.ConnectServer();

            NetworkDevice = keyenceMc;
            if (!connect.IsSuccess)
            {
                throw new Exception("Connect Failed");
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
File: DevicePlc.cs Progetto: Gz1d/Gz
        //KeyencePLC初始化
        void DoInitKeyencePlc(LD.Config.PlcTypeItem item)
        {
            KeyenceMcNet KeyencePLC = new KeyenceMcNet(item.IP, item.Port);

            KeyencePLC.ConnectTimeOut = item.ConnectOutTime;
            item.Tag = KeyencePLC;
            if (KeyencePLC != null)
            {
                KeyencePLC.ConnectClose();
            }
            OperateResult connect = KeyencePLC.ConnectServer();

            if (connect.IsSuccess)
            {
                item.IsConnected = true;
            }
            else
            {
                item.IsConnected = false;
            }
        }