-
Notifications
You must be signed in to change notification settings - Fork 139
Raspberry.IO.GeneralPurpose.GpioConnection
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
.
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);
-
pins
: configurations of pins that must be allocated when connection is established. -
settings
: settings for the connection. See GpioConnectionSettings for more information.
The following properties are available on GpioConnection
:
bool IsOpened { get; }
A boolean value indicating whether the connection is opened.
ConnectedPins Pins { get; }
A container of connected pins, providing access to each pin status and event registration. See ConnectedPins for additional information.
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.
-
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
The following methods are available on GpioConnection
:
void Add(PinConfiguration configuration);
Adds a pin to the connection.
-
configuration
: the pin configuration.
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.
-
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, theGpioConnectionSettings.BlinkDuration
is used.
void Clear();
Clears the connection; that is, remove all pins.
void Close();
Closes the connection and release all pins.
bool Contains(ProcessorPin processorPin);
bool Contains(ConnectorPin connectorPin);
bool Contains(PinConfiguration pinConfiguration);
bool Contains(string pinName);
Indicates whether the connection contains the specified pin.
-
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
A boolean value indicating whether the specified pin is associated with the current connection.
void Open();
Opens a connection.
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.
-
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
void Toggle(ProcessorPin processorPin);
void Toggle(ConnectorPin connectorPin);
void Toggle(PinConfiguration pinConfiguration);
void Toggle(string pinName);
Toggles (inverts) the state of a pin.
-
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
The following event is available on GpioConnection
:
EventHandler<PinStatusEventArgs> PinStatusChanged;
Fired when the status of a pin changed. PinStatusEventArgs
class provides access to the pin configuration and current state.