Class GpioController
Represents a general-purpose I/O (GPIO) controller.
Implements
Inherited Members
Namespace: System.Device.Gpio
Assembly: System.Device.Gpio.dll
Syntax
public sealed class GpioController : IDisposable
Constructors
| Improve this Doc View SourceGpioController()
Initializes a new instance of the System.Device.Gpio.GpioController class that will use the logical pin numbering scheme as default.
Declaration
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.
Declaration
public GpioController(PinNumberingScheme numberingScheme)
Parameters
Type | Name | Description |
---|---|---|
PinNumberingScheme | numberingScheme | The numbering scheme used to represent pins provided by the controller. |
Properties
| Improve this Doc View SourceNumberingScheme
The numbering scheme used to represent pins provided by the controller.
Declaration
public PinNumberingScheme NumberingScheme { get; }
Property Value
Type | Description |
---|---|
PinNumberingScheme |
PinCount
The number of pins provided by the controller.
Declaration
public int PinCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
| Improve this Doc View SourceClosePin(Int32)
Closes an open pin.
Declaration
public void ClosePin(int pinNumber)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pinNumber | The pin number in the controller's numbering scheme. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | This exception will be thrown on an attempt to close a pin that hasn't been opened. |
Dispose()
Dispose the controller
Declaration
public void Dispose()
GetPinMode(Int32)
Gets the mode of a pin.
Declaration
public PinMode GetPinMode(int pinNumber)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pinNumber | The pin number in the controller's numbering scheme. |
Returns
Type | Description |
---|---|
PinMode | The mode of the pin. |
IsPinModeSupported(Int32, PinMode)
Checks if a pin supports a specific mode.
Declaration
public extern bool IsPinModeSupported(int pinNumber, PinMode mode)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pinNumber | The pin number in the controller's numbering scheme. |
PinMode | mode | The mode to check. |
Returns
Type | Description |
---|---|
Boolean | The status if the pin supports the mode. |
IsPinOpen(Int32)
Checks if a specific pin is open.
Declaration
public extern bool IsPinOpen(int pinNumber)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pinNumber | The pin number in the controller's numbering scheme. |
Returns
Type | Description |
---|---|
Boolean | The status if the pin is open or closed. |
OpenPin(Int32)
Opens a pin in order for it to be ready to use.
Declaration
public GpioPin OpenPin(int pinNumber)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pinNumber | The pin number in the controller's numbering scheme. |
Returns
Type | Description |
---|---|
GpioPin | The opened GPIO pin. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | This exception will be thrown if the pin is already open. |
OpenPin(Int32, PinMode)
Opens a pin and sets it to a specific mode.
Declaration
public GpioPin OpenPin(int pinNumber, PinMode mode)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pinNumber | The pin number in the controller's numbering scheme. |
PinMode | mode | The mode to be set. |
Returns
Type | Description |
---|---|
GpioPin | The opened GPIO pin. |
Read(Int32)
Reads the current value of a pin.
Declaration
public PinValue Read(int pinNumber)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pinNumber | The pin number in the controller's numbering scheme. |
Returns
Type | Description |
---|---|
PinValue | The value of the pin. |
RegisterCallbackForPinValueChangedEvent(Int32, PinEventTypes, PinChangeEventHandler)
Adds a callback that will be invoked when pinNumber has an event of type eventType.
Declaration
public void RegisterCallbackForPinValueChangedEvent(int pinNumber, PinEventTypes eventTypes, PinChangeEventHandler callback)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pinNumber | The pin number in the controller's numbering scheme. |
PinEventTypes | eventTypes | The event types to wait for. |
PinChangeEventHandler | callback | The callback method that will be invoked. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | This exception will be thrown on an attempt to register a callback to a pin that hasn't been opened. |
SetPinMode(Int32, PinMode)
Sets the mode to a pin.
Declaration
public extern void SetPinMode(int pinNumber, PinMode mode)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pinNumber | The pin number in the controller's numbering scheme |
PinMode | mode | The mode to be set. |
UnregisterCallbackForPinValueChangedEvent(Int32, PinChangeEventHandler)
Removes a callback that was being invoked for pin at pinNumber.
Declaration
public void UnregisterCallbackForPinValueChangedEvent(int pinNumber, PinChangeEventHandler callback)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pinNumber | The pin number in the controller's numbering scheme. |
PinChangeEventHandler | callback | The callback method that will be invoked. |
Write(Int32, PinValue)
Writes a value to a pin.
Declaration
public void Write(int pinNumber, PinValue value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pinNumber | The pin number in the controller's numbering scheme. |
PinValue | value | The value to be written to the pin. |