Exemple #1
0
        /// <summary>
        /// Use this to retrieve a sensor's value in the units of your choice.
        /// </summary>
        /// <param name="sensorId">PlxSensorId returned from PushByte()</param>
        /// <param name="units">Desired units.</param>
        /// <returns>The sensor's value in the desired units.</returns>
        public double GetValue(PlxSensorId sensorId, PlxSensorUnits units)
        {
            int rawValue;

            lock (this.dictionaryLock)
            {
                if (!this.results.ContainsKey(sensorId))
                {
                    return(0);
                }
                rawValue = this.results[sensorId];
            }

            double result;

            if (units == PlxSensorUnits.Raw)
            {
                result = rawValue;
            }
            else
            {
                result = PlxParser.ConvertValue(sensorId.Sensor, units, rawValue);
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Convert the given raw value to the desired units, according to sensor type.
        /// </summary>
        /// <remarks>
        /// This code was copy/pasted from PLXApp018.PDF, with very minor changes (the
        /// original used integers for sensor type and units).
        /// </remarks>
        /// <param name="sensorType">Type of sensor.</param>
        /// <param name="units">Desired units.</param>
        /// <param name="raw">Raw value from the sensor.</param>
        /// <returns>Value converted to the desired units.</returns>
        private static double ConvertValue(PlxSensorType sensorType, PlxSensorUnits units, int raw)
        {
            double data = 0;

            if (sensorType == PlxSensorType.WidebandAfr)
            {
                if (units == PlxSensorUnits.WidebandAfrLambda)
                {
                    data = (raw / 3.75 + 68) / 100;
                }
                else if (units == PlxSensorUnits.WidebandAfrGasoline147)
                {
                    data = (raw / 2.55 + 100) / 10;
                }
                else if (units == PlxSensorUnits.WidebandAfrDiesel146)
                {
                    data = (raw / 2.58 + 100) / 10;
                }
                else if (units == PlxSensorUnits.WidebandAfrMethanol64)
                {
                    data = (raw / 5.856 + 43.5) / 10;
                }
                else if (units == PlxSensorUnits.WidebandAfrEthanol90)
                {
                    data = (raw / 4.167 + 61.7) / 10;
                }
                else if (units == PlxSensorUnits.WidebandAfrLpg155)
                {
                    data = (raw / 2.417 + 105.6) / 10;
                }
                else if (units == PlxSensorUnits.WidebandAfrCng172)
                {
                    data = (raw / 2.18 + 117) / 10;
                }
            }
            else if (sensorType == PlxSensorType.ExhaustGasTemperature)
            {
                if (units == PlxSensorUnits.ExhaustGasTemperatureCelsius)
                {
                    data = raw;
                }
                else if (units == PlxSensorUnits.ExhaustGasTemperatureFahrenheit)
                {
                    data = (raw / .555 + 32);
                }
            }


/*                      Call me lazy, but I'm not going to polish code for sensors that I don't own.
 *
 *                      else if (sensorType == PlxSensorType.FluidTemperature)
 *                      {
 *                          if (units == 0) //Degrees Celsius Water
 *                              data = raw;
 *                          else if (units == 1) //Degrees Fahrenheit Water
 *                              data = (raw / .555 + 32);
 *                          else if (units == 2) //Degrees Celsius Oil
 *                              data = raw;
 *                          else if (units == 3) //Degrees Fahrenheit Oil
 *                              data = (raw / .555 + 32);
 *                      }
 *                      else if (sensorType == PlxSensorType.Vacuum) //Vac
 *                      {
 *                          if (units == 0) //in/Hg (inch Mercury)
 *                              data = -(raw / 11.39 - 29.93);
 *                          else if (units == 1) //mm/Hg (millimeters Mercury)
 *                              data = -(raw * 2.23 + 760.4);
 *                      }
 *                      else if (sensorType == PlxSensorType.Boost) //Boost
 *                      {
 *                          if (units == 0) //0-30 PSI
 *                              data = raw / 22.73;
 *                          else if (units == 1) //0-2 kg/cm^2
 *                              data = raw / 329.47;
 *                          else if (units == 2) //0-15 PSI
 *                              data = raw / 22.73;
 *                          else if (units == 3) //0-1 kg/cm^2
 *                              data = raw / 329.47;
 *                          else if (units == 4) //0-60 PSI
 *                              data = raw / 22.73;
 *                          else if (units == 5) //0-4 kg/cm^2
 *                              data = raw / 329.47;
 *                      }
 *                      else if (sensorType == PlxSensorType.AirIntakeTemperature) //AIT
 *                      {
 *                          if (units == 0) //Celsius
 *                              data = raw;
 *                          else if (units == 1) //Fahrenheit
 *                              data = (raw / .555 + 32);
 *                      }
 *                      else if (sensorType == PlxSensorType.Rpm) //RPM
 *                      {
 *                          data = raw * 19.55; //RPM
 *                      }
 *                      else if (sensorType == PlxSensorType.VehicleSpeed) //Speed
 *                      {
 *                          if (units == 0) //MPH
 *                              data = raw / 6.39;
 *                          else if (units == 1) //KMH
 *                              data = raw / 3.97;
 *                      }
 *                      else if (sensorType == PlxSensorType.ThrottlePosition) //TPS
 *                      {
 *                          data = raw; //Throttle Position %
 *                      }
 *                      else if (sensorType == PlxSensorType.EngineLoad) //Engine Load
 *                      {
 *                          data = raw; //Engine Load %
 *                      }
 *                      else if (sensorType == PlxSensorType.FluidPressure) //Fluid Pressure
 *                      {
 *                          if (units == 0) //PSI Fuel
 *                              data = raw / 5.115;
 *                          else if (units == 1) //kg/cm^2 Fuel
 *                              data = raw / 72.73;
 *                          else if (units == 2) //Bar Fuel
 *                              data = raw / 74.22;
 *                          else if (units == 3) //PSI Oil
 *                              data = raw / 5.115;
 *                          else if (units == 4) //kg/cm^2 Oil
 *                              data = raw / 72.73;
 *                          else if (units == 5) //Bar Oil
 *                              data = raw / 74.22;
 *                      }
 *                      else if (sensorType == PlxSensorType.Timing) //Engine timing
 *                      {
 *                          data = raw - 64; //Degree Timing
 *                      }
 *                      else if (sensorType == PlxSensorType.ManifoldAbsolutePressure) //MAP
 *                      {
 *                          if (units == 0) //kPa
 *                              data = raw;
 *                          else if (units == 1) //inHg
 *                              data = raw / 3.386;
 *                      }
 *                      else if (sensorType == PlxSensorType.MassAirFlow) //MAF
 *                      {
 *                          if (units == 0) //g/s (grams per second)
 *                              data = raw;
 *                          else if (units == 1) //lb/min (pounds per minute)
 *                              data = raw / 7.54;
 *                      }
 *                      else if (sensorType == PlxSensorType.ShortTermFuelTrim) //Short term fuel trim
 *                      {
 *                          data = raw - 100; //Fuel trim %
 *                      }
 *                      else if (sensorType == PlxSensorType.LongTermFuelTrim) //Long term fuel trim
 *                      {
 *                          data = raw - 100; //Fuel trim %
 *                      }
 *                      else if (sensorType == PlxSensorType.NarrowbandAfr) //Narrowband O2 sensor
 *                      {
 *                          if (units == 0) //Percent
 *                              data = raw;
 *                          else if (units == 1) //Volts
 *                              data = raw / 78.43;
 *                      }
 *                      else if (sensorType == PlxSensorType.FuelLevel) //Fuel level
 *                      {
 *                          data = raw; //Fuel Level %
 *                      }
 *                      else if (sensorType == PlxSensorType.Voltage) //Volts
 *                      {
 *                          data = raw / 51.15; //Volt Meter Volts
 *                      }
 *                      else if (sensorType == PlxSensorType.Knock) //Knock
 *                      {
 *                          data = raw / 204.6; //Knock volts 0-5
 *                      }
 *                      else if (sensorType == PlxSensorType.DutyCycle) //Duty cycle
 *                      {
 *                          if (units == 0) //Positive Duty
 *                              data = raw / 10.23;
 *                          else if (units == 1) //Negative Duty
 *                              data = 100 - (raw / 10.23);
 *                      }*/
            return(data);
        }
Exemple #3
0
 public double GetValue(PlxSensorId id, PlxSensorUnits units)
 {
     return(this.parser.GetValue(id, units));
 }