GpioController.OpenPin GpioController.OpenPin GpioController.OpenPin GpioController.OpenPin GpioController.OpenPin Method

Definition

Overloads

OpenPin(Int32) OpenPin(Int32) OpenPin(Int32) OpenPin(Int32) OpenPin(Int32)

Opens a connection to the specified general-purpose I/O (GPIO) pin in exclusive mode.

OpenPin(Int32, GpioSharingMode) OpenPin(Int32, GpioSharingMode) OpenPin(Int32, GpioSharingMode) OpenPin(Int32, GpioSharingMode) OpenPin(Int32, GpioSharingMode)

Opens the specified general-purpose I/O (GPIO) pin in the specified mode.

OpenPin(Int32) OpenPin(Int32) OpenPin(Int32) OpenPin(Int32) OpenPin(Int32)

Opens a connection to the specified general-purpose I/O (GPIO) pin in exclusive mode.

public : GpioPin OpenPin(int pinNumber)
GpioPin OpenPin(int32_t pinNumber) const;
public GpioPin OpenPin(Int32 pinNumber)
Public Function OpenPin(pinNumber As Int32) As GpioPin
var gpioPin = gpioController.openPin(pinNumber);

Parameters

pinNumber
Int32 Int32 Int32

The pin number of the GPIO pin that you want to open. The pin number must be

  • in range
  • available to usermode applications

Pin numbers start at 0, and increase to the maximum pin number, which is one less than the value returned by GpioController.PinCount.

Which pins are available to usermode depends on the circuit board on which the code is running. For information about how pin numbers correspond to physical pins, see the documentation for your circuit board. Pin mappings for boards such as the Raspberry Pi are available at the IoT developer center.

Returns

The opened GPIO pin.

Remarks

Error codes:

E_INVALIDARG (0x80070057)

An invalid parameter was specified. This error will be returned if the pin number is out of range. Pin numbers start at 0 and increase to the maximum pin number, which is one less than the value returned by GpioController.PinCount.

HRESULT_FROM_WIN32(ERROR_NOT_FOUND) (0x80070490)

The pin is not available to usermode applications; it is reserved by the system. See the documentation for your circuit board to find out which pins are available to usermode applications.

HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION) (0x80070020)

The pin is currently open in an incompatible sharing mode. For example:

  • The pin is already open in GpioSharingMode.Exclusive mode.
  • The pin is already open in GpioSharingMode.SharedReadOnly mode when you request to open it in GpioSharingMode.Exclusive mode.

HRESULT_FROM_WIN32(ERROR_GPIO_INCOMPATIBLE_CONNECT_MODE) (0x80073bde)

The pin is currently muxed to a different function; for example I2C, SPI, or UART. Ensure the pin is not in use by another function.

HRESULT_FROM_WIN32(ERROR_GEN_FAILURE) (0x8007001f)

The GPIO driver returned an error. Ensure that the GPIO driver is running and configured correctly.

See also

OpenPin(Int32, GpioSharingMode) OpenPin(Int32, GpioSharingMode) OpenPin(Int32, GpioSharingMode) OpenPin(Int32, GpioSharingMode) OpenPin(Int32, GpioSharingMode)

Opens the specified general-purpose I/O (GPIO) pin in the specified mode.

public : GpioPin OpenPin(int pinNumber, GpioSharingMode sharingMode)
GpioPin OpenPin(int32_t pinNumber, GpioSharingMode sharingMode) const;
public GpioPin OpenPin(Int32 pinNumber, GpioSharingMode sharingMode)
Public Function OpenPin(pinNumber As Int32, sharingMode As GpioSharingMode) As GpioPin
var gpioPin = gpioController.openPin(pinNumber, sharingMode);

Parameters

pinNumber
Int32 Int32 Int32

The pin number of the GPIO pin that you want to open. The pin number must be

  • in range
  • available to usermode applications

Pin numbers start at 0, and increase to the maximum pin number, which is one less than the value returned by GpioController.PinCount.

Which pins are available to usermode depends on the circuit board on which the code is running. For information about how pin numbers correspond to physical pins, see the documentation for your circuit board. Pin mappings for boards such as the Raspberry Pi are available at the IoT developer center.

sharingMode
GpioSharingMode GpioSharingMode GpioSharingMode

The mode in which you want to open the GPIO pin, which determines whether other connections to the pin can be opened while you have the pin open.

Returns

The opened GPIO pin.

Remarks

Error Codes:

E_INVALIDARG (0x80070057)

An invalid parameter was specified. This error will be returned if the pin number is out of range. Pin numbers start at 0 and increase to the maximum pin number, which is one less than the value returned by GpioController.PinCount.

HRESULT_FROM_WIN32(ERROR_NOT_FOUND) (0x80070490)

The pin is not available to usermode applications; it is reserved by the system. See the documentation for your circuit board to find out which pins are available to usermode applications.

HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION) (0x80070020)

The pin is currently open in an incompatible sharing mode. For example:

  • The pin is already open in GpioSharingMode.Exclusive mode.
  • The pin is already open in GpioSharingMode.SharedReadOnly mode when you request to open it in GpioSharingMode.Exclusive mode.

HRESULT_FROM_WIN32(ERROR_GPIO_INCOMPATIBLE_CONNECT_MODE) (0x80073bde)

The pin is currently muxed to a different function; for example I2C, SPI, or UART. Ensure the pin is not in use by another function.

HRESULT_FROM_WIN32(ERROR_GEN_FAILURE) (0x8007001f)

The GPIO driver returned an error. Ensure that the GPIO driver is running and configured correctly.

See also