GpioChangeCounter GpioChangeCounter GpioChangeCounter GpioChangeCounter Class

Definition

Counts changes of a specified polarity on a general-purpose I/O (GPIO) pin.

public : sealed class GpioChangeCounter : IGpioChangeCounter, IClosablepublic sealed class GpioChangeCounter : IGpioChangeCounter, IDisposablePublic NotInheritable Class GpioChangeCounter Implements IGpioChangeCounter, IDisposable// You can use this class in JavaScript.
Attributes
Windows 10 requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Devices.DevicesLowLevelContract (introduced v3)

Remarks

When the pin is an input, interrupts are used to detect pin changes. Interrupts for the pin are enabled for the specified polarity, and the count is incremented when an interrupt occurs.

When the pin is an output, the count will increment whenever the specified transition occurs on the pin. For example, if the pin is configured as an output and counting is enabled for rising edges, writing a 0 and then a 1 will cause the count to be incremented.

Constructors

GpioChangeCounter(GpioPin) GpioChangeCounter(GpioPin) GpioChangeCounter(GpioPin) GpioChangeCounter(GpioPin)

Creates a new GpioChangeCounter associated with the specified pin. Only a single GpioChangeCounter may be associated with a pin at any given time.

public : GpioChangeCounter(GpioPin pin)public GpioChangeCounter(GpioPin pin)Public Sub New(pin As GpioPin)// You can use this method in JavaScript.
Parameters
pin
GpioPin GpioPin GpioPin GpioPin

The pin on which to count changes. This pin must have been opened in Exclusive mode, and cannot be associated with another GpioChangeCounter.

Remarks

The following exceptions can be thrown by this method:

  • E_POINTER - The pin passed in is null.
  • HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION) - The pin is already associated with a change counter. That change counter must be disposed before the pin can be associated with a new change counter.
  • E_ACCESSDENIED - The pin is not opened in Exclusive mode.

Properties

IsStarted IsStarted IsStarted IsStarted

Gets whether pin change counting is currently active.

public : PlatForm::Boolean IsStarted { get; }public bool IsStarted { get; }Public ReadOnly Property IsStarted As bool// You can use this property in JavaScript.
Value
PlatForm::Boolean bool bool bool

Remarks

Returns TRUE if pin change counting is active, and FALSE otherwise.

Polarity Polarity Polarity Polarity

Gets or sets the polarity of transitions that will be counted. The polarity may only be changed when pin counting is not started.

public : GpioChangePolarity Polarity { get; set; }public GpioChangePolarity Polarity { get; set; }Public ReadWrite Property Polarity As GpioChangePolarity// You can use this property in JavaScript.

Remarks

The default polarity value is Falling. See GpioChangePolarity for more information on polarity values. Counting a single edge can be considerably more efficient than counting both edges.

The following exceptions can be thrown when setting the polarity:

  • E_INVALIDARG - value is not a valid GpioChangePolarity value.
  • HRESULT_FROM_WIN32(ERROR_BAD_COMMAND) - change counting is currently active. Polarity can only be set before calling Start() or after calling Stop().

Methods

Close() Close() Close() Close()

Closes the change counter, disassociating it from its pin.

public : void Close()This member is not implemented in C#This member is not implemented in VB.Net// You can use this method in JavaScript.

Remarks

If change counting is active for this counter, calling this method will also stop it.

Dispose() Dispose() Dispose() Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

This member is not implemented in C++void Dispose()Sub Disposevoid Dispose()

Read() Read() Read() Read()

Reads the current count of polarity changes. Before counting has been started, this will return 0.

public : GpioChangeCount Read()public GpioChangeCount Read()Public Function Read() As GpioChangeCount// You can use this method in JavaScript.
Returns

A GpioChangeCount structure containing a count and an associated timestamp.

Remarks

The following exception can be thrown by this method:

  • HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE) - the change counter or the associated pin has been disposed.

Reset() Reset() Reset() Reset()

Resets the count to 0 and returns the previous count.

public : GpioChangeCount Reset()public GpioChangeCount Reset()Public Function Reset() As GpioChangeCount// You can use this method in JavaScript.
Returns

A GpioChangeCount structure containing a count and an associated timestamp.

Remarks

The following exception can be thrown by this method:

  • HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE) - the change counter or the associated pin has been disposed.

Start() Start() Start() Start()

Starts counting changes in pin polarity. This method may only be called when change counting is not already active.

public : void Start()public void Start()Public Function Start() As void// You can use this method in JavaScript.

Remarks

Calling Start() may enable or reconfigure interrupts for the pin.

The following exceptions can be thrown by this method:

  • HRESULT_FROM_WIN32(ERROR_BAD_COMMAND) - change counting has already been started.
  • HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE) - the change counter or the associated pin has been disposed.

Stop() Stop() Stop() Stop()

Stop counting changes in pin polarity. This method may only be called when change counting is currently active.

public : void Stop()public void Stop()Public Function Stop() As void// You can use this method in JavaScript.

Remarks

Calling Stop() may disable or reconfigure interrupts for the pin.

The following exceptions can be thrown by this method:

  • HRESULT_FROM_WIN32(ERROR_BAD_COMMAND) - change counting is not currently active.
  • HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE) - the change counter or the associated pin has been disposed.