Beispiel #1
0
        public override void DeviceConn(PanasonicMewtocolConfig config)
        {
            PanasonicMewtocol mewtocol = new PanasonicMewtocol(config.StationNo);

            SetPort();
            mewtocol.SerialPortInni(serialPort.PortName, serialPort.BaudRate, serialPort.DataBits, serialPort.StopBits, serialPort.Parity);
            mewtocol.Open();
            NetworkDevice = mewtocol;
        }
        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;
            }


            if (!byte.TryParse(textBox15.Text, out byte station))
            {
                MessageBox.Show("站号输入不正确!");
                return;
            }

            panasonicMewtocol?.Close( );
            panasonicMewtocol = new PanasonicMewtocol(station);


            ComboBox2_SelectedIndexChanged(null, new EventArgs( ));


            try
            {
                panasonicMewtocol.SerialPortInni(sp =>
                {
                    sp.PortName = comboBox3.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);
                });
                panasonicMewtocol.Open( );

                button2.Enabled = true;
                button1.Enabled = false;
                panel2.Enabled  = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void BuildReadCommandTest( )
        {
            OperateResult <byte[]> read = PanasonicMewtocol.BuildReadCommand(0xEE, "X1", 10);

            Assert.IsTrue(read.IsSuccess, "Build read command failed");

            string command = Encoding.ASCII.GetString(read.Content);
            string corrent = "%EE#RCCX00010010";

            Assert.IsTrue(corrent == command.Substring(0, command.Length - 3), "data is not same");
        }
        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;
            }


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

            panasonicMewtocol?.Close( );
            panasonicMewtocol = new PanasonicMewtocol(station);


            try
            {
                panasonicMewtocol.SerialPortInni(sp =>
                {
                    sp.PortName = comboBox3.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);
                });
                panasonicMewtocol.Open( );

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