Table of Contents

Class I2cSlaveDevice

Namespace
System.Device.I2c
Assembly
System.Device.I2c.Slave.dll

Represents an I2C slave device.

public class I2cSlaveDevice : IDisposable
Inheritance
I2cSlaveDevice
Implements
Inherited Members
Extension Methods

Constructors

I2cSlaveDevice(int, int)

Create an I2C slave device with the specified address.

public I2cSlaveDevice(int busId, int deviceAddress)

Parameters

busId int

The I2C bus ID where the device will be made available.

deviceAddress int

The address of the I2C slave device.

Exceptions

ArgumentException

Thrown when busId is invalid.

-- or --

The specified busId is being used either has slave or master device.

Properties

BusId

The bus ID the I2C slave device is available.

public int BusId { get; }

Property Value

int

DeviceAddress

The address of the I2C slave device.

public int DeviceAddress { get; }

Property Value

int

The address of the I2C device.

Methods

Dispose()

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

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

Finalize()

protected override void Finalize()

Read(SpanByte, int)

Reads data from the I2C master.

public int Read(SpanByte buffer, int timeout = -1)

Parameters

buffer SpanByte

The buffer to read the data from the I2C master.

timeout int

The timeout in milliseconds to wait for the read to complete. Default is Infinite.

Returns

int

The number of bytes read from the I2C master.

Remarks

The length of buffer determines how much data to read from the I2C master.

The return value will be the same as the length of buffer if the read was successful.

No exception will be thrown if the read was not successful. The return value will indicate how many bytes were read.

ReadByte(out byte, int)

Reads a byte from the I2C master.

public bool ReadByte(out byte value, int timeout = -1)

Parameters

value byte

The byte read from the I2C master.

timeout int

The timeout in milliseconds to wait for the read to complete. Default is Infinite

Returns

bool

The byte read from the I2C master.

Write(SpanByte, int)

Writes data to the I2C master.

public int Write(SpanByte buffer, int timeout = -1)

Parameters

buffer SpanByte

The buffer to be written to the I2C master.

timeout int

The timeout in milliseconds to wait for the write to complete. Default is Infinite

Returns

int

The number of bytes written to the I2C master.

Remarks

The length of buffer determines how much data to write to the I2C master.

The return value will be the same as the length of buffer if the write was successful.

No exception will be thrown if the write was not successful. The return value will indicate how many bytes were written.

WriteByte(byte, int)

Writes a byte to the I2C master.

public bool WriteByte(byte value, int timeout = -1)

Parameters

value byte

The byte to be written to the I2C master.

timeout int

The timeout in milliseconds to wait for the write to complete. Default is Infinite

Returns

bool

true if the byte was written successfully; otherwise, false.