Exemplo n.º 1
0
        void CommSelectAndSettingsFormShown(object sender, EventArgs e)
        {
            BtnRefreshClick(sender, e);

            try
            {
                cbCommPort.Text = _project.GetCommPort();
            }
            catch (Exception)
            {
                if (cbCommPort.Items.Count > 0)
                {
                    cbCommPort.SelectedIndex = 0;
                }
            }

            CommSettings c = _project.GetCommSettings();

            if (c.AsString() == "38400:8:N:1:")
            {
                rbDefault.Checked = true;
            }
            else
            {
                rbCustom.Checked = true;

                try
                {
                    cbBitRate.Text  = String.Format("{0}", c.BitRate);
                    cbDataBits.Text = String.Format("{0}", c.DataBits);
                    switch (c.Parity)
                    {
                    case Parity.Even:
                        cbParity.Text = "Even";
                        break;

                    case Parity.Odd:
                        cbParity.Text = "Odd";
                        break;

                    case Parity.None:
                    default:
                        cbParity.Text = "None";
                        break;
                    }
                    switch (c.StopBits)
                    {
                    case StopBits.Two:
                        cbStopBits.Text = "2";
                        break;

                    case StopBits.OnePointFive:
                        cbStopBits.Text = "1.5";
                        break;

                    case StopBits.One:
                    default:
                        cbStopBits.Text = "1";
                        break;
                    }
                    switch (c.Handshake)
                    {
                    case Handshake.RequestToSend:
                        cbHandshake.Text = "Hardware";
                        break;

                    case Handshake.XOnXOff:
                        cbHandshake.Text = "Xon/Xoff";
                        break;

                    case Handshake.None:
                    default:
                        cbHandshake.Text = "None";
                        break;
                    }
                }
                catch (Exception)
                {
                }
            }

            rbParamsChanged(sender, e);
        }
Exemplo n.º 2
0
        void BtnOKClick(object sender, EventArgs e)
        {
            _project.SetCommPort(cbCommPort.Text);

            CommSettings c = _project.GetCommSettings();

            int t;

            int.TryParse(cbBitRate.Text, out t);
            c.BitRate = t;
            int.TryParse(cbDataBits.Text, out t);
            c.DataBits = t;
            switch (cbParity.Text)
            {
            case "Odd":
                c.Parity = Parity.Odd;
                break;

            case "Even":
                c.Parity = Parity.Even;
                break;

            case "None":
            default:
                c.Parity = Parity.None;
                break;
            }
            switch (cbStopBits.Text)
            {
            case "2":
                c.StopBits = StopBits.Two;
                break;

            case "1.5":
                c.StopBits = StopBits.OnePointFive;
                break;

            case "1":
            default:
                c.StopBits = StopBits.One;
                break;
            }
            switch (cbHandshake.Text)
            {
            case "Hardware":
                c.Handshake = Handshake.RequestToSend;
                break;

            case "Xon/Xoff":
                c.Handshake = Handshake.XOnXOff;
                break;

            case "None":
            default:
                c.Handshake = Handshake.None;
                break;
            }

            _project.SetCommSettings(c);

            DialogResult = DialogResult.OK;
            Close();
        }