private void CheckTemperature(SetPropertyEventArgs args, double value)
        {
            if (args.RunContext.IsManual)              // If this is requested manually by the user
            {
                if (!args.RunContext.IsSemanticCheck)  // This is not just a check - the command will be executed after the preflight is successful
                {
                    m_Driver.CheckIsCommunicating();
                    CheckIsTemperatureControlOn();
                }
            }

            ITypeDouble type = m_Properties.TemperatureNominal.DataType;

            if (args.RunContext.IsManual)
            {
                // This check can be made only in manual mode, because the script can have steps that modify
                // TemperatureMin and/or TemperatureMax and therefor the current Min/Max values are not the ones the script sets
                if (value < TemperatureMin || value > TemperatureMax)
                {
                    throw new InvalidOperationException("Cannot set TemperatureValue = " + value.ToString() + " " + type.Unit + ". Must be in [" + TemperatureMin + ", " + TemperatureMax.ToString() + "]");
                }
            }

            double valueMin = type.Minimum.GetValueOrDefault();
            double valueMax = type.Maximum.GetValueOrDefault();

            if (value < valueMin || value > valueMax)
            {
                throw new InvalidOperationException("Cannot set TemperatureValue = " + value.ToString() + " " + type.Unit + ". Must be in [" + valueMin + ", " + valueMax.ToString() + "]");
            }
        }
        void m_MyDoubleProperty_OnSetProperty(SetPropertyEventArgs args)
        {
            SetDoublePropertyEventArgs doubleArgs = args as SetDoublePropertyEventArgs;
            Double?newValue = doubleArgs.NewValue;

            m_MyDoubleProperty.Update(doubleArgs.NewValue);
        }
Exemple #3
0
        private void OnPropertyDescriptionSet(SetPropertyEventArgs args)
        {
            try
            {
                string value = Property.GetString(args);
                if (value == null)
                {
                    value = Property.EmptyString;  // Warning: Do not set Null to string properties
                }

                if (string.IsNullOrEmpty(value))
                {
                    throw new InvalidOperationException("Property " + args.Property.Name + " value cannot be empty");
                }

                if (value == m_Properties.Description.Value)
                {
                    return;
                }

                m_Properties.Description.Update(value);

                string userName = Property.GetUserName(args);
                Log.WriteLine(Id, "Property changed: " + args.Property.Name + " = \"" + value + "\"" + (string.IsNullOrEmpty(userName) ? string.Empty : " - requested by " + userName));
            }
            catch (Exception ex)
            {
                AuditMessage(AuditLevel.Error, ex.Message);
            }
        }
        void m_MyStringProperty_OnPreflightSetProperty(SetPropertyEventArgs args)
        {
            SetStringPropertyEventArgs stringArgs = args as SetStringPropertyEventArgs;
            String message = String.Format("New value #{0}#", stringArgs.NewValue);

            m_MyCmDevice.AuditMessage(AuditLevel.Warning, message); // AuditLevel.Warning so that it shows up in Ready Check Results
        }
        public static bool GetBool(SetPropertyEventArgs args)
        {
            int  number = GetInt(args);
            bool result = GetBool(number);

            return(result);
        }
 /// <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.");
     }
 }
 private void OnPropertyTemperatureNominalSet(SetPropertyEventArgs args)
 {
     // Do not throw exceptions from the event handler
     if (!IsSimulated)
     {
         throw new InvalidOperationException("This works only in simulation mode.");  // Aborts the injection and the sequence and is not going to be logged by Log.WriteLine
     }
     try
     {
         if (!IsSimulated)
         {
             throw new InvalidOperationException("This works only in simulation mode.");  // Whether to abort is up to the exception handler
         }
         double value = Property.GetDouble(args);
         SetTemperature(args, value);
     }
     catch (InvalidOperationException ex)
     {
         AuditMessage(AuditLevel.Abort, ex.Message);  // Aborts the injection
     }
     catch (Exception ex)
     {
         AuditMessage(AuditLevel.Error, ex.Message);  // Does not abort the injection
     }
 }
Exemple #8
0
        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);
        }
 public static string GetUserName(SetPropertyEventArgs args)
 {
     if (args == null)
     {
         return(null);
     }
     return(GetUserName(args.RunContext));
 }
