C# Class CyrusBuilt.MonoPi.IO.I2C.I2CBus

An I2C bus implementation for the Raspberry Pi. Derived from the RPi.I2C.Net library by mshmelev at https://github.com/mshmelev/RPi.I2C.Net. As such, this class (and the required methods in UnsafeNativeMethods) is dependent on the underlying LibNativeI2C native library which must be compiled and included with this library.
Inheritance: II2CBus
显示文件 Open project: cyrusbuilt/MonoPi Class Usage Examples

Public Methods

Method Description
Close ( ) : void

Closes the connection.

Dispose ( ) : void

Releases all resource used by the CyrusBuilt.MonoPi.IO.I2C.I2CBus object.

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

I2CBus ( BoardRevision boardRev ) : System

Initializes a new instance of the CyrusBuilt.MonoPi.IO.I2C.I2CBus class with the path the I2C bus.

Open ( BoardRevision boardRev ) : I2CBus

Gets an open I2C connection instance.

Open ( ) : void

Open a connection to the I2C bus.

Read ( Int32 address ) : Byte

Reads a single byte from the device at the specified address.

ReadBytes ( Int32 address, Int32 count ) : Byte[]

Reads bytes from the device at the specified address.

WriteByte ( Int32 address, Byte b ) : void

Writes a single byte to the specified device address.

WriteBytes ( Int32 address, Byte bytes ) : void

Writes an array of bytes to the specified device address.

Currently, RPi drivers do not allow writing more than 3 bytes at a time. As such, if an array of greater than 3 bytes is provided, an exception is thrown.

WriteCommand ( Int32 address, Byte command, Byte data ) : void

Writes a command with data to the specified device address.

WriteCommand ( Int32 address, Byte command, Byte data1, Byte data2 ) : void

Writes a command with data to the specified device address.

WriteCommand ( Int32 address, Byte command, ushort data ) : void

Writes a command with data to the specified device address.

Protected Methods

Method Description
Dispose ( System.Boolean disposing ) : void

Releases all resource used by the CyrusBuilt.MonoPi.IO.I2C.I2CBus object.

Method Details

Close() public method

Closes the connection.
public Close ( ) : void
return void

Dispose() public method

Releases all resource used by the CyrusBuilt.MonoPi.IO.I2C.I2CBus object.
Call Dispose when you are finished using the CyrusBuilt.MonoPi.IO.I2C.I2CBus. The Dispose method leaves the CyrusBuilt.MonoPi.IO.I2C.I2CBus in an unusable state. After calling Dispose, you must release all references to the CyrusBuilt.MonoPi.IO.I2C.I2CBus so the garbage collector can reclaim the memory that the CyrusBuilt.MonoPi.IO.I2C.I2CBus was occupying.
public Dispose ( ) : void
return void

Dispose() protected method

Releases all resource used by the CyrusBuilt.MonoPi.IO.I2C.I2CBus object.
protected Dispose ( System.Boolean disposing ) : void
disposing System.Boolean /// Set true if disposing managed resources as well as unmanaged. ///
return void

I2CBus() public method

Initializes a new instance of the CyrusBuilt.MonoPi.IO.I2C.I2CBus class with the path the I2C bus.
public I2CBus ( BoardRevision boardRev ) : System
boardRev BoardRevision /// Specifies the revision of the RPi board in use. This /// used to determine the path to the system file associated /// with the i2c bus. ///
return System

Open() public static method

Gets an open I2C connection instance.
/// This instance has been disposed. /// /// Unable to open the bus connection. ///
public static Open ( BoardRevision boardRev ) : I2CBus
boardRev BoardRevision /// Specifies the revision of the RPi board in use. This /// used to determine the path to the system file associated /// with the i2c bus. ///
return I2CBus

Open() public method

Open a connection to the I2C bus.
/// This instance has been disposed. /// /// Unable to open the bus connection. ///
public Open ( ) : void
return void

Read() public method

Reads a single byte from the device at the specified address.
/// This instance has been disposed and can no longer be used. /// /// You must open a conection to the I2C bus by calling /// first. /// /// An I/O error occurred. The specified address is inacessible or the /// I2C transaction failed. ///
public Read ( Int32 address ) : Byte
address System.Int32 /// The address of the device to read from. ///
return Byte

ReadBytes() public method

Reads bytes from the device at the specified address.
/// This instance has been disposed and can no longer be used. /// /// You must open a conection to the I2C bus by calling /// first. /// /// An I/O error occurred. The specified address is inacessible or the /// I2C transaction failed. ///
public ReadBytes ( Int32 address, Int32 count ) : Byte[]
address System.Int32 /// The address of the device to read from. ///
count System.Int32 /// The number of bytes to read. ///
return Byte[]

WriteByte() public method

Writes a single byte to the specified device address.
/// This instance has been disposed and can no longer be used. /// /// You must open a conection to the I2C bus by calling /// first. /// /// An I/O error occurred. The specified address is inacessible or the /// I2C transaction failed. ///
public WriteByte ( Int32 address, Byte b ) : void
address System.Int32 /// The address of the target device. ///
b Byte /// The byte to write. ///
return void

WriteBytes() public method

Writes an array of bytes to the specified device address.
Currently, RPi drivers do not allow writing more than 3 bytes at a time. As such, if an array of greater than 3 bytes is provided, an exception is thrown.
/// This instance has been disposed and can no longer be used. /// /// You must open a conection to the I2C bus by calling /// first. /// /// cannot be greater than 3 elements in length. /// /// An I/O error occurred. The specified address is inacessible or the /// I2C transaction failed. ///
public WriteBytes ( Int32 address, Byte bytes ) : void
address System.Int32 /// The address of the target device. ///
bytes Byte /// The byte array to write. ///
return void

WriteCommand() public method

Writes a command with data to the specified device address.
/// This instance has been disposed and can no longer be used. /// /// You must open a conection to the I2C bus by calling /// first. /// /// An I/O error occurred. The specified address is inacessible or the /// I2C transaction failed. ///
public WriteCommand ( Int32 address, Byte command, Byte data ) : void
address System.Int32 /// The address of the target device. ///
command Byte /// The command to send to the device. ///
data Byte /// The data to send with the command. ///
return void

WriteCommand() public method

Writes a command with data to the specified device address.
/// This instance has been disposed and can no longer be used. /// /// You must open a conection to the I2C bus by calling /// first. /// /// An I/O error occurred. The specified address is inacessible or the /// I2C transaction failed. ///
public WriteCommand ( Int32 address, Byte command, Byte data1, Byte data2 ) : void
address System.Int32 /// The address of the target device. ///
command Byte /// The command to send to the device. ///
data1 Byte /// The data to send as the first parameter. ///
data2 Byte /// The data to send as the second parameter. ///
return void

WriteCommand() public method

Writes a command with data to the specified device address.
/// This instance has been disposed and can no longer be used. /// /// You must open a conection to the I2C bus by calling /// first. /// /// An I/O error occurred. The specified address is inacessible or the /// I2C transaction failed. ///
public WriteCommand ( Int32 address, Byte command, ushort data ) : void
address System.Int32 /// The address of the target device. ///
command Byte /// The command to send to the device. ///
data ushort /// The data to send with the command. ///
return void