Skip to content

Raspberry.IO.GeneralPurpose.GpioConnection

raspberry-sharp edited this page Oct 24, 2012 · 23 revisions

The GpioConnection class is used in conjunction with GpioConnectionSettings and PinConfiguration to manage a connection to a consistent set of pins (either input or output). Please refer to related documentation for detailed information concerning connection settings and configuration of GPIO pins.

Since GpioConnection implements the IDisposable interface, it must be closed once used, by calling either IDisposable.Dispose or Close.

Initializers

The following initializers may be used to create an instance of GpioConnection:

GpioConnection(params PinConfiguration[] pins);
GpioConnection(IEnumerable<PinConfiguration> pins);
GpioConnection(GpioConnectionSettings settings, params PinConfiguration[] pins);
GpioConnection(GpioConnectionSettings settings, IEnumerable<PinConfiguration> pins);
Parameters
  • pins: configurations of pins that must be allocated when connection is established.
  • settings: settings for the connection. See GpioConnectionSettings for more information.

Properties

The following properties are available on GpioConnection:

IsOpened

bool IsOpened { get; }

A boolean value indicating whether the connection is opened.

Pins

ConnectedPins Pins { get; }

A container of connected pins, providing access to each pin status and event registration. See ConnectedPins for additional information.

this (Indexers)

bool this[ProcessorPin processorPin] { get; set; }
bool this[ConnectorPin connectorPin] { get; set; }
bool this[PinConfiguration pinConfiguration] { get; set; }
bool this[string pinName] { get; set; }

Gets or sets the state of a pin. An exception is thrown if attempt is made to set the value of an input pin.

Parameters
  • processorPin: a pin, as numbered on processor
  • connectorPin: a pin, as numbered on Raspberry Pi P1 or P5 connector
  • pinConfiguration: a pin configuration, as defined by PinConfiguration
  • pinName: a pin name, if defined in pin configuration

Methods

The following methods are available on GpioConnection:

Add

void Add(PinConfiguration configuration);

Adds a pin to the connection.

Parameters
  • configuration: the pin configuration.

Blink

void Blink(ProcessorPin processorPin, decimal duration = -1);
void Blink(ConnectorPin connectorPin, decimal duration = -1);
void Blink(PinConfiguration pinConfiguration, decimal duration = -1);
void Blink(string pinName, decimal duration = -1);

Blinks (toogle, wait a specified amount of time, then toggle again) a specified pin.

Parameters
  • processorPin: a pin, as numbered on processor
  • connectorPin: a pin, as numbered on Raspberry Pi P1 or P5 connector
  • pinConfiguration: a pin configuration, as defined by PinConfiguration
  • pinName: a pin name, if defined in pin configuration
  • duration: the blink duration, in milliseconds. By default, the GpioConnectionSettings.BlinkDuration is used.

Clear

void Clear();

Clears the connection; that is, remove all pins.

Close

void Close();

Closes the connection and release all pins.

Contains

bool Contains(ProcessorPin processorPin);
bool Contains(ConnectorPin connectorPin);
bool Contains(PinConfiguration pinConfiguration);
bool Contains(string pinName);

Indicates whether the connection contains the specified pin.

Parameters
  • processorPin: a pin, as numbered on processor
  • connectorPin: a pin, as numbered on Raspberry Pi P1 or P5 connector
  • pinConfiguration: a pin configuration, as defined by PinConfiguration
  • pinName: a pin name, if defined in pin configuration
Return value

A boolean value indicating whether the specified pin is associated with the current connection.

Open

void Open();

Opens a connection.

Remove

void Remove(ProcessorPin processorPin);
void Remove(ConnectorPin connectorPin);
void Remove(PinConfiguration pinConfiguration);
void Remove(string pinName);

Removes a pin from the connection, and releases related resources.

Parameters
  • processorPin: a pin, as numbered on processor
  • connectorPin: a pin, as numbered on Raspberry Pi P1 or P5 connector
  • pinConfiguration: a pin configuration, as defined by PinConfiguration
  • pinName: a pin name, if defined in pin configuration

Toggle

void Toggle(ProcessorPin processorPin);
void Toggle(ConnectorPin connectorPin);
void Toggle(PinConfiguration pinConfiguration);
void Toggle(string pinName);

Toggles (inverts) the state of a pin.

Parameters
  • processorPin: a pin, as numbered on processor
  • connectorPin: a pin, as numbered on Raspberry Pi P1 or P5 connector
  • pinConfiguration: a pin configuration, as defined by PinConfiguration
  • pinName: a pin name, if defined in pin configuration

Events

The following event is available on GpioConnection:

PinStatusChanged

EventHandler<PinStatusEventArgs> PinStatusChanged;

Fired when the status of a pin changed. PinStatusEventArgs class provides access to the pin configuration and current state.