Exemple #10
0
        private void OnTimeStepDivisor(SetPropertyEventArgs args)
        {
            SetIntPropertyEventArgs intPropertyArgs = args as SetIntPropertyEventArgs;

            m_MyCmDevice.TimeStepDivisorProperty.Update(intPropertyArgs.NewValue);

            Driver.Comm.SetSamplingInterval((double)intPropertyArgs.NewValue);
        }
        void TimeStepDivisorProperty_OnSetProperty(SetPropertyEventArgs args)
        {
            SetIntPropertyEventArgs intArgs = args as SetIntPropertyEventArgs;

            m_MyCmDevice.TimeStepDivisorProperty.Update(intArgs.NewValue);

            UpdateRate();
        }
        void genericHandler(SetPropertyEventArgs args)
        {
            SetDoublePropertyEventArgs doubleArgs = args as SetDoublePropertyEventArgs;
            Double?         newValue       = doubleArgs.NewValue;
            IDoubleProperty doubleProperty = args.Property as IDoubleProperty;

            doubleProperty.Update(doubleArgs.NewValue);
        }
        /// OnDebugCommand will be called when the DebugCommand property is set by CM.
        private void OnDebugCommand(SetPropertyEventArgs args)
        {
            Debug.Assert(args.Property == m_DebugCommand);
            SetStringPropertyEventArgs stringPropertyArgs = args as SetStringPropertyEventArgs;

            Driver.Comm.SendLine(stringPropertyArgs.NewValue);
            m_DebugCommand.Update(stringPropertyArgs.NewValue);
        }
Exemple #14
0
 void m_dcrmode_OnPreflightSetProperty(SetPropertyEventArgs args)
 {
     if (m_MyCmDevice.AcquisitionStateProperty.Value.HasValue &&
         m_MyCmDevice.AcquisitionStateProperty.Value.Value != (int)AcquisitionState.Idle)
     {
         m_MyCmDevice.AuditMessage(AuditLevel.Abort, "Cannot change the internal acquisition mode during data acquisition");
     }
 }
Exemple #15
0
        void m_dcrmode_OnSetProperty(SetPropertyEventArgs args)
        {
            SetIntPropertyEventArgs intArgs = args as SetIntPropertyEventArgs;

            if (intArgs != null)
            {
                m_dcrmode.Update(intArgs.NewValue);
            }
        }
Exemple #16
0
        private void OnTest(SetPropertyEventArgs args)
        {
            SetIntPropertyEventArgs iProp = args as SetIntPropertyEventArgs;

            m_MyCmDevice.AuditMessage(AuditLevel.Message, args.RunContext.ProgramTime.Minutes.ToString() + " min: OnSetProperty OnTest");
            IIntProperty intProperty = iProp.Property as IIntProperty;

            intProperty.Update(iProp.NewValue);
        }
Exemple #17
0
        void m_TerminateInTimeProperty_OnSetProperty(SetPropertyEventArgs args)
        {
            SetIntPropertyEventArgs setIntArgs = args as SetIntPropertyEventArgs;

            if (setIntArgs.NewValue.HasValue)
            {
                m_TerminateInTimeProperty.Update(setIntArgs.NewValue.Value);
            }
        }
Exemple #18
0
        void m_dcr_OnSetProperty(SetPropertyEventArgs args)
        {
            SetDoublePropertyEventArgs dblArgs = args as SetDoublePropertyEventArgs;

            if (dblArgs != null)
            {
                m_dcr.Update(dblArgs.NewValue);
            }
        }
Exemple #19
0
 void m_dcr_OnPreflightSetProperty(SetPropertyEventArgs args)
 {
     if (m_MyCmDevice.AcquisitionStateProperty.Value.HasValue &&
         m_MyCmDevice.AcquisitionStateProperty.Value.Value != (int)AcquisitionState.Idle &&
         m_dcrmode.Value.HasValue &&
         m_dcrmode.Value.Value == 0)
     {
         m_MyCmDevice.AuditMessage(AuditLevel.Abort, "Cannot change the data collection rate during data acquisition if in regular mode");
     }
 }
        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.
        }
Exemple #21
0
        void m_TerminationTimeoutProperty_OnSetProperty(SetPropertyEventArgs args)
        {
            SetIntPropertyEventArgs setIntArgs = args as SetIntPropertyEventArgs;

            if (setIntArgs.NewValue.HasValue)
            {
                m_TerminationTimeoutProperty.Update(setIntArgs.NewValue.Value);
                m_MyCmDevice.TerminationTimeout = setIntArgs.NewValue.Value;
            }
        }
