// <CONSTRUCTORS> /// <summary> /// Constructor /// </summary> /// <param name="currentSettings">Initial settings to display</param> public LogSettings(LoggingSettings currentSettings) { InitializeComponent(); newSettings = currentSettings; comboBoxUnit.Items.Clear(); foreach (string unit in Enum.GetNames(typeof(TimeUnits))) { comboBoxUnit.Items.Add(unit); } comboBoxUnit.SelectedIndex = (int)(currentSettings.TimeUnit); textBoxInterval.Text = currentSettings.Interval.ToString(); checkBoxMilliseconds.IsChecked = currentSettings.IncludeMilliseconds; }
private TriggerStates triggerStateBeforeSweep = TriggerStates.Continuous; // save previous setting before going to sweep so it can be reloaded after sweep finishes // <CONSTRUCTORS> /// <summary> /// Constructor /// </summary> private Program() { // serial port port = new COM(); port.PortClosed += Port_PortClosed;; // pass port closed event port.DeviceIdentified += Port_AssignDeviceInfo; port.DeviceReady += Port_MeasurementModeInitialize; port.DataUpdated += Port_DataUpdated; CompensationFinished += (bool b) => port.ClearQueue(); device = new Device(); // logging LogManualAndSweep = true; NewValues += WriteToFile; loggingSettings = new LoggingSettings(1, TimeUnits.s, false); // default logging interval }
/// <summary> /// Handles clicks to OK button - create new settings /// </summary> /// <param name="sender">OK button</param> /// <param name="e">Parameters</param> private void buttonOK_Click(object sender, RoutedEventArgs e) { double interval; if (double.TryParse(textBoxInterval.Text, out interval)) { if (checkBoxMilliseconds.IsChecked != null) { newSettings = new LoggingSettings(interval, (TimeUnits)(comboBoxUnit.SelectedIndex), (bool)(checkBoxMilliseconds.IsChecked)); } else { newSettings = new LoggingSettings(interval, (TimeUnits)(comboBoxUnit.SelectedIndex), false); } } DialogResult = true; Close(); }
/// <summary> /// Writes a single line of data to the file /// </summary> /// <param name="device">Device with current parameters and values</param> /// <param name="loggingSettings">Settings that affect logging period and writing milliseconds in timestamps</param> public void WriteData(Device device, LoggingSettings loggingSettings) { if ((device.Values.X == null) && (device.Values.Y == null)) // if both values are not measured (null), then do not write anything { return; } DateTime now = DateTime.Now; if ((now - lastLog).TotalSeconds >= (loggingSettings.Seconds() - lastLogDeadTime)) // only log if the logging period - the dead time is lower than the period of time passed from the last log { lastLogDeadTime = (now - lastLog).TotalSeconds - loggingSettings.Seconds(); // calculate new dead time if (lastLogDeadTime < 0) // only shorten the time { lastLogDeadTime = 0; } lastLog = now; stringBuilder.Clear(); // date and time stringBuilder.Append(now.ToShortDateString()); stringBuilder.Append(" "); stringBuilder.Append(now.ToLongTimeString()); if (loggingSettings.IncludeMilliseconds) { stringBuilder.Append("."); stringBuilder.Append(string.Format("{0,0:D3}", now.Millisecond)); // append milliseconds with leading zeroes } stringBuilder.Append(Global.Delimiter); // x value if (device.Values.X != null) { stringBuilder.Append(((double)(device.Values.X)).ToString(Global.NumberFormat)); } else { stringBuilder.Append("N/A"); } stringBuilder.Append(Global.Delimiter); // y value if (device.Values.Y != null) { stringBuilder.Append(((double)(device.Values.Y)).ToString(Global.NumberFormat)); } else { stringBuilder.Append("N/A"); } stringBuilder.Append(Global.Delimiter); // x symbol stringBuilder.Append(device.XSymbol); stringBuilder.Append(Global.Delimiter); // y symbol stringBuilder.Append(device.YSymbol); stringBuilder.Append(Global.Delimiter); // x unit stringBuilder.Append(device.XUnit); stringBuilder.Append(Global.Delimiter); // y unit stringBuilder.Append(device.YUnit); stringBuilder.Append(Global.Delimiter); // frequency stringBuilder.Append(Global.Frequencies[device.FrequencyIndex]); stringBuilder.Append(Global.Delimiter); // voltage stringBuilder.Append(device.Voltage); stringBuilder.Append(Global.Delimiter); // mode stringBuilder.Append(device.Mode.Name()); stringBuilder.Append(Global.Delimiter); // model stringBuilder.Append(device.Model); stringBuilder.Append(Global.Delimiter); // averaging stringBuilder.Append(device.Averaging); stringBuilder.Append(Global.Delimiter); // measurement speed stringBuilder.Append(device.Speed); stringBuilder.Append(Global.Delimiter); // trigger stringBuilder.Append(device.Trigger); stringBuilder.Append(Global.Delimiter); file.WriteLine(stringBuilder.ToString()); } }