Пример #1
0
        private void btnConnectSerialPort_Click(object sender, EventArgs e)
        {
            switch (btnConnectSerialPort.Text)
            {
            case "連接":
            {
                XmlConfig.XmlConfig.Write(cbxSerialPort.SelectedItem.ToString(), "serialport", "port");
                int lRet = optController.InitSerialPort(cbxSerialPort.SelectedItem.ToString());
                if (0 != lRet)
                {
                    MessageBox.Show("串口初始化失敗!", "Error");
                    return;
                }
                cbxSerialPort.Enabled     = false;
                btnConnectSerialPort.Text = "斷開";

                break;
            }

            case "斷開":
            {
                int lRet = optController.ReleaseSerialPort();
                if (0 != lRet)
                {
                    MessageBox.Show("釋放端口失敗!", "Error");
                    return;
                }
                btnConnectSerialPort.Text = "連接";
                break;
            }

            default:
            {
                break;
            }
            }
        }