Exemple #22
0
        private void OnPropertyFlowNominalSet(SetPropertyEventArgs args)
        {
            double value = Property.GetDouble(args);

            FlowNominal = value;
            if (IsSimulated)
            {
                Flow = value;
            }
        }
Exemple #23
0
        void m_DelayTerminationProperty_OnSetProperty(SetPropertyEventArgs args)
        {
            SetIntPropertyEventArgs setIntArgs = args as SetIntPropertyEventArgs;

            if (setIntArgs.NewValue.HasValue)
            {
                m_DelayTerminationProperty.Update(setIntArgs.NewValue.Value);
                m_MyCmDevice.DelayTermination =
                    (setIntArgs.NewValue.Value != 0) ? true : false;
            }
        }
Exemple #24
0
        private void OnPropertyVolumeSet(SetPropertyEventArgs args)
        {
            Nullable <double> value = Property.GetDoubleNullable(args);

            if (value == null)
            {
                AuditMessage(AuditLevel.Error, "Invalid volume.");
                return;
            }
            Volume = value.GetValueOrDefault();
        }
        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);
        }
Exemple #26
0
        private void OnPropertyPositionSet(SetPropertyEventArgs args)
        {
            Nullable <int> value = Property.GetIntNullable(args);

            if (value == null)
            {
                AuditMessage(AuditLevel.Error, "Invalid position.");
                return;
            }
            Position = value.GetValueOrDefault();
        }
 private void OnPropertyTemperatureNominalSetPreflight(SetPropertyEventArgs args)
 {
     try
     {
         double value = Property.GetDouble(args);
         CheckTemperature(args, value);
     }
     catch (Exception ex)
     {
         AuditMessage(AuditLevel.Error, ex.Message);
     }
 }
Exemple #28
0
        private void OnPropertyPressureUpperLimitSet(SetPropertyEventArgs args)
        {
            double value = Property.GetDouble(args);

            Log.WriteLine(Id, "On Property PressureUpperLimit Set " + value.ToString());
            if (m_Properties.PressureUpperLimit.Value.GetValueOrDefault() == value)
            {
                return;
            }
            m_Properties.PressureUpperLimit.Update(value);
            AuditMessage(AuditLevel.Normal, m_Properties.PressureUpperLimit.Name + " set to " + value.ToString() + " " + m_Properties.PressureUpperLimit.DataType.Unit);
        }
        void m_MyStringProperty_OnSetProperty(SetPropertyEventArgs args)
        {
            SetStringPropertyEventArgs stringArgs = args as SetStringPropertyEventArgs;
            String newValue = stringArgs.NewValue;
            String message  = String.Format("New value #{0}#", stringArgs.NewValue);

            m_MyCmDevice.AuditMessage(AuditLevel.Normal, message);
            m_MyStringProperty.Update(stringArgs.NewValue);
            m_MyStringProperty.LogValue();
            message = String.Format("Internal value #{0}#", m_MyStringProperty.Value);
            m_MyCmDevice.AuditMessage(AuditLevel.Normal, message);
        }
        private void SetTemperature(SetPropertyEventArgs args, double value)
        {
            m_Driver.CheckIsCommunicating();

            if (args.RunContext.IsManual)
            {
                // Only in manual. The script 1st sets the Temperature and turns the Heater On or
                // Turns the Heater Off and then sets the Temperature
                CheckIsTemperatureControlOn();
            }
            CheckTemperature(args, value);

            Ready = false;
            TemperatureNominal = value;  // Set the user requested temperature

            // Perform Asynchronously
            Action task = (() =>
            {
                const int stepsCount = 5;
                double valueStep = (value - Temperature) / stepsCount;
                for (int i = 0; i < stepsCount - 1; i++)
                {
                    Thread.Sleep(1000);
                    Temperature += valueStep;
                    if (TemperatureNominal != value)
                    {
                        // Start over
                        value = TemperatureNominal;
                        valueStep = (value - Temperature) / stepsCount;
                        i = -1;
                        continue;
                    }
                }
                Thread.Sleep(1000);
                Temperature = value;
                Ready = true;
            });

            AsyncCallback taskCallback = (ar =>
            {
                try
                {
                    task.EndInvoke(ar);
                }
                catch (Exception ex)
                {
                    AuditMessage(AuditLevel.Error, "Failed to set Temperature = " + value.ToString() + ". Error: " + ex.Message);
                }
            });

            task.BeginInvoke(taskCallback, null);
        }