private void button2_Click(object sender, EventArgs e)
 {
     // 断开连接
     melsecSerial.Close( );
     button2.Enabled = false;
     button1.Enabled = true;
     panel2.Enabled  = false;
 }
 public override void Disconnect()
 {
     try
     {
         PLC.Close();
     }
     catch { }
 }
Exemplo n.º 3
0
 private void MBtnDisconnect_Click(object sender, EventArgs e)
 {
     try
     {
         melsecFxSerial.Close();
         HideOrShow(false);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox2.Text, out int baudRate))
            {
                MessageBox.Show(DemoUtils.BaudRateInputWrong);
                return;
            }

            if (!int.TryParse(textBox16.Text, out int dataBits))
            {
                MessageBox.Show(DemoUtils.DataBitsInputWrong);
                return;
            }

            if (!int.TryParse(textBox17.Text, out int stopBits))
            {
                MessageBox.Show(DemoUtils.StopBitInputWrong);
                return;
            }


            melsecSerial?.Close( );
            melsecSerial = new MelsecFxSerial( );
            melsecSerial.IsNewVersion = checkBox1.Checked;

            try
            {
                melsecSerial.SerialPortInni(sp =>
                {
                    sp.PortName = comboBox3.Text;
                    sp.BaudRate = baudRate;
                    sp.DataBits = dataBits;
                    sp.StopBits = stopBits == 0 ? StopBits.None : (stopBits == 1 ? StopBits.One : StopBits.Two);
                    sp.Parity   = comboBox1.SelectedIndex == 0 ? Parity.None : (comboBox1.SelectedIndex == 1 ? Parity.Odd : Parity.Even);
                });
                melsecSerial.Open( );

                button2.Enabled = true;
                button1.Enabled = false;
                panel2.Enabled  = true;

                userControlReadWriteOp1.SetReadWriteNet(melsecSerial, "D100", false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox2.Text, out int baudRate))
            {
                MessageBox.Show("波特率输入错误!");
                return;
            }

            if (!int.TryParse(textBox16.Text, out int dataBits))
            {
                MessageBox.Show("数据位输入错误!");
                return;
            }

            if (!int.TryParse(textBox17.Text, out int stopBits))
            {
                MessageBox.Show("停止位输入错误!");
                return;
            }


            melsecSerial?.Close( );
            melsecSerial = new MelsecFxSerial( );

            try
            {
                melsecSerial.SerialPortInni(sp =>
                {
                    sp.PortName = textBox1.Text;
                    sp.BaudRate = baudRate;
                    sp.DataBits = dataBits;
                    sp.StopBits = stopBits == 0 ? System.IO.Ports.StopBits.None : (stopBits == 1 ? System.IO.Ports.StopBits.One : System.IO.Ports.StopBits.Two);
                    sp.Parity   = comboBox1.SelectedIndex == 0 ? System.IO.Ports.Parity.None : (comboBox1.SelectedIndex == 1 ? System.IO.Ports.Parity.Odd : System.IO.Ports.Parity.Even);
                });
                melsecSerial.Open( );

                button2.Enabled = true;
                button1.Enabled = false;
                panel2.Enabled  = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }