// clears the existing list of program items and replaces them with the items from xml file; changes loop settings, local/remote and period settings according to the xml file public void ReplaceItems(BindingList <ProgramItem> programItems, out bool loopIsEnabled, out int loopCount, out bool isRemote, out double periodSeconds, out TimeUnits periodTimeUnits) { loopIsEnabled = false; loopCount = 1; isRemote = false; periodSeconds = 1; periodTimeUnits = TimeUnits.s; programItems.Clear(); // clear program items list document.Load(this.path); XmlElement main; main = document.DocumentElement; // loop foreach (XmlNode node in main.ChildNodes) { if (node.Name == "loop") { loopIsEnabled = true; if (node.Attributes.GetNamedItem("count").Value == "infinite") { loopCount = 0; } else { loopCount = Int32.Parse(node.Attributes.GetNamedItem("count").Value); } break; } } // remote/local XmlNode remote; remote = main.SelectSingleNode("voltageSenseMode"); isRemote = Boolean.Parse(remote.Attributes.GetNamedItem("isRemote").Value); // period settings XmlNode loggingPeriod; loggingPeriod = main.SelectSingleNode("logging"); periodTimeUnits = (TimeUnits)Enum.Parse(typeof(TimeUnits), loggingPeriod.Attributes.GetNamedItem("timeUnit").Value); timeConverter = new Converters.TimeConverter(); // convert representation in time-unit to seconds periodSeconds = (double)(timeConverter.ConvertBack(loggingPeriod.Attributes.GetNamedItem("period").Value, typeof(string), periodTimeUnits, System.Globalization.CultureInfo.CurrentCulture)); // elements AddItems(programItems); }
// creates constant mode program item private void constant(Modes mode, double?value, string durationString, TimeUnits timeUnit) { this.programMode = ProgramModes.Constant; this.mode = mode; this.durationString = durationString; this.timeUnit = timeUnit; this.value = value; this.skipEnabled = false; // compute duration in seconds Converters.TimeConverter timeConverter = new Converters.TimeConverter(); this.duration = (double)(timeConverter.ConvertBack(durationString, typeof(double), timeUnit, System.Globalization.CultureInfo.CurrentCulture)); // string representation for GUI switch (mode) { case Modes.Current: { if (value != null) { this.name = "Constant current " + ((double)value).ToString(NUMBER_FORMAT) + " A, " + durationString + " " + timeUnit.ToString(); } else { this.name = "Constant current (use previous), " + durationString + " " + timeUnit.ToString(); } break; } case Modes.Power_CC: { if (value != null) { this.name = "Constant power (CC) " + ((double)value).ToString(NUMBER_FORMAT) + " W, " + durationString + " " + timeUnit.ToString(); } else { this.name = "Constant power (CC, use previous), " + durationString + " " + timeUnit.ToString(); } break; } case Modes.Power_CV: { if (value != null) { this.name = "Constant power (CV) " + ((double)value).ToString(NUMBER_FORMAT) + " W, " + durationString + " " + timeUnit.ToString(); } else { this.name = "Constant power (CV, use previous), " + durationString + " " + timeUnit.ToString(); } break; } case Modes.Resistance_CC: { if (value != null) { this.name = "Constant resistance (CC) " + ((double)value).ToString(NUMBER_FORMAT) + " Ω, " + durationString + " " + timeUnit.ToString(); } else { this.name = "Constant resistance (CC, use previous), " + durationString + " " + timeUnit.ToString(); } break; } case Modes.Resistance_CV: { if (value != null) { this.name = "Constant resistance (CV) " + ((double)value).ToString(NUMBER_FORMAT) + " Ω, " + durationString + " " + timeUnit.ToString(); } else { this.name = "Constant resistance (CV, use previous), " + durationString + " " + timeUnit.ToString(); } break; } case Modes.Voltage: { if (value != null) { this.name = "Constant voltage " + ((double)value).ToString(NUMBER_FORMAT) + " V, " + durationString + " " + timeUnit.ToString(); } else { this.name = "Constant voltage (use previous), " + durationString + " " + timeUnit.ToString(); } break; } case Modes.VoltageSoftware: { if (value != null) { this.name = "Constant SW controlled voltage " + ((double)value).ToString(NUMBER_FORMAT) + " V, " + durationString + " " + timeUnit.ToString(); } else { this.name = "Constant SW controlled voltage (use previous), " + durationString + " " + timeUnit.ToString(); } break; } case Modes.MPPT: { if (value != null) { //this.name = "Maximum power point tracker from " + ((double)value).ToString(NUMBER_FORMAT) + " A, " + durationString + " " + timeUnit.ToString(); this.name = "Maximum power point tracker from " + ((double)value).ToString(NUMBER_FORMAT) + " V, " + durationString + " " + timeUnit.ToString(); } else { //this.name = "Maximum power point tracker (use previous current), " + durationString + " " + timeUnit.ToString(); this.name = "Maximum power point tracker (use previous voltage), " + durationString + " " + timeUnit.ToString(); } break; } case Modes.SimpleAmmeter: { name = "Simple ammeter, " + durationString + " " + timeUnit.ToString(); break; } } }
// creates ramp mode program item private void ramp(Modes mode, double?startingValue, double finalValue, string durationString, TimeUnits timeUnit) { this.programMode = ProgramModes.Ramp; this.mode = mode; this.durationString = durationString; this.timeUnit = timeUnit; this.startingValue = startingValue; this.finalValue = finalValue; // compute duration in seconds Converters.TimeConverter timeConverter = new Converters.TimeConverter(); this.duration = (double)(timeConverter.ConvertBack(durationString, typeof(double), timeUnit, System.Globalization.CultureInfo.CurrentCulture)); // string representation for GUI switch (mode) { case Modes.Current: { if (startingValue != null) { this.name = "Ramp current " + ((double)startingValue).ToString(NUMBER_FORMAT) + " –> " + finalValue.ToString(NUMBER_FORMAT) + " A, " + durationString + " " + timeUnit.ToString(); } else { this.name = "Ramp current (use previous) –> " + finalValue.ToString(NUMBER_FORMAT) + " A, " + durationString + " " + timeUnit.ToString(); } break; } case Modes.Power_CC: { if (startingValue != null) { this.name = "Ramp power (CC) " + ((double)startingValue).ToString(NUMBER_FORMAT) + " –> " + finalValue.ToString(NUMBER_FORMAT) + " W, " + durationString + " " + timeUnit.ToString(); } else { this.name = "Ramp power (CC, use previous) –> " + finalValue.ToString(NUMBER_FORMAT) + " W, " + durationString + " " + timeUnit.ToString(); } break; } case Modes.Power_CV: { if (startingValue != null) { this.name = "Ramp power (CV) " + ((double)startingValue).ToString(NUMBER_FORMAT) + " –> " + finalValue.ToString(NUMBER_FORMAT) + " W, " + durationString + " " + timeUnit.ToString(); } else { this.name = "Ramp power (CV, use previous) –> " + finalValue.ToString(NUMBER_FORMAT) + " W, " + durationString + " " + timeUnit.ToString(); } break; } case Modes.Resistance_CC: { if (startingValue != null) { this.name = "Ramp resistance (CC) " + ((double)startingValue).ToString(NUMBER_FORMAT) + " –> " + finalValue.ToString(NUMBER_FORMAT) + " Ω, " + durationString + " " + timeUnit.ToString(); } else { this.name = "Ramp resistance (CC, use previous) –> " + finalValue.ToString(NUMBER_FORMAT) + " Ω, " + durationString + " " + timeUnit.ToString(); } break; } case Modes.Resistance_CV: { if (startingValue != null) { this.name = "Ramp resistance (CV) " + ((double)startingValue).ToString(NUMBER_FORMAT) + " –> " + finalValue.ToString(NUMBER_FORMAT) + " Ω, " + durationString + " " + timeUnit.ToString(); } else { this.name = "Ramp resistance (CV, use previous) –> " + finalValue.ToString(NUMBER_FORMAT) + " Ω, " + durationString + " " + timeUnit.ToString(); } break; } case Modes.Voltage: { if (startingValue != null) { this.name = "Ramp voltage " + ((double)startingValue).ToString(NUMBER_FORMAT) + " –> " + finalValue.ToString(NUMBER_FORMAT) + " V, " + durationString + " " + timeUnit.ToString(); } else { this.name = "Ramp voltage (use previous) –> " + finalValue.ToString(NUMBER_FORMAT) + " V, " + durationString + " " + timeUnit.ToString(); } break; } case Modes.VoltageSoftware: { if (startingValue != null) { this.name = "Ramp SW controlled voltage " + ((double)startingValue).ToString(NUMBER_FORMAT) + " –> " + finalValue.ToString(NUMBER_FORMAT) + " V, " + durationString + " " + timeUnit.ToString(); } else { this.name = "Ramp SW controlled voltage (use previous) –> " + finalValue.ToString(NUMBER_FORMAT) + " V, " + durationString + " " + timeUnit.ToString(); } break; } } }
public void LoadSettings(out bool loopIsEnabled, out int loopCount, out bool isRemote, out double periodSeconds, out TimeUnits periodTimeUnits, out LEDBrightnesses LEDBrightness, out byte LEDRule, out FanRules FanRule, out MeasurementFilters MeasurementFilter, out bool CurrentAutoranging, out bool VoltageAutoranging) { loopIsEnabled = false; loopCount = 1; isRemote = false; periodSeconds = 1; periodTimeUnits = TimeUnits.s; document.Load(this.path); XmlElement main; main = document.DocumentElement; // loop foreach (XmlNode node in main.ChildNodes) { if (node.Name == "loop") { loopIsEnabled = true; if (node.Attributes.GetNamedItem("count").Value == "infinite") { loopCount = 0; } else { loopCount = Int32.Parse(node.Attributes.GetNamedItem("count").Value); } break; } } // remote/local XmlNode remote; remote = main.SelectSingleNode("voltageSenseMode"); isRemote = Boolean.Parse(remote.Attributes.GetNamedItem("isRemote").Value); // LED settings XmlNode LED; LED = main.SelectSingleNode("LED"); // brightness LEDBrightnesses lb; if (Enum.TryParse(LED.Attributes.GetNamedItem("brightness").Value, out lb)) { LEDBrightness = lb; } else { LEDBrightness = Load.DefaultLEDBrightness; } // rules byte ledRule; bool result; string hex = LED.Attributes.GetNamedItem("rules").Value; if (hex.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase)) { result = byte.TryParse(hex.Substring(2), System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture, out ledRule); } else { result = byte.TryParse(hex, out ledRule); } if (result) { LEDRule = ledRule; } else { LEDRule = Load.DefaultLEDRule; } // Fan XmlNode Fan; Fan = main.SelectSingleNode("fan"); // rule FanRules fr; if (Enum.TryParse(Fan.Attributes.GetNamedItem("rules").Value, out fr)) { FanRule = fr; } else { FanRule = Load.DefaultFanRule; } // Measurement XmlNode Measurement; Measurement = main.SelectSingleNode("measurement"); // filter MeasurementFilters ms; if (Enum.TryParse(Measurement.Attributes.GetNamedItem("filter").Value, out ms)) { MeasurementFilter = ms; } else { MeasurementFilter = Load.DefaultMeasurementFilter; } // Autoranging XmlNode Autoranging; Autoranging = main.SelectSingleNode("autoranging"); // current if (bool.TryParse(Autoranging.Attributes.GetNamedItem("current").Value, out CurrentAutoranging) == false) { CurrentAutoranging = Load.DefaultAutorangingCurrent; } // voltage if (bool.TryParse(Autoranging.Attributes.GetNamedItem("voltage").Value, out VoltageAutoranging) == false) { VoltageAutoranging = Load.DefaultAutorangingVoltage; } // period settings XmlNode loggingPeriod; loggingPeriod = main.SelectSingleNode("logging"); periodTimeUnits = (TimeUnits)Enum.Parse(typeof(TimeUnits), loggingPeriod.Attributes.GetNamedItem("timeUnit").Value); timeConverter = new Converters.TimeConverter(); // convert representation in time-unit to seconds periodSeconds = (double)(timeConverter.ConvertBack(loggingPeriod.Attributes.GetNamedItem("period").Value, typeof(string), periodTimeUnits, System.Globalization.CultureInfo.CurrentCulture)); }