private static void Application_ApplicationExit(object sender, EventArgs e) { // This event handler is meant to fix the weird problem with the PnP watcher staying active even after the program closes. // There are a few methods similar to this one throughout the code for this program. One of them works and // the rest probably don't do anything, but I haven't taken the time see which ones are useless and remove them. if (SerialInterface.Create().pnpWatcher != null) { SerialInterface.Create().pnpWatcher.Stop(); SerialInterface.Create().pnpWatcher.Dispose(); } // Maybe this fixes the PnP event problem... if (Application.MessageLoop) { // WinForms app Application.Exit(); } else { // Console app System.Environment.Exit(1); } }
private string UserDefaultLanguage = "en"; // The language the user chose to use as a default (not implemented yet) // The constructor. This sets up most of what this program does. public Main() { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(Main_UnhandledException); // Create the SerialInterface object serial = SerialInterface.Create(); // Subscribe to some events: FormClosing += Main_FormClosing; // Might not be needed anymore serial.ArduinoChanged += Serial_ArduinoChanged; serial.ArduinoDataChanged += Serial_ArduinoDataChanged; InitializeComponent(); // Unfocus controls as necessary when the user clicks any of these controls: this.MouseDown += UnfocusControls; tabControl.MouseDown += UnfocusControls; menuStrip1.MouseDown += UnfocusControls; StatusPage.MouseDown += UnfocusControls; ConfigPage.MouseDown += UnfocusControls; SensorsPage.MouseDown += UnfocusControls; DataPage.MouseDown += UnfocusControls; panelStartDelay.MouseDown += UnfocusControls; labelConfigSec2.MouseDown += UnfocusControls; labelConfigSec.MouseDown += UnfocusControls; labelConfigMin.MouseDown += UnfocusControls; labelConfigHr.MouseDown += UnfocusControls; labelPackageName.MouseDown += UnfocusControls; labelSamplePeriod.MouseDown += UnfocusControls; labelTestDuration.MouseDown += UnfocusControls; labelStartDelay.MouseDown += UnfocusControls; // Config Page setup: checkBoxSyncTimeDate.Tag = false; // Unchecked by default textBoxPackageName.TextChanged += TextBoxPackageName_TextChanged; numericUpDownSamplePeriod.ValueChanged += NumericUpDownSampleRate_ValueChanged; numericUpDownTestDurationHours.ValueChanged += NumericUpDownTestDuration_ValueChanged; numericUpDownTestDurationMinutes.ValueChanged += NumericUpDownTestDuration_ValueChanged; numericUpDownTestDurationSeconds.ValueChanged += NumericUpDownTestDuration_ValueChanged; radioButtonStartDelayNone.CheckedChanged += RadioButtonStartDelayOption_CheckedChanged; radioButtonStartDelayOneMin.CheckedChanged += RadioButtonStartDelayOption_CheckedChanged; radioButtonStartDelayThreeMin.CheckedChanged += RadioButtonStartDelayOption_CheckedChanged; // Languages setup: imageComboLanguage.DropDownClosed += imageComboLanguage_DropDownClosed; // To unhighlight the selection imageComboLanguage.KeyDown += imageComboLanguage_KeyDown; imageComboLanguage.SelectedIndexChanged += imageComboLanguage_SelectedIndexChanged; LanguageText = new Dictionary <string, string>(); AvailableLanguages = new SortedSet <string>(); LanguageIcons = new ImageList(); LanguageIcons.ImageSize = new Size(imageComboLanguage.ImageList.ImageSize.Height, imageComboLanguage.ImageList.ImageSize.Height); CurrentLanguage = ""; LoadLanguages(); Console.WriteLine("\n\n\n"); // Arduino List setup: deviceList = new object[] { "<No Device>" }; // This doesn't work! //arduinoList.Items.AddRange(deviceList); arduinoListBinding = new BindingSource(); arduinoListBinding.DataSource = serial.LCAArduinos; arduinoListBinding.ListChanged += Serial_LCAArduinos_Changed; arduinoList.DataSource = arduinoListBinding; arduinoList.DisplayMember = "displayName"; // Start watching for USB PnP (Plug and Play) devices to be added/removed/modified: serial.StartPnPWatcher(); // Find LCA Arduinos (our sensor array Arduinos): serial.ActivateAllArduinos(); RefreshControlsEnable(); }