Esempio n. 1
0
        /// <summary>
        /// Get one of the supported sensor values from a sensor. The triplet protocol, model and id together identifies a sensor.
        /// </summary>
        /// <param name="protocol">The protocol returned by GetSensor</param>
        /// <param name="model">The model returned by GetSensor</param>
        /// <param name="id">The id returned by GetSensor</param>
        /// <param name="type">One of the SensorValueTypes returned by GetSensor</param>
        /// <returns>A reading with a timestamp for when the value was read.</returns>
        public SensorReadingResult GetSensorValue(string protocol, string model, int id, SensorValueType type) 
        {
            using (var valuePointer = new DisposableStringPointer())
            {
                int timestamp = 0;

                var response = NativeMethods.tdSensorValue(protocol, model, id, (int)type, valuePointer.Pointer, 20, ref timestamp);

                return new SensorReadingResult
                {
                    Value = valuePointer.Value,
                    TimeStamp = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(timestamp)
                };
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Use this function to iterate over all sensors.
        /// </summary>
        /// <returns>Returns a sensor, if present. Call until Result != Success to enumerate sensors.</returns>
        public SensorResult GetSensor()
        {
            using (var protocol = new DisposableStringPointer())
            using (var model = new DisposableStringPointer())
            {
                int sensorId = 0;
                int type = 0;

                // Assume no protocol name is longer than 20 characters, and no models are longer than 30 characters
                var response = NativeMethods.tdSensor(protocol.Pointer, 20, model.Pointer, 30, ref sensorId, ref type);

                return new SensorResult
                {
                    Model = model.Value,
                    Protocol = protocol.Value,
                    Result = response,
                    SensorId = sensorId,
                    Type = (SensorValueType)type
                };   
            }
        }