C# Class CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider

This GPIO provider implements the PCF8574 I2C GPIO expansion board as native Pi4J GPIO pins. More information about the board can be found here: http://www.ti.com/lit/ds/symlink/pcf8574.pdf

The PCF8574 is connected via I2C connection to the Raspberry Pi and provides 8 GPIO pins that can be used for either digital input or digital output pins.
Inheritance: IDisposable
ファイルを表示 Open project: cyrusbuilt/MonoPi

Public Properties

Property Type Description
PinPollFailed PinPollFailEventHandler
PinStateChanged PinStateChangeEventHandler

Public Methods

Method Description
Dispose ( ) : void

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Call Dispose when you are finished using the CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider. The Dispose method leaves the CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider in an unusable state. After calling Dispose, you must release all references to the CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider so the garbage collector can reclaim the memory that the CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider was occupying.

GetPinMode ( IPCF8574Pin pin ) : PinMode

Gets the mode of the specified pin.

GetPinState ( IPCF8574Pin pin ) : PinState

Gets the current state of the specified pin in the pin cache.

InterruptPoll ( ) : void

Interrupts a poll cycle (if running).

PCF8574GpioProvider ( II2CBus device, Int32 address ) : System

Initializes a new instance of the CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider class with the I2C bus device that is the connection to the PCF8574, and the bus address of the device.

PCF8574GpioProvider ( Int32 address ) : System

Initializes a new instance of the CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider class with the bus address of the device. This overload assumes a Rev 2 or higher board and creates a default I2C connection instance.

Poll ( ) : void

Polls the state of the all the pins once every ~50ms.

SetPinMode ( IPCF8574Pin pin, PinMode mode ) : void

Sets the mode of the specified pin.

SetPinState ( IPCF8574Pin pin, PinState state ) : void

Sets the state of the specified pin.

Protected Methods

Method Description
OnPinPollFailed ( PinPollFailEventArgs e ) : void

Raises the PinPollFailed event.

OnPinStateChanged ( PinStateChangeEventArgs e ) : void

Raises the PinStateChanged event.

Private Methods

Method Description
BackgroundExecutePoll ( ) : void

Executes the poll cycle on a background thread.

ExecutePoll ( ) : void

Polls all the pins on the PCF8574 every ~50ms and refreshes their states. This will fire a state change event for any and all pins that have changed state since the last check. This will also fire a failure event if any exceptions are thrown.

Method Details

Dispose() public method

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Call Dispose when you are finished using the CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider. The Dispose method leaves the CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider in an unusable state. After calling Dispose, you must release all references to the CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider so the garbage collector can reclaim the memory that the CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider was occupying.
public Dispose ( ) : void
return void

GetPinMode() public method

Gets the mode of the specified pin.
/// cannot be null. /// /// This instance has been disposed and can no longer be used. /// /// The specified pin does not exist in the pin cache. ///
public GetPinMode ( IPCF8574Pin pin ) : PinMode
pin IPCF8574Pin /// A pin in the pin cache to get the mode from. ///
return PinMode

GetPinState() public method

Gets the current state of the specified pin in the pin cache.
/// cannot be null. /// /// This instance has been disposed and can no longer be used. /// /// The specified pin does not exist in the pin cache. ///
public GetPinState ( IPCF8574Pin pin ) : PinState
pin IPCF8574Pin /// The pin to get the state from. ///
return PinState

InterruptPoll() public method

Interrupts a poll cycle (if running).
public InterruptPoll ( ) : void
return void

OnPinPollFailed() protected method

Raises the PinPollFailed event.
protected OnPinPollFailed ( PinPollFailEventArgs e ) : void
e PinPollFailEventArgs /// The event arguments. ///
return void

OnPinStateChanged() protected method

Raises the PinStateChanged event.
protected OnPinStateChanged ( PinStateChangeEventArgs e ) : void
e PinStateChangeEventArgs /// The event arguments. ///
return void

PCF8574GpioProvider() public method

Initializes a new instance of the CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider class with the I2C bus device that is the connection to the PCF8574, and the bus address of the device.
public PCF8574GpioProvider ( II2CBus device, Int32 address ) : System
device II2CBus /// The I2C bus device that is the connection to the PCF8574. ///
address System.Int32 /// The bus address of the device. ///
return System

PCF8574GpioProvider() public method

Initializes a new instance of the CyrusBuilt.MonoPi.IO.PCF.PCF8574GpioProvider class with the bus address of the device. This overload assumes a Rev 2 or higher board and creates a default I2C connection instance.
public PCF8574GpioProvider ( Int32 address ) : System
address System.Int32 /// The bus address of the device. ///
return System

Poll() public method

Polls the state of the all the pins once every ~50ms.
/// This instance has been disposed and can no longer be used. ///
public Poll ( ) : void
return void

SetPinMode() public method

Sets the mode of the specified pin.
/// cannot be null. /// /// This instance has been disposed and can no longer be used. /// /// The specified pin does not exist in the pin cache. ///
public SetPinMode ( IPCF8574Pin pin, PinMode mode ) : void
pin IPCF8574Pin /// The pin to alter. ///
mode PinMode /// The mode to set. ///
return void

SetPinState() public method

Sets the state of the specified pin.
/// cannot be null. /// /// This instance has been disposed and can no longer be used. /// /// The specified pin does not exist in the pin cache. /// /// Failed to write the new state to the device. ///
public SetPinState ( IPCF8574Pin pin, PinState state ) : void
pin IPCF8574Pin /// The pin to alter. ///
state PinState /// The state of the pin to set. ///
return void

Property Details

PinPollFailed public_oe property

Occurs if device polling fails.
public PinPollFailEventHandler PinPollFailed
return PinPollFailEventHandler

PinStateChanged public_oe property

Occurs when a pin state changes.
public PinStateChangeEventHandler PinStateChanged
return PinStateChangeEventHandler