Beispiel #1
0
        public bool PanaAdd(string name)
        {
            Panasonic_PLC Pana = new Panasonic_PLC(name);

            PanaList.Add(Pana);
            return(true);
        }
Beispiel #2
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (SerialLB.SelectedItem != null)
                {
                    Panasonic_PLC SelectPort = PanaMgr.PanaList[SerialLB.SelectedIndex]; //SerialLB.SelectedItem as Panasonic_PLC;

                    if (SelectPort.DisConnect())                                         //关闭串口
                    {
                        SelectPort.Port.PortName = PortCB.Text.Trim();
                        SelectPort.Port.BaudRate = int.Parse(RateCB.Text.Trim());
                        SelectPort.Port.DataBits = int.Parse(BitCB.Text.Trim());
                        //停止位赋值
                        if (StopBitCB.Text.Trim() == "One")
                        {
                            SelectPort.Port.StopBits = StopBits.One;
                        }
                        else if (StopBitCB.Text.Trim() == "OnePointFive")
                        {
                            SelectPort.Port.StopBits = StopBits.OnePointFive;
                        }
                        else
                        {
                            SelectPort.Port.StopBits = StopBits.Two;
                        }
                        //奇偶校验位赋值
                        if (ParityCB.Text.Trim() == "None")
                        {
                            SelectPort.Port.Parity = Parity.None;
                        }
                        else if (ParityCB.Text.Trim() == "Odd")
                        {
                            SelectPort.Port.Parity = Parity.Odd;
                        }
                        else
                        {
                            SelectPort.Port.Parity = Parity.Even;
                        }

                        SelectPort.Port.ReadTimeout = Convert.ToInt32(RSNUD.Value);

                        if (SelectPort.Connect())//打开串口,如果能够打开则保存数据
                        {
                            PanaMgr.PanaList_Save();
                            MessageBox.Show(SelectPort.Port.PortName + "保存成功");
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("串口数据保存失败,请检查参数及线路是否正确");
            }
        }