C# Класс 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.
Наследование: II2CBus
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
Dispose ( System.Boolean disposing ) : void

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

Описание методов

Close() публичный Метод

Closes the connection.
public Close ( ) : void
Результат void

Dispose() публичный Метод

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
Результат void

Dispose() защищенный Метод

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. ///
Результат void

I2CBus() публичный Метод

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. ///
Результат System

Open() публичный статический Метод

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. ///
Результат I2CBus

Open() публичный Метод

Open a connection to the I2C bus.
/// This instance has been disposed. /// /// Unable to open the bus connection. ///
public Open ( ) : void
Результат void

Read() публичный Метод

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. ///
Результат Byte

ReadBytes() публичный Метод

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. ///
Результат Byte[]

WriteByte() публичный Метод

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. ///
Результат void

WriteBytes() публичный Метод

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. ///
Результат void

WriteCommand() публичный Метод

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. ///
Результат void

WriteCommand() публичный Метод

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. ///
Результат void

WriteCommand() публичный Метод

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. ///
Результат void