Characteristic Locus
Inheritance System.Object ObservableBase<UNIT> > SensorBase<UNIT> > SamplingSensorBase<UNIT> > AnalogObservableBase > Gp2d12 > Hcsr04 > Hysrf05 > Mb10x0 > Sfsr02 > AnalogWaterLevel > AnalogJoystick > As5013 > Alspt19315C > AnalogLightSensor > AnalogSolarGauge > Capacitive > Fc28 > AnalogTemperature > SwitchingRainGauge > WindVane
Inherited Members ObservableBase<UNIT>.observers ObservableBase<UNIT>.NotifyObservers(IChangeResult<UNIT>) ObservableBase<UNIT>.Subscribe(IObserver<IChangeResult<UNIT>>) ObservableBase<UNIT>.CreateObserver(Action<IChangeResult<UNIT>>, Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation
Assembly Meadow.Foundation.dll

Syntax

public abstract class SensorBase<UNIT> : ObservableBase<UNIT> where UNIT : struct

Type Parameters

Name Description
UNIT

Fields

samplingLock

Lock for sampling

Declaration
protected object samplingLock

Field Value

Type Description
System.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
System.Boolean

true if sampling; otherwise, false.

SamplingTokenSource

Sampling cancellation token source

Declaration
protected CancellationTokenSource? SamplingTokenSource { get; set; }

Property Value

Type Description
System.Nullable<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

Events

Updated

Event handler for updated values

Declaration
public event EventHandler<IChangeResult<UNIT>> Updated

Event Type

Type Description
EventHandler<IChangeResult<UNIT>>