Example #1
0
        /// <summary>
        /// Set a sensor's information.
        /// </summary>
        /// <param name="position">The position of the sensor to be updated.</param>
        /// <param name="sensor">The cached values for the sensor to be updated that corresponds with the position.</param>
        /// <param name="sensorSettings">Keyed by sensor code.</param>
        private void UpdateSensor(int position, Sensor sensor, Dictionary <string, Sensor> sensorSettings)
        {
            string sensorCode = sensor.Type.Code;
            // Get the sensor's maximum reading. - INS-6584 RHP v7.6
            double maximumReading = _instCtrlr.GetSensorMaximumReading(position, sensor.Resolution);

            string updateMsg = string.Format(" Sensor{0}({1}) ", position, sensorCode);

            Log.Debug(string.Format("{0}.UpdateSensor - {1}", Name, updateMsg));
            Log.Debug(string.Format("{0}. Sensor's Maximum Reading is  {1}.", updateMsg, maximumReading));

            Sensor settings = null;

            if (!sensorSettings.TryGetValue(sensorCode, out settings))
            {
                string msg = string.Format("Sensor \"{0}\" not updated. No settings available for sensor code \"{1}\"", position, sensorCode);
                Log.Warning(msg);
                _instrumentSettingsUpdateEvent.Errors.Add(new DockingStationError(msg, DockingStationErrorLevel.Warning));
                return;
            }

            // Enable/disable the sensor as needed.
            bool tmpEnabled = sensor.Enabled;

            if (settings.Enabled != tmpEnabled)
            {
                LogUpdate(updateMsg + "Enabled", settings.Enabled, tmpEnabled);
                _instCtrlr.EnableSensor(position, settings.Enabled);
                sensor.Enabled = settings.Enabled;
            }

            // Although VX500's allow their response factors to be changed, DS2 does not support it.
            if (_instCtrlr.IsSensorGasCodeConfigurable(sensorCode))
            {
                string tmpGasCode = sensor.GasDetected;
                if (settings.GasDetected != tmpGasCode)
                {
                    if (settings.GasDetected != string.Empty)
                    {
                        LogUpdate(updateMsg + "GasDetected", settings.GasDetected, tmpGasCode);
                        _instCtrlr.SetSensorGasCode(position, settings.GasDetected);
                        sensor.GasDetected = settings.GasDetected;
                    }
                    else                      // GasDetected == String.Empty
                    {
                        Log.Error("SetSensorGasCode cannot be called. No gas code specified!!");
                    }
                }
            }

            // Update calibration gas code.
            string tmpString = sensor.CalibrationGas.Code;

            if (settings.CalibrationGas.Code != tmpString)
            {
                LogUpdate(updateMsg + "CalGasCode", settings.CalibrationGas.Code, tmpString);
                _instCtrlr.SetSensorCalGasCode(position, settings.CalibrationGas.Code);
                sensor.CalibrationGas = GasType.Cache[settings.CalibrationGas.Code];
            }

            // Need to get the sensor's resolution for the following setttings.
            double resolution = sensor.Resolution;

            // Sensor Calibration Gas Concentration.
            double tmpDouble = settings.CalibrationGasConcentration;

            if (tmpDouble != sensor.CalibrationGasConcentration)
            {
                // INS-6584 RHP v7.6 - If the Sensor setting received form iNet has a value higher than the sensor's maximum value allowed,
                // then set the maximum allowed value.
                tmpDouble = (Math.Abs(tmpDouble) > maximumReading) ? maximumReading : tmpDouble;

                LogUpdate(updateMsg + "CalGasConc", tmpDouble, sensor.CalibrationGasConcentration);
                _instCtrlr.SetSensorCalGasConcentration(position, tmpDouble, resolution);
                sensor.CalibrationGasConcentration = tmpDouble;
            }

            // Sensor low alarm.
            tmpDouble = settings.Alarm.Low;
            if (tmpDouble != DomainModelConstant.NullDouble && tmpDouble != sensor.Alarm.Low)
            {
                // INS-6584 RHP v7.6 - If the Sensor setting received form iNet has a value higher than the sensor's maximum value allowed,
                // then set the maximum allowed value.
                tmpDouble = (Math.Abs(tmpDouble) > maximumReading) ? maximumReading : tmpDouble;

                LogUpdate(updateMsg + "AlarmLow", tmpDouble, sensor.Alarm.Low);
                _instCtrlr.SetSensorLowAlarm(position, tmpDouble, resolution);
                sensor.Alarm.Low = tmpDouble;
            }

            // Sensor high alarm.
            tmpDouble = settings.Alarm.High;
            if (tmpDouble != DomainModelConstant.NullDouble && tmpDouble != sensor.Alarm.High)
            {
                // INS-6584 RHP v7.6 - If the Sensor setting received form iNet has a value higher than the sensor's maximum value allowed,
                // then set the maximum allowed value.
                tmpDouble = (Math.Abs(tmpDouble) > maximumReading) ? maximumReading : tmpDouble;

                LogUpdate(updateMsg + "AlarmHigh", tmpDouble, sensor.Alarm.High);
                _instCtrlr.SetSensorHighAlarm(position, tmpDouble, resolution);
                sensor.Alarm.High = tmpDouble;
            }

            // Sensor gas alert.
            if (_instCtrlr.Driver.Definition.HasGasAlertFeature)
            {
                // iNet will send null if the value is to be set to the low alarm value so the gas alert is effectively disabled.
                double tmpGasAlert = settings.Alarm.GasAlert == DomainModelConstant.NullDouble ? settings.Alarm.Low : settings.Alarm.GasAlert;
                if (tmpGasAlert != sensor.Alarm.GasAlert)
                {
                    // INS-6584 RHP v7.6 - If the Sensor setting received form iNet has a value higher than the sensor's Alarm Low,
                    // then set the Sensor's Alarm Low for Non-O2 sensors. For O2 the maximum permissable level is Alam High.
                    if (sensorCode.Equals(SensorCode.O2))
                    {
                        tmpGasAlert = (Math.Abs(tmpGasAlert) > sensor.Alarm.High) ? sensor.Alarm.High : tmpGasAlert;
                    }
                    else
                    {
                        tmpGasAlert = (Math.Abs(tmpGasAlert) > sensor.Alarm.Low) ? sensor.Alarm.Low : tmpGasAlert;
                    }

                    LogUpdate(updateMsg + "AlarmGasAlert", tmpGasAlert, sensor.Alarm.GasAlert);
                    _instCtrlr.SetSensorGasAlert(position, tmpGasAlert, resolution);
                    sensor.Alarm.GasAlert = tmpGasAlert;
                }
            }

            // Sensor TWA alarm.
            if (sensor.Alarm.TWA != double.MinValue)
            {
                tmpDouble = settings.Alarm.TWA;
                if (tmpDouble != DomainModelConstant.NullDouble && tmpDouble != sensor.Alarm.TWA)
                {
                    // INS-6584 RHP v7.6 - If the Sensor setting received form iNet has a value higher than the sensor's maximum value allowed,
                    // then set the maximum allowed value.
                    tmpDouble = (Math.Abs(tmpDouble) > maximumReading) ? maximumReading : tmpDouble;

                    LogUpdate(updateMsg + "AlarmTWA", tmpDouble, sensor.Alarm.TWA);
                    _instCtrlr.SetSensorTwaAlarm(position, tmpDouble, resolution);
                    sensor.Alarm.TWA = tmpDouble;
                }
            }
            // Sensor STEL alarm.
            if (sensor.Alarm.STEL != double.MinValue)
            {
                tmpDouble = settings.Alarm.STEL;
                if (tmpDouble != DomainModelConstant.NullDouble && tmpDouble != sensor.Alarm.STEL)
                {
                    // INS-6584 RHP v7.6 - If the Sensor setting received form iNet has a value higher than the sensor's maximum value allowed,
                    // then set the maximum allowed value.
                    tmpDouble = (Math.Abs(tmpDouble) > maximumReading) ? maximumReading : tmpDouble;

                    LogUpdate(updateMsg + "AlarmSTEL", tmpDouble, sensor.Alarm.STEL);
                    _instCtrlr.SetSensorStelAlarm(position, tmpDouble, resolution);
                    sensor.Alarm.STEL = tmpDouble;
                }
            }
        }