Class GpioLine
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
Offset
The line's number on its chip.
public uint Offset { get; }
Property Value
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
levelPinLevelThe level to drive.
Exceptions
- PamojaException
The kernel refused the write, which an input line does.
- ArgumentOutOfRangeException
levelis not one of the PinLevel values.
OpenInput(string, uint)
Opens a line as an input.
public static GpioLine OpenInput(string chip, uint line)
Parameters
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
chipstringThe GPIO chip's device file,
/dev/gpiochip0on most boards.lineuintThe line's number on that chip, the GPIO or BCM number on a Raspberry Pi.
initialPinLevelThe 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
initialis 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.