Characteristic Locus
Inheritance object PortBase<IAnalogChannelInfo> AnalogPortBase AnalogInputPortBase > AnalogInputPort
Implements IAnalogInputPort IAnalogPort IPort<IAnalogChannelInfo> IDisposable IObservable<IChangeResult<Voltage>>
Inherited Members AnalogInputPortBase.BufferSyncRoot AnalogInputPortBase.Updated AnalogInputPortBase.VoltageSampleBuffer AnalogInputPortBase.UpdateInterval AnalogInputPortBase.SampleCount AnalogInputPortBase.SampleInterval AnalogInputPortBase.ReferenceVoltage AnalogInputPortBase.Voltage AnalogInputPortBase.Observers AnalogInputPortBase.ConvertReadingToVoltage(int) AnalogInputPortBase.RaiseChangedAndNotify(IChangeResult<Voltage>) AnalogInputPortBase.Subscribe(IObserver<IChangeResult<Voltage>>) PortBase<IAnalogChannelInfo>.disposed PortBase<IAnalogChannelInfo>.Channel PortBase<IAnalogChannelInfo>.Pin PortBase<IAnalogChannelInfo>.Dispose(bool) PortBase<IAnalogChannelInfo>.Dispose() object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString()
Namespace Meadow.Hardware
Assembly Meadow.dll

Syntax

public class AnalogInputPort : AnalogInputPortBase, IAnalogInputPort, IAnalogPort, IPort<IAnalogChannelInfo>, IDisposable, IObservable<IChangeResult<Voltage>>

Constructors

AnalogInputPort(IPin, IMeadowIOController, IAnalogChannelInfo, int, TimeSpan, Voltage)

Creates an AnalogInputPort given the provided parameters

Declaration
protected AnalogInputPort(IPin pin, IMeadowIOController ioController, IAnalogChannelInfo channel, int sampleCount, TimeSpan sampleInterval, Voltage referenceVoltage)

Parameters

Type Name Description
IPin pin

The IPin to use for the input port

IMeadowIOController ioController

The IMeadowIOController for the pin

IAnalogChannelInfo channel

The pin's channel info

int sampleCount

The number of ADC readings to average for a single sample

TimeSpan sampleInterval

The time between readings used for calculating the average for a sample

Voltage referenceVoltage

The ADCs reference voltage

Exceptions

Type Condition
PortInUseException

Fields

DefaultReferenceVoltage

The default reference voltage for the Input (3.3V)

Declaration
public static readonly Voltage DefaultReferenceVoltage

Field Value

Type Description
Voltage

DefaultSampleInterval

The default sampling interval for the Input (40ms)

Declaration
public static readonly TimeSpan DefaultSampleInterval

Field Value

Type Description
TimeSpan

Properties

IOController

Gets the IOController device

Declaration
protected IMeadowIOController IOController { get; }

Property Value

Type Description
IMeadowIOController

IsSampling

Gets a value indicating whether the analog input port is currently sampling the ADC. Call StartUpdating() to spin up the sampling process.

Declaration
public bool IsSampling { get; protected set; }

Property Value

Type Description
bool

true if sampling; otherwise, false.

PreviousVoltageReading

Gets or sets the previous voltage reading

Declaration
protected Voltage? PreviousVoltageReading { get; set; }

Property Value

Type Description
Voltage?

Methods

From(IPin, IMeadowIOController, int)

Creates an AnalogInputPort given the provided parameters

Declaration
public static AnalogInputPort From(IPin pin, IMeadowIOController ioController, int sampleCount = 5)

Parameters

Type Name Description
IPin pin
IMeadowIOController ioController
int sampleCount

Returns

Type Description
AnalogInputPort

From(IPin, IMeadowIOController, int, TimeSpan, Voltage)

Creates an AnalogInputPort given the provided parameters

Declaration
public static AnalogInputPort From(IPin pin, IMeadowIOController ioController, int sampleCount, TimeSpan sampleInterval, Voltage referenceVoltage)

Parameters

Type Name Description
IPin pin
IMeadowIOController ioController
int sampleCount
TimeSpan sampleInterval
Voltage referenceVoltage

Returns

Type Description
AnalogInputPort

Exceptions

Type Condition
ArgumentException
Exception

Read()

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

Declaration
public override Task<Voltage> Read()

Returns

Type Description
Task<Voltage>

Read Voltage

Overrides

StartUpdating(TimeSpan?)

Starts sampling the ADC and populating the sample buffer with values.

When sampling, the AnalogInputPort will take multiple readings (samples); waiting for the sampleIntervalDuration in between them, and fill the sample buffer with those values, then sleep for the duration specified in readIntervalDuration.

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

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

Parameters

Type Name Description
TimeSpan? updateInterval

A TimeSpan to wait between sets of sample readings. This value determines how often Changed events are raised and IObservable consumers are notified.

Overrides

StopUpdating()

Spins down the process sampling the ADC. Any values in the SampleBuffer will become stale after calling this method.

Declaration
public override void StopUpdating()

Overrides