Class I2cDevice
Represents a peripheral connected via the I2C/SM bus.
Implements
Inherited Members
Namespace: Unosquare.PiGpio.ManagedModel
Syntax
public sealed class I2cDevice : IDisposable
Properties
Address
Gets the devide address on the bus.
Declaration
public byte Address { get; }
Property Value
Type | Description |
---|---|
Byte |
BusId
Gets the bus identifier.
Declaration
public I2cBusId BusId { get; }
Property Value
Type | Description |
---|---|
I2cBusId |
Handle
Gets the device handle.
Declaration
public UIntPtr Handle { get; }
Property Value
Type | Description |
---|---|
UIntPtr |
UseCombinedTransactions
This sets the I2C (i2c-bcm2708) module "use combined transactions" parameter on or off.
NOTE: when the flag is on a write followed by a read to the same slave address will use a repeated start (rather than a stop/start).
Declaration
public static bool UseCombinedTransactions { set; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
ReadBlock(Byte)
This reads a block of up to 32 bytes from the specified register of the device associated with handle. The amount of returned data is set by the device.
Declaration
public byte[] ReadBlock(byte register)
Parameters
Type | Name | Description |
---|---|---|
Byte | register | The register. |
Returns
Type | Description |
---|---|
Byte[] | The data read from the device. |
ReadBlock(Byte, Int32)
This reads count bytes from the specified register of the device associated with handle . The count may be 1-32.
Declaration
public byte[] ReadBlock(byte register, int count)
Parameters
Type | Name | Description |
---|---|---|
Byte | register | The register. |
Int32 | count | The count. |
Returns
Type | Description |
---|---|
Byte[] | The data read from the device. |
ReadByte()
This reads a single byte from the device associated with handle.
Declaration
public byte ReadByte()
Returns
Type | Description |
---|---|
Byte | The value read. |
ReadByte(Byte)
This reads a single byte from the specified register of the device associated with handle.
Declaration
public byte ReadByte(byte register)
Parameters
Type | Name | Description |
---|---|---|
Byte | register | The register. |
Returns
Type | Description |
---|---|
Byte | The read value. |
ReadRaw(Int32)
This reads count bytes from the raw device into buf.
Declaration
public byte[] ReadRaw(int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | The count. |
Returns
Type | Description |
---|---|
Byte[] | The raw byte data. |
ReadWord(Byte)
This reads a single 16 bit word from the specified register of the device associated with handle.
Declaration
public ushort ReadWord(byte register)
Parameters
Type | Name | Description |
---|---|---|
Byte | register | The register. |
Returns
Type | Description |
---|---|
UInt16 | The word data. |
SetMode(I2cQuickMode)
This sends a single bit (in the Rd/Wr bit) to the device associated with handle.
Declaration
public void SetMode(I2cQuickMode mode)
Parameters
Type | Name | Description |
---|---|---|
I2cQuickMode | mode | The mode (write is 0, read is 1). |
Transfer(Byte, Byte[])
This writes data bytes to the specified register of the device associated with handle and reads a device specified number of bytes of data in return.
The SMBus 2.0 documentation states that a minimum of 1 byte may be sent and a minimum of 1 byte may be received. The total number of bytes sent/received must be 32 or less.
Declaration
public byte[] Transfer(byte register, byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
Byte | register | The register. |
Byte[] | buffer | The buffer. |
Returns
Type | Description |
---|---|
Byte[] | The bytes that were read. |
Write(Byte)
This sends a single byte to the device associated with handle.
Declaration
public void Write(byte value)
Parameters
Type | Name | Description |
---|---|---|
Byte | value | The value. |
Write(Byte, Byte)
This writes a single byte to the specified register of the device associated with handle.
Declaration
public void Write(byte register, byte value)
Parameters
Type | Name | Description |
---|---|---|
Byte | register | The register. |
Byte | value | The value. |
Write(Byte, Byte[])
This writes up to 32 bytes to the specified register of the device associated with handle.
Declaration
public void Write(byte register, byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
Byte | register | The register. |
Byte[] | buffer | The buffer. |
Write(Byte, Byte[], Int32)
This writes 1 to 32 bytes to the specified register of the device associated with handle.
Declaration
public void Write(byte register, byte[] buffer, int count)
Parameters
Type | Name | Description |
---|---|---|
Byte | register | The register. |
Byte[] | buffer | The buffer. |
Int32 | count | The count. |
Write(Byte, Int16)
This writes a single 16 bit word to the specified register of the device associated with handle.
Declaration
public void Write(byte register, short value)
Parameters
Type | Name | Description |
---|---|---|
Byte | register | The register. |
Int16 | value | The value. |
Write(Byte, UInt16)
This writes a single 16 bit word to the specified register of the device associated with handle.
Declaration
public void Write(byte register, ushort value)
Parameters
Type | Name | Description |
---|---|---|
Byte | register | The register. |
UInt16 | value | The value. |
Write(Byte[])
This writes a sequence of bytes without control bits between blocks. This operation sends the bytes in its raw form consecutively.
Declaration
public void Write(byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | buffer | The buffer. |