Skip to main content

DigitalSignal Class

NuGet: GHIElectronics.TinyCLR.Devices.Signals
Assembly: GHIElectronics.TinyCLR.Devices.Signals
Namespace: GHIElectronics.TinyCLR.Devices.Signals

DMA/timer-backed pulse-train I/O on a small set of pins. Capable of pulse counting (ReadPulse), high-resolution edge capture (Capture), and emitting pulse-width-modulated sequences (Generate). All three operations are mutually exclusive and run asynchronously — completion is reported via OnReadPulseFinished / OnCaptureFinished / OnGenerateFinished. Only specific pins are supported (currently 0, 1, and 19).

public class DigitalSignal : IDisposable

Constructors

DigitalSignal(GpioPin pin)

public DigitalSignal(GpioPin pin)

Opens a digital-signal session on a supported pin (0, 1, or 19).

Properties

CanReadPulse

public bool CanReadPulse { get; }

True when no operation is in progress and ReadPulse may be called.

CanCapture

public bool CanCapture { get; }

True when no operation is in progress and Capture may be called.

CanGenerate

public bool CanGenerate { get; }

True when no operation is in progress and Generate may be called.

Methods

Dispose()

public void Dispose()

Releases the native pulse-train resources.

Dispose(bool disposing)

protected virtual void Dispose(bool disposing)

Dispose implementation.

ReadPulse(uint pulseNum, GpioPinEdge edge, bool waitForEdge)

public void ReadPulse(uint pulseNum, GpioPinEdge edge, bool waitForEdge)

Counts up to pulseNum edges matching edge and measures the total elapsed time. Result is delivered via OnReadPulseFinished.

ParameterTypeDescription
pulseNumuintNumber of edges to count.
edgeGpioPinEdgeWhich edge(s) to count.
waitForEdgeboolWhen true, the timer starts on the first matching edge instead of immediately.

Capture(uint bufferSize, GpioPinEdge edge, bool waitForEdge)

public void Capture(uint bufferSize, GpioPinEdge edge, bool waitForEdge)

Captures inter-edge intervals. See full-parameter overload for buffer-layout details.

Capture(uint count, GpioPinEdge edge, bool waitForEdge, TimeSpan timeout)

public void Capture(uint count, GpioPinEdge edge, bool waitForEdge, TimeSpan timeout)

Capture timestamps of count edges on the pin.

Generate(uint[] data, uint offset, uint count)

public void Generate(uint[] data, uint offset, uint count)

Emits a pulse train described by data with default multiplier and starting high.

Generate(uint[] data, uint offset, uint count, uint multiplier)

public void Generate(uint[] data, uint offset, uint count, uint multiplier)

Emits a pulse train with explicit multiplier and starting high.

Generate(uint[] data, uint offset, uint count, uint multiplier, GpioPinValue startingPolarity)

public void Generate(uint[] data, uint offset, uint count, uint multiplier, GpioPinValue startingPolarity)

Emits the pulse train once (equivalent to repeatCount: 1).

Generate(uint[] data, uint offset, uint count, uint multiplier, GpioPinValue startingPolarity, uint repeatCount)

public void Generate(uint[] data, uint offset, uint count, uint multiplier, GpioPinValue startingPolarity, uint repeatCount=1)

Emits a pulse train: each data entry is a duration in timer ticks, alternating polarity starting from startingPolarity. The waveform can be repeated back-to-back with no gap between repeats.

ParameterTypeDescription
datauint[]Buffer of segment durations.
offsetuintStarting index in data.
countuintNumber of entries to emit.
multiplieruintMultiplier applied to each duration entry (timer-tick scaling).
startingPolarityGpioPinValuePolarity of the first segment.
repeatCountuintHow many times to play the waveform: 1 = once (default, single shot); N > 1 = play N times back-to-back then stop and raise OnGenerateFinished; 0 = repeat forever until Abort (or Dispose()) is called. In repeat mode the output runs off a circular DMA so there is no gap between repeats. For the waveform to repeat identically, provide an even number of transitions (count even) so the pin returns to startingPolarity at the end of each cycle; an odd count inverts the polarity every cycle (inherent to toggle output).

Abort()

public void Abort()

Aborts the running operation, if any. Safe to call during an infinite (repeatCount: 0) or multi-shot Generate: it stops the circular DMA, returns the driver to idle, and raises OnGenerateFinished so the next Generate(uint[], uint, uint, uint, GpioPinValue, uint) call re-arms cleanly.

Events

OnReadPulseFinished

public event PulseReadEventHandler OnReadPulseFinished

Raised when ReadPulse completes.

OnCaptureFinished

public event PulseCaptureEventHandler OnCaptureFinished

Raised when Capture completes.

OnGenerateFinished

public event PulseGenerateEventHandler OnGenerateFinished

Raised when Generate completes.