Table of Contents

Class GpioController

Namespace
System.Device.Gpio
Assembly
System.Device.Gpio.dll

Represents a general-purpose I/O (GPIO) controller.

public sealed class GpioController : IDisposable
Inheritance
GpioController
Implements
Inherited Members
Extension Methods

Constructors

GpioController()

Initializes a new instance of the System.Device.Gpio.GpioController class that will use the logical pin numbering scheme as default.

public GpioController()

GpioController(PinNumberingScheme)

Initializes a new instance of the System.Device.Gpio.GpioController class that will use the specified numbering scheme. The controller will default to use the driver that best applies given the platform the program is executing on.

public GpioController(PinNumberingScheme numberingScheme)

Parameters

numberingScheme PinNumberingScheme

The numbering scheme used to represent pins provided by the controller.

Properties

NumberingScheme

The numbering scheme used to represent pins provided by the controller.

public PinNumberingScheme NumberingScheme { get; }

Property Value

PinNumberingScheme

PinCount

The number of pins provided by the controller.

public int PinCount { get; }

Property Value

int

Methods

ClosePin(int)

Closes an open pin.

public void ClosePin(int pinNumber)

Parameters

pinNumber int

The pin number in the controller's numbering scheme.

Exceptions

InvalidOperationException

This exception will be thrown on an attempt to close a pin that hasn't been opened.

Dispose()

Dispose the controller

public void Dispose()

GetPinMode(int)

Gets the mode of a pin.

public PinMode GetPinMode(int pinNumber)

Parameters

pinNumber int

The pin number in the controller's numbering scheme.

Returns

PinMode

The mode of the pin.

IsPinModeSupported(int, PinMode)

Checks if a pin supports a specific mode.

public bool IsPinModeSupported(int pinNumber, PinMode mode)

Parameters

pinNumber int

The pin number in the controller's numbering scheme.

mode PinMode

The mode to check.

Returns

bool

The status if the pin supports the mode.

IsPinOpen(int)

Checks if a specific pin is open.

public bool IsPinOpen(int pinNumber)

Parameters

pinNumber int

The pin number in the controller's numbering scheme.

Returns

bool

The status if the pin is open or closed.

OpenPin(int)

Opens a pin in order for it to be ready to use.

public GpioPin OpenPin(int pinNumber)

Parameters

pinNumber int

The pin number in the controller's numbering scheme.

Returns

GpioPin

The opened GPIO pin.

Exceptions

InvalidOperationException

This exception will be thrown if the pin is already open.

OpenPin(int, PinMode)

Opens a pin and sets it to a specific mode.

public GpioPin OpenPin(int pinNumber, PinMode mode)

Parameters

pinNumber int

The pin number in the controller's numbering scheme.

mode PinMode

The mode to be set.

Returns

GpioPin

The opened GPIO pin.

Read(int)

Reads the current value of a pin.

public PinValue Read(int pinNumber)

Parameters

pinNumber int

The pin number in the controller's numbering scheme.

Returns

PinValue

The value of the pin.

RegisterCallbackForPinValueChangedEvent(int, PinEventTypes, PinChangeEventHandler)

Adds a callback that will be invoked when pinNumber has an event of type eventType.

public void RegisterCallbackForPinValueChangedEvent(int pinNumber, PinEventTypes eventTypes, PinChangeEventHandler callback)

Parameters

pinNumber int

The pin number in the controller's numbering scheme.

eventTypes PinEventTypes

The event types to wait for.

callback PinChangeEventHandler

The callback method that will be invoked.

Exceptions

InvalidOperationException

This exception will be thrown on an attempt to register a callback to a pin that hasn't been opened.

SetPinMode(int, PinMode)

Sets the mode to a pin.

public void SetPinMode(int pinNumber, PinMode mode)

Parameters

pinNumber int

The pin number in the controller's numbering scheme

mode PinMode

The mode to be set.

UnregisterCallbackForPinValueChangedEvent(int, PinChangeEventHandler)

Removes a callback that was being invoked for pin at pinNumber.

public void UnregisterCallbackForPinValueChangedEvent(int pinNumber, PinChangeEventHandler callback)

Parameters

pinNumber int

The pin number in the controller's numbering scheme.

callback PinChangeEventHandler

The callback method that will be invoked.

Write(int, PinValue)

Writes a value to a pin.

public void Write(int pinNumber, PinValue value)

Parameters

pinNumber int

The pin number in the controller's numbering scheme.

value PinValue

The value to be written to the pin.