Characteristic Locus
Inheritance System.Object PortBase<IAnalogChannelInfo> AnalogPortBase > AnalogInputPortBase > AnalogInputPort
Implements IAnalogPort IAnalogInputPort
Inherited Members PortBase<IAnalogChannelInfo>.disposed PortBase<IAnalogChannelInfo>.Channel PortBase<IAnalogChannelInfo>.Pin PortBase<IAnalogChannelInfo>.Dispose(Boolean) PortBase<IAnalogChannelInfo>.Dispose()
Namespace Meadow.Hardware
Assembly Meadow.dll

Syntax

public abstract class AnalogInputPortBase : AnalogPortBase, IAnalogPort, IAnalogInputPort

Constructors

AnalogInputPortBase(IPin, IAnalogChannelInfo, Int32, TimeSpan, Voltage)

Declaration
protected AnalogInputPortBase(IPin pin, IAnalogChannelInfo channel, int sampleCount, TimeSpan sampleInterval, Voltage referenceVoltage)

Parameters

Type Name Description
IPin pin
IAnalogChannelInfo channel
System.Int32 sampleCount
TimeSpan sampleInterval
Voltage referenceVoltage

Properties

BufferSyncRoot

Declaration
protected object BufferSyncRoot { get; }

Property Value

Type Description
System.Object

observers

Declaration
protected List<IObserver<IChangeResult<Voltage>>> observers { get; set; }

Property Value

Type Description
List<IObserver<IChangeResult<Voltage>>>

ReferenceVoltage

The reference voltage being used for the ADC comparison

Declaration
public Voltage ReferenceVoltage { get; protected set; }

Property Value

Type Description
Voltage

SampleCount

Number of samples to take per reading. If > 1 then the port will take multiple readings and These are automatically averaged to reduce noise, a process known as oversampling.

Declaration
public int SampleCount { get; protected set; }

Property Value

Type Description
System.Int32

SampleInterval

Duration in between samples when oversampling.

Declaration
public TimeSpan SampleInterval { get; protected set; }

Property Value

Type Description
TimeSpan

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 TimeSpan UpdateInterval { get; protected set; }

Property Value

Type Description
TimeSpan

Voltage

Gets the average value of the values in the buffer. Use in conjunction with StartUpdating() for long-running analog sampling. For occasional sampling, use Read().

Declaration
public Voltage Voltage { get; }

Property Value

Type Description
Voltage

The average buffer value.

VoltageSampleBuffer

Gets the sample buffer. Make sure to call StartUpdating() before use.

Declaration
public IList<Voltage> VoltageSampleBuffer { get; }

Property Value

Type Description
IList<Voltage>

The sample buffer.

Methods

RaiseChangedAndNotify(IChangeResult<Voltage>)

Declaration
protected void RaiseChangedAndNotify(IChangeResult<Voltage> changeResult)

Parameters

Type Name Description
IChangeResult<Voltage> changeResult

Read()

Convenience method to get the current voltage. For frequent reads, use StartUpdating() and StopUpdating() in conjunction with the SampleBuffer.

Declaration
public abstract Task<Voltage> Read()

Returns

Type Description
Task<Voltage>

StartUpdating(Nullable<TimeSpan>)

Starts continuously sampling the analog port.

This method also starts raising Changed events and IObservable subscribers getting notified. Use the readIntervalDuration parameter to specify how often events and notifications are raised/sent.

Declaration
public abstract void StartUpdating(TimeSpan? updateInterval)

Parameters

Type Name Description
System.Nullable<TimeSpan> updateInterval

StopUpdating()

Stops sampling the analog port.

Declaration
public abstract void StopUpdating()

Subscribe(IObserver<IChangeResult<Voltage>>)

Declaration
public IDisposable Subscribe(IObserver<IChangeResult<Voltage>> observer)

Parameters

Type Name Description
IObserver<IChangeResult<Voltage>> observer

Returns

Type Description
IDisposable

Events

Updated

Raised when the value of the reading changes.

Declaration
public event EventHandler<IChangeResult<Voltage>> Updated

Event Type

Type Description
EventHandler<IChangeResult<Voltage>>