示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox19.Text, out int baudRate))
            {
                MessageBox.Show(DemoUtils.BaudRateInputWrong);
                return;
            }

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

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

            if (!byte.TryParse(textBox1.Text, out byte Station))
            {
                MessageBox.Show("PLC Station input wrong!");
                return;
            }

            rkc?.Close( );
            rkc = new TemperatureController( );

            try
            {
                rkc.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   = comboBox2.SelectedIndex == 0 ? Parity.None : (comboBox2.SelectedIndex == 1 ? Parity.Odd : Parity.Even);
                });
                //yamateke.ByteTransform.DataFormat = (HslCommunication.Core.DataFormat)comboBox1.SelectedItem;

                rkc.Open( );
                rkc.Station     = Station;
                button2.Enabled = true;
                button1.Enabled = false;
                panel2.Enabled  = true;

                userControlReadWriteOp1.SetReadWriteNet(rkc, "M1", false);
                userControlReadWriteOp1.EnableRKC( );
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }