Example #1
0
        private void btnOpenPort_Click(object sender, EventArgs e)
        {
            try
            {
                LEDStatusLightingUtil ledStatusLightingUtil = LEDStatusLightingUtil.Instance;

                string station = "";
                string parity  = "";
                if (chkSSA.Checked)
                {
                    station = EnumStation.ALK;
                    parity  = "Even";
                }
                else if (chkSSK.Checked)
                {
                    station = EnumStation.ARK;
                    parity  = "None";
                }
                ledStatusLightingUtil.DataReceived += LedStatusLightingUtil_DataReceived;
                txtReceivedData.Text = ledStatusLightingUtil.OpenPort(station, cboPortNames.Text, int.Parse(cboBaudRate.Text), parity);

                btnOpenPort.Enabled  = false;
                btnClosePort.Enabled = true;
                btnSend.Enabled      = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            //try
            //{
            //    if (cboPortNames.Text == "" || cboBaudRate.Text == "")
            //    {
            //        txtReceivedData.Text = "Please select port settings";
            //    }
            //    else
            //    {
            //        serialPort1.PortName = cboPortNames.Text;
            //        serialPort1.BaudRate = int.Parse(cboBaudRate.Text);
            //        progressBar1.Value = 100;
            //        btnSend.Enabled = true;
            //        btnReceive.Enabled = true;
            //        txtHEXStringToSend.Enabled = true;
            //        btnOpenPort.Enabled = false;
            //        btnClosePort.Enabled = true;
            //        //if (cboParity.SelectedIndex == 0)
            //        //{
            //        //    serialPort1.Parity = Parity.Even;
            //        //}
            //        //else
            //        //{
            //        //    serialPort1.Parity = Parity.None;
            //        //}
            //        serialPort1.Parity = Parity.None;
            //        serialPort1.Open();

            //        serialPort1.DataReceived += SerialPort1_DataReceived;
            //    }
            //}
            //catch (UnauthorizedAccessException ex)
            //{
            //    txtReceivedData.Text = ex.Message;
            //}
        }