private void connectBtn_Click(object sender, EventArgs e) { //close old connection (just in case) if (serialController != null) { serialController.disconnect(); statusLabel.Text = "Idle"; enableConfigControl(false); } //load GUI profile to runningConfig if (updateRunningConfig()) { serialController = new SerialController(config, logTextBox, debugTextBox, notifyIcon); if (serialController.connect()) { Console.WriteLine("Connect success!"); statusLabel.Text = "Connected: " + config.port; logTextBox.AppendText("Connected to : " + config.port + "\n"); enableConfigControl(true); } else { Console.WriteLine("Cannot connect to serial port!"); logTextBox.AppendText("Cannot connect to : " + config.port + "\n"); } } else { logTextBox.AppendText("Cannot connect! Invalid running config!\n"); } }
private void MainForm_Load(object sender, EventArgs e) { listComPort(); //load config configMan = new ConfigManager(); if (configMan.readConfig()) { logTextBox.AppendText("Loaded config.conf\n"); config = configMan.getconfig(); if (applyConfigToGUI()) { logTextBox.AppendText("Config applied!\n"); //try to auto connect if (config.startup && config.enable) { if (updateRunningConfig()) { serialController = new SerialController(config, logTextBox, debugTextBox, notifyIcon); serialController.updateConfig(config); if (serialController.connect()) { logTextBox.AppendText("Auto connect success!\n"); statusLabel.Text = "Connected: " + config.port; enableConfigControl(true); //hide this.Hide(); //hide taskbar icon this.ShowInTaskbar = false; //show tooltip notifyIcon.ShowBalloonTip(1000, "Console controller", "Application is running in background.", ToolTipIcon.Info); } else { logTextBox.AppendText("Auto connect failed!\n"); } } } } else { logTextBox.AppendText("Cannot apply current config!\n"); } } else { logTextBox.AppendText("Cannot read config.conf or invalid format!\n"); } }
private void saveBtn_Click(object sender, EventArgs e) { Config tmpConf; tmpConf.baudRate = 0; tmpConf.duration = 0; bool error = false; //check valid input try { tmpConf.baudRate = Int32.Parse(baudComboBox.Text); tmpConf.duration = Int32.Parse(durationComboBox.Text); } catch (Exception exp) { Console.WriteLine(exp.ToString()); error = true; } tmpConf.port = comPortComboBox.Text; if (tmpConf.port == "--Select--") { error = true; } tmpConf.enable = enableCheckBox.Checked; tmpConf.tooltip = tooltipCheckbox.Checked; tmpConf.startup = startupCheckBox.Checked; if (!error) { if (configMan.writeConfig(tmpConf)) { logTextBox.AppendText("Setting saved!\n"); //update running config config = tmpConf; if (serialController != null) { serialController.disconnect(); enableConfigControl(false); statusLabel.Text = "Idle"; serialController.updateConfig(config); //reconnect if (serialController.connected) { logTextBox.AppendText("Trying to connect with new setting!\n"); if (serialController.connect()) { logTextBox.AppendText("Connected!\n"); statusLabel.Text = "Connected: " + config.port; enableConfigControl(true); } else { logTextBox.AppendText("Cannot connect!\n"); } } } else { //init new serial serialController = new SerialController(config, logTextBox, debugTextBox, notifyIcon); } } else { logTextBox.AppendText("Cannot save setting! Unknown error\n"); } } else { logTextBox.AppendText("Cannot save setting.Invalid config\n"); } }