/// <summary> /// Called when the string or percentage property is set by Chromeleon. /// Note that one handler can handle several properties as well. /// </summary> /// <param name="args">The SetPropertyEventArgs contain both a reference to /// the property being set and the new value.</param> private void OnSetProperty(SetPropertyEventArgs args) { // Find out which property was meant. if (args.Property == m_AnyTextProperty) { SetStringPropertyEventArgs stringArgs = args as SetStringPropertyEventArgs; m_MyString = stringArgs.NewValue; m_AnyTextProperty.Update(m_MyString); } else if (args.Property == m_PercentageProperty) { SetDoublePropertyEventArgs doubleArgs = args as SetDoublePropertyEventArgs; Debug.Assert(doubleArgs.NewValue.HasValue); m_Percentage = doubleArgs.NewValue.Value; m_PercentageProperty.Update(m_Percentage); } else if (args.Property == m_FilterTimeConstantProperty) { SetDoublePropertyEventArgs doubleArgs = args as SetDoublePropertyEventArgs; Debug.Assert(doubleArgs.NewValue.HasValue); m_FilterTimeConstantProperty.Update(doubleArgs.NewValue.Value); } else if (args.Property == m_MeasurementRangeProperty) { SetDoublePropertyEventArgs doubleArgs = args as SetDoublePropertyEventArgs; Debug.Assert(doubleArgs.NewValue.HasValue); m_MeasurementRangeProperty.Update(doubleArgs.NewValue.Value); } else { // This mustn't happen. Debug.Fail("Unknown property."); } }
void m_MyDoubleProperty_OnSetProperty(SetPropertyEventArgs args) { SetDoublePropertyEventArgs doubleArgs = args as SetDoublePropertyEventArgs; Double?newValue = doubleArgs.NewValue; m_MyDoubleProperty.Update(doubleArgs.NewValue); }
private void OnSetPressureUpperLimit(SetPropertyEventArgs args) { SetDoublePropertyEventArgs doubleArgs = args as SetDoublePropertyEventArgs; m_Device.AuditMessage(AuditLevel.Normal, "Pressure.UpperLimit is set to " + doubleArgs.NewValue.Value.ToString() + " bar"); m_PressureUpperLimit.Update(doubleArgs.NewValue.Value); }
void genericHandler(SetPropertyEventArgs args) { SetDoublePropertyEventArgs doubleArgs = args as SetDoublePropertyEventArgs; Double? newValue = doubleArgs.NewValue; IDoubleProperty doubleProperty = args.Property as IDoubleProperty; doubleProperty.Update(doubleArgs.NewValue); }
void m_dcr_OnSetProperty(SetPropertyEventArgs args) { SetDoublePropertyEventArgs dblArgs = args as SetDoublePropertyEventArgs; if (dblArgs != null) { m_dcr.Update(dblArgs.NewValue); } }
void m_RateProperty_OnSetProperty(SetPropertyEventArgs args) { SetDoublePropertyEventArgs doubleArgs = args as SetDoublePropertyEventArgs; m_RateProperty.Update(doubleArgs.NewValue); // For the time stamped channel rate and timestep are different. // The rate determines at which rate data points are to be sent; // The timestep determines how the timestamps are encoded. }
private void OnSetTemperature(SetPropertyEventArgs args) { SetDoublePropertyEventArgs doublePropertyArgs = args as SetDoublePropertyEventArgs; Debug.Assert(doublePropertyArgs.NewValue.HasValue); m_NominalTempProperty.Update(doublePropertyArgs.NewValue.Value); // A real hardware would need some time to reach the new temperature. Thread.Sleep(1000); m_CurrentTempProperty.Update(doublePropertyArgs.NewValue.Value); }
/// <summary> /// Called when a Percentage property is set by Chromeleon. /// </summary> /// <param name="args">The SetPropertyEventArgs contain both a reference to /// the property being set and the new value.</param> private void m_RampedPercentageProperty_OnSetProperty(SetPropertyEventArgs args) { SetDoublePropertyEventArgs doubleArgs = args as SetDoublePropertyEventArgs; Debug.Assert((doubleArgs != null) && doubleArgs.NewValue.HasValue); // Write a message to the audit trail String message = String.Format(CultureInfo.InvariantCulture, "m_RampedPercentageProperty_OnSetProperty(time: {1} newValue: {0})", doubleArgs.NewValue, RetentionToString(args.RetentionTime)); m_MyCmDevice.AuditMessage(AuditLevel.Message, message); m_FlowHandler.ComponentProperties[1].Update(doubleArgs.NewValue.Value); }
public static Nullable <double> GetDoubleNullable(SetPropertyEventArgs args) { if (args == null) { throw new ArgumentNullException("args"); } SetDoublePropertyEventArgs doubleArgs = args as SetDoublePropertyEventArgs; if (doubleArgs == null) { throw new ArgumentException("Parameter args type " + args.GetType().FullName + " is not " + typeof(SetDoublePropertyEventArgs)); } return(doubleArgs.NewValue); }
private void OnSetVolume(SetPropertyEventArgs args) { SetDoublePropertyEventArgs setVolumeArgs = args as SetDoublePropertyEventArgs; if (setVolumeArgs.NewValue.HasValue) { m_Volume = setVolumeArgs.NewValue.Value; m_InjectHandler.VolumeProperty.Update(m_Volume); } else { m_MyCmDevice.AuditMessage(AuditLevel.Error, "Invalid volume."); } }
void m_RateProperty_OnSetProperty(SetPropertyEventArgs args) { SetDoublePropertyEventArgs doubleArgs = args as SetDoublePropertyEventArgs; m_RateProperty.Update(doubleArgs.NewValue); // Our rate determines TimeStepFactorProperty and TimeStepDivisorProperty: // TimeStepDivisorProperty / TimeStepFactorProperty = RateProperty /100 Hz // TimeStepFactorProperty and TimeStepDivisorProperty must be integers. // To keep it simple we set TimeStepFactorProperty = 10000 and calcutate // TimeStepDivisorProperty from the rate: // TimeStepDivisorProperty = RateProperty * 100 m_MyCmDevice.TimeStepDivisorProperty.Update( (int)(doubleArgs.NewValue.Value * 100.0)); m_MyCmDevice.TimeStepFactorProperty.Update(10000); }
private void OnSetFlow(SetPropertyEventArgs args) { SetDoublePropertyEventArgs doubleArgs = args as SetDoublePropertyEventArgs; double newFlow = doubleArgs.NewValue.Value; m_Device.AuditMessage(AuditLevel.Normal, "Flow is set to " + newFlow.ToString() + " ml/min"); m_FlowHandler.FlowNominalProperty.Update(newFlow); // Usually the value would be update from the hardware during some status poll. m_FlowHandler.FlowValueProperty.Update(newFlow); // The pressure would also change somehow. // We emulate this by deriving a pressure form the flow. m_PressureValue.Update(newFlow * 40); }
private void m_RampedPercentageProperty_OnPreflightSetProperty(SetPropertyEventArgs args) { SetDoublePropertyEventArgs doubleArgs = args as SetDoublePropertyEventArgs; if ((doubleArgs == null) || !doubleArgs.NewValue.HasValue) { return; } // Write a message to the preflight results String message = String.Format(CultureInfo.InvariantCulture, "m_RampedPercentageProperty_OnPreflightSetProperty(time: {1} newValue: {0})", doubleArgs.NewValue, RetentionToString(args.RetentionTime)); #if (PreflightMessagesToCM) m_MyCmDevice.AuditMessage(AuditLevel.Warning, message); #else Debug.WriteLine("PreflightMessage: " + message); #endif }
/// <summary> /// Called when the "SetPercentage" command is sent by Chromeleon. /// </summary> /// <param name="args">The CommandEventArgs contain a reference to /// the command being called and the argument list.</param> private void OnSetPercentage(CommandEventArgs args) { Debug.Assert(args.Command == m_SetPercentageCommand); // Get the parameter IDoubleParameterValue percentValue = args.ParameterValue(m_SetPercentageCommand.FindParameter("Value")) as IDoubleParameterValue; Debug.Assert(percentValue != null, "Required parameter is missing!"); Debug.Assert(percentValue.Value.HasValue); double newValue = percentValue.Value.Value; // We use the OnSetProperty handler to set the property. This avoids code duplication. // The last two parameters are not used by our handler, so it is safe to set them to null. SetDoublePropertyEventArgs doubleArgs = new SetDoublePropertyEventArgs(m_PercentageProperty, newValue, null, null); OnSetProperty(doubleArgs); }
public void OnSetWaveLength(SetPropertyEventArgs args) { SetDoublePropertyEventArgs doublePropertyArgs = args as SetDoublePropertyEventArgs; m_WavelengthProperty.Update(doublePropertyArgs.NewValue.Value); }