private void Serial_ArduinoChanged(object sender, ArduinoEventArgs e) { // The ArduinoChanged event that this handler is subscribed to is triggered when SerialInterface.Arduino is changed. // SerialInterface.Arduino is the currently active ArduinoBoard object - the one that this synchronization program is connected to and interacting with. Console.WriteLine("SerialInterface.Arduino changed."); RefreshControlsEnable(); // Refresh all GUI controls that require a sensor package to be connected if (serial.Arduino == null) { // If no Arduino is connected and selected, set Status page labels text to their default values labelStatusPackageName.Text = getLanguageText("PackageName", "Package Name"); labelStatusSerialPort.Text = getLanguageText("SerialPort", "Serial Port"); labelStatusTotalSensors.Text = getLanguageText("TotalSensors", "Total Sensors") + ":"; labelStatusMode.Text = getLanguageText("Mode", "Mode") + ":"; labelStatusElapsedTime.Text = getLanguageText("ElapsedTime", "Elapsed Time") + ":"; labelStatusDataFile.Text = getLanguageText("CurrentDataFile", "Current Data File") + ":"; buttonStatusStartStop.Text = getLanguageText("StartTest", "Start Test"); buttonConfigDiscardChanges_Click(this, new EventArgs()); // No Ardunio connected, so discard user's config page changes } else { // The serial port name only changes when Arduino changes, so I'll update the serial port text label here instead // of in the serial Arduino data changed event handler. labelStatusSerialPort.Text = "(" + (serial.Arduino.Port?.PortName ?? "ERROR") + ")"; } }
private void Serial_ArduinoDataChanged(object sender, ArduinoEventArgs e) { // Should probably return here if the arduino whose data changed is not the arduino in use, // because the UI only needs refreshed if it is the arduino in use which has data that changed. // Can do more here: // Use e.Reason for the reason the event was called switch ((string)e.Type) { case "PackageName": Console.WriteLine("PackageName changed, so UI will be updated"); textBoxPackageName.Text = serial.Arduino.PackageName; labelStatusPackageName.Text = serial.Arduino.PackageName; break; case "StartDelay": Console.WriteLine("StartDelay changed, so UI will be updated"); if (serial.Arduino.StartDelay == 0) // No start delay { radioButtonStartDelayNone.Checked = true; radioButtonStartDelayOneMin.Checked = false; radioButtonStartDelayThreeMin.Checked = false; } else if (serial.Arduino.StartDelay == 60) // One minute { radioButtonStartDelayNone.Checked = false; radioButtonStartDelayOneMin.Checked = true; radioButtonStartDelayThreeMin.Checked = false; } else if (serial.Arduino.StartDelay == 60 * 3) // Three minutes { radioButtonStartDelayNone.Checked = false; radioButtonStartDelayOneMin.Checked = false; radioButtonStartDelayThreeMin.Checked = true; } else { Console.WriteLine("Unacceptable value for StartDelay."); } break; case "TestDuration": Console.WriteLine("TestDuration changed, so UI will be updated"); numericUpDownTestDurationHours.Value = Math.Floor((decimal)serial.Arduino.TestDuration / 60 / 60); // Get hours from total seconds numericUpDownTestDurationMinutes.Value = Math.Floor((decimal)serial.Arduino.TestDuration / 60) % 60; // Get minutes from total seconds numericUpDownTestDurationSeconds.Value = (decimal)serial.Arduino.TestDuration % 60; // Get seconds from total seconds break; case "SamplePeriod": Console.WriteLine("SamplePeriod changed, so UI will be updated"); numericUpDownSamplePeriod.Value = (decimal)serial.Arduino.SamplePeriod; break; case "TestStarted": Console.WriteLine("TestStarted changed, so UI will be updated"); ButtonStatusStartStopRefresh(); if (serial.Arduino.TestStarted) { labelStatusMode.Text = getLanguageText("Mode", "Mode") + ": " + getLanguageText("Running", "Running"); } else { labelStatusMode.Text = getLanguageText("Mode", "Mode") + ": " + getLanguageText("Ready", "Ready"); } break; default: Console.WriteLine("In serial_ArduinoDataChanged, an unrecognized arduino variable was changed: {0}", (string)e.Type); break; } //// I'm putting these here since they don't have their own member variables in ArduinoBoard yet: labelStatusTotalSensors.Text = getLanguageText("TotalSensors", "Total Sensors") + ": __"; // A placeholder labelStatusElapsedTime.Text = getLanguageText("ElapsedTime", "Elapsed Time") + ": __/__"; // A placeholder labelStatusDataFile.Text = getLanguageText("CurrentDataFile", "Current Data File") + ": __"; // A placeholder /////// arduinoListBinding.ResetBindings(false); //RefreshStatusPageText(); // Refresh the text on the status page UpdateTabText(); }