Characteristic Locus
Inheritance object ObservableBase<UNIT> > SamplingSensorBase<UNIT> > PollingSensorBase<UNIT> > AnalogSamplingBase > Hcsr04 > AnalogWaterLevel > MiniPID2 > AnalogJoystick > As5013 > Alspt19315C > AnalogLightSensor > AnalogSolarIntensityGauge > Capacitive > Fc28 > CurrentTransducer > AnalogTemperature > SwitchingRainGauge > WindVane
Implements IObservable<IChangeResult<UNIT>> ISamplingSensor<UNIT> ISensor<UNIT>
Inherited Members ObservableBase<UNIT>.observers ObservableBase<UNIT>.NotifyObservers(IChangeResult<UNIT>) ObservableBase<UNIT>.Subscribe(IObserver<IChangeResult<UNIT>>) ObservableBase<UNIT>.CreateObserver(Action<IChangeResult<UNIT>>, Predicate<IChangeResult<UNIT>>) object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString()
Namespace Meadow.Foundation
Assembly Meadow.Foundation.dll

Syntax

public abstract class SamplingSensorBase<UNIT> : ObservableBase<UNIT>, IObservable<IChangeResult<UNIT>>, ISamplingSensor<UNIT>, ISensor<UNIT> where UNIT : struct

Type Parameters

Name Description
UNIT

Fields

samplingLock

Lock for sampling

Declaration
protected object samplingLock

Field Value

Type Description
object

Properties

Conditions

The last read conditions

Declaration
public UNIT Conditions { get; protected set; }

Property Value

Type Description
UNIT

IsSampling

Gets a value indicating whether the sensor is currently in a sampling loop. Call StartSampling() to spin up the sampling process.

Declaration
public bool IsSampling { get; protected set; }

Property Value

Type Description
bool

true if sampling; otherwise, false.

SamplingTokenSource

Sampling cancellation token source

Declaration
protected CancellationTokenSource? SamplingTokenSource { get; set; }

Property Value

Type Description
CancellationTokenSource

UpdateInterval

A TimeSpan that specifies how long to wait between readings. This value influences how often *Updated events are raised and IObservable consumers are notified.

Declaration
public virtual TimeSpan UpdateInterval { get; protected set; }

Property Value

Type Description
TimeSpan

Methods

RaiseEventsAndNotify(IChangeResult<UNIT>)

Notify observers

Declaration
protected virtual void RaiseEventsAndNotify(IChangeResult<UNIT> changeResult)

Parameters

Type Name Description
IChangeResult<UNIT> changeResult

provides new and old values

Read()

Convenience method to get the current sensor readings. For frequent reads, use StartSampling() and StopSampling() in conjunction with the SampleBuffer.

Declaration
public virtual Task<UNIT> Read()

Returns

Type Description
Task<UNIT>

ReadSensor()

Read value from sensor

Declaration
protected abstract Task<UNIT> ReadSensor()

Returns

Type Description
Task<UNIT>

unitized value

StartUpdating(TimeSpan?)

Starts updating the sensor on the updateInterval frequency specified

Declaration
public abstract void StartUpdating(TimeSpan? updateInterval = null)

Parameters

Type Name Description
TimeSpan? updateInterval

A TimeSpan that specifies how long to wait between readings

StopUpdating()

Stops sampling the sensor

Declaration
public abstract void StopUpdating()

Events

Updated

Event handler for updated values

Declaration
public event EventHandler<IChangeResult<UNIT>> Updated

Event Type

Type Description
EventHandler<IChangeResult<UNIT>>