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>
 /// FxCop recommended doing this...
 /// </summary>
 public override bool Equals(object obj)
 {
     if (obj is PlxSensorId)
     {
         PlxSensorId that = (PlxSensorId)obj;
         if ((this.Sensor == that.Sensor) &&
             (this.Instance == that.Instance))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #3
0
        /// <summary>
        /// Call this for each byte received from the PLX chain.
        /// </summary>
        /// <param name="b">Received byte.</param>
        /// <returns>If a complete packet was received, this will return the
        /// PlxSensorId of the sensor whose data has been updated.  Call the
        /// GetValue() method to retrieve the value.</returns>
        public PlxSensorId?PushByte(byte b)
        {
            if (b == 0x80)
            {
                this.state = ParserState.ExpectingFirstHalfOfSensorType;
                return(null);
            }

            if (b == 0x40)
            {
                this.state = ParserState.ExpectingStart;
                return(null);
            }

            switch (this.state)
            {
            case ParserState.ExpectingFirstHalfOfSensorType:
                this.partialValue = b;
                this.state        = ParserState.ExpectingSecondHalfOfSensorType;
                break;

            case ParserState.ExpectingSecondHalfOfSensorType:
                this.sensorType = (PlxSensorType)((this.partialValue << 6) | b);
                this.state      = ParserState.ExpectingInstance;
                break;

            case ParserState.ExpectingInstance:
                this.instance = b;
                this.state    = ParserState.ExpectingFirstHalfOfValue;
                break;

            case ParserState.ExpectingFirstHalfOfValue:
                this.partialValue = b;
                this.state        = ParserState.ExpectingSecondHalfOfValue;
                break;

            case ParserState.ExpectingSecondHalfOfValue:
                int rawValue = (this.partialValue << 6) | b;
                //double convertedValue = PlxParser.ConvertValue(this.sensorType, i);
                PlxSensorId id = new PlxSensorId(this.sensorType, this.instance);
                lock (this.dictionaryLock)
                {
                    this.results[id] = rawValue;
                }
                this.state = ParserState.ExpectingFirstHalfOfSensorType;
                return(id);
            }
            return(null);
        }