Udostępnij za pośrednictwem


GpioController.OpenPin Method

Definition

Overloads

OpenPin(Int32)

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

OpenPin(Int32, GpioSharingMode)

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

OpenPin(Int32)

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

public:
 virtual GpioPin ^ OpenPin(int pinNumber) = OpenPin;
/// [Windows.Foundation.Metadata.Overload("OpenPin")]
GpioPin OpenPin(int const& pinNumber);
[Windows.Foundation.Metadata.Overload("OpenPin")]
public GpioPin OpenPin(int pinNumber);
function openPin(pinNumber)
Public Function OpenPin (pinNumber As Integer) As GpioPin

Parameters

pinNumber
Int32

int

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.

Attributes

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

Applies to

OpenPin(Int32, GpioSharingMode)

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

public:
 virtual GpioPin ^ OpenPin(int pinNumber, GpioSharingMode sharingMode) = OpenPin;
/// [Windows.Foundation.Metadata.Overload("OpenPinWithSharingMode")]
GpioPin OpenPin(int const& pinNumber, GpioSharingMode const& sharingMode);
[Windows.Foundation.Metadata.Overload("OpenPinWithSharingMode")]
public GpioPin OpenPin(int pinNumber, GpioSharingMode sharingMode);
function openPin(pinNumber, sharingMode)
Public Function OpenPin (pinNumber As Integer, sharingMode As GpioSharingMode) As GpioPin

Parameters

pinNumber
Int32

int

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

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.

Attributes

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

Applies to