Characteristic Locus
Inheritance System.Object PortBase<IAnalogChannelInfo> AnalogPortBase AnalogInputPortBase > AnalogInputPort
Implements IAnalogPort IAnalogInputPort IObservable<IChangeResult<Voltage>>
Inherited Members AnalogInputPortBase.BufferSyncRoot AnalogInputPortBase.Updated AnalogInputPortBase.VoltageSampleBuffer AnalogInputPortBase.UpdateInterval AnalogInputPortBase.SampleCount AnalogInputPortBase.SampleInterval AnalogInputPortBase.ReferenceVoltage AnalogInputPortBase.Voltage AnalogInputPortBase.observers AnalogInputPortBase.RaiseChangedAndNotify(IChangeResult<Voltage>) AnalogInputPortBase.Subscribe(IObserver<IChangeResult<Voltage>>) PortBase<IAnalogChannelInfo>.disposed PortBase<IAnalogChannelInfo>.Channel PortBase<IAnalogChannelInfo>.Pin PortBase<IAnalogChannelInfo>.Dispose(Boolean) PortBase<IAnalogChannelInfo>.Dispose()
Namespace Meadow.Hardware
Assembly Meadow.dll

Syntax

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

Constructors

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

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

Parameters

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

Fields

_previousVoltageReading

Declaration
protected Voltage? _previousVoltageReading

Field Value

Type Description
System.Nullable<Voltage>

DefaultReferenceVoltage

Declaration
public static readonly Voltage DefaultReferenceVoltage

Field Value

Type Description
Voltage

DefaultSampleInterval

Declaration
public static readonly TimeSpan DefaultSampleInterval

Field Value

Type Description
TimeSpan

Properties

IOController

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

true if sampling; otherwise, false.

Methods

From(IPin, IMeadowIOController, Int32)

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

Parameters

Type Name Description
IPin pin
IMeadowIOController ioController
System.Int32 sampleCount

Returns

Type Description
AnalogInputPort

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

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

Parameters

Type Name Description
IPin pin
IMeadowIOController ioController
System.Int32 sampleCount
TimeSpan sampleInterval
Voltage referenceVoltage

Returns

Type Description
AnalogInputPort

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(Nullable<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
System.Nullable<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