Table of Contents

Class GpioLine

Namespace
Pamoja.Gpio
Assembly
Pamoja.Gpio.dll

A GPIO line opened on a Linux board, through the kernel's GPIO character device: the line a Switch<TLine> or a Contact<TLine> sits over on a Raspberry Pi or any Linux board.

public sealed class GpioLine : IOutputLine, IInputLine, IDisposable
Inheritance
GpioLine
Implements
Inherited Members

Remarks

A line is held by one process at a time, and the kernel names the holder, which gpioinfo prints; a line another program or a kernel driver holds cannot be opened until it is let go. On Raspberry Pi OS a user in the gpio group opens lines without root. Dispose the line to hand it back.

Only Linux has the GPIO character device; every other platform throws PlatformNotSupportedException.

Properties

Chip

The GPIO chip's device file.

public string Chip { get; }

Property Value

string

Offset

The line's number on its chip.

public uint Offset { get; }

Property Value

uint

Methods

Dispose()

Hands the line back to the kernel.

public void Dispose()

Drive(PinLevel)

Drives the line to a level. The line must have been opened as an output.

public void Drive(PinLevel level)

Parameters

level PinLevel

The level to drive.

Exceptions

PamojaException

The kernel refused the write, which an input line does.

ArgumentOutOfRangeException

level is not one of the PinLevel values.

OpenInput(string, uint)

Opens a line as an input.

public static GpioLine OpenInput(string chip, uint line)

Parameters

chip string

The GPIO chip's device file.

line uint

The line's number on that chip.

Returns

GpioLine

The line.

Exceptions

PlatformNotSupportedException

The platform is not Linux.

PamojaException

The chip or the line could not be opened.

OpenOutput(string, uint, PinLevel)

Opens a line as an output, driving initial from the moment it is taken.

public static GpioLine OpenOutput(string chip, uint line, PinLevel initial)

Parameters

chip string

The GPIO chip's device file, /dev/gpiochip0 on most boards.

line uint

The line's number on that chip, the GPIO or BCM number on a Raspberry Pi.

initial PinLevel

The level to drive as soon as the line is taken; an active-low relay is opened high so it stays off.

Returns

GpioLine

The line.

Exceptions

PlatformNotSupportedException

The platform is not Linux.

PamojaException

The chip or the line could not be opened.

ArgumentOutOfRangeException

initial is not one of the PinLevel values.

Read()

Reads the level on the line now.

public PinLevel Read()

Returns

PinLevel

The level.

Exceptions

PamojaException

The kernel refused the read.