private void button2_Click(object sender, EventArgs e)
 {
     // 断开连接
     keyenceNanoSerial.ConnectClose( );
     button2.Enabled = false;
     button1.Enabled = true;
     panel2.Enabled  = false;
 }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show(DemoUtils.PortInputWrong);
                return;
            }

            if (!byte.TryParse(textBox3.Text, out byte station))
            {
                MessageBox.Show("Station int wrong, it needs 0 - 255");
                return;
            }


            keyence?.ConnectClose( );
            keyence            = new KeyenceNanoSerialOverTcp( );
            keyence.IpAddress  = textBox1.Text;
            keyence.Port       = port;
            keyence.Station    = station;
            keyence.UseStation = checkBox1.Checked;

            try
            {
                OperateResult connect = keyence.ConnectServer( );
                if (connect.IsSuccess)
                {
                    MessageBox.Show(StringResources.Language.ConnectedSuccess);
                    button2.Enabled = true;
                    button1.Enabled = false;
                    panel2.Enabled  = true;

                    userControlReadWriteOp1.SetReadWriteNet(keyence, "DM0", false);
                    userControlCurve1.ReadWriteNet = keyence;
                }
                else
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedFailed);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
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(DemoUtils.IpAddressInputWrong);
                return;
            }

            if (!int.TryParse(textBox2.Text, out int port))
            {
                MessageBox.Show(DemoUtils.PortInputWrong);
                return;
            }


            keyenceNanoSerial?.ConnectClose( );
            keyenceNanoSerial           = new KeyenceNanoSerialOverTcp( );
            keyenceNanoSerial.IpAddress = textBox1.Text;
            keyenceNanoSerial.Port      = port;


            try
            {
                OperateResult connect = keyenceNanoSerial.ConnectServer( );
                if (connect.IsSuccess)
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedSuccess);
                    button2.Enabled = true;
                    button1.Enabled = false;
                    panel2.Enabled  = true;

                    userControlReadWriteOp1.SetReadWriteNet(keyenceNanoSerial, "DM0", false);
                    userControlCurve1.ReadWriteNet = keyenceNanoSerial;
                }
                else
                {
                    MessageBox.Show(HslCommunication.StringResources.Language.ConnectedFailed);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }