Class I2cSlaveDevice
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
intThe I2C bus ID where the device will be made available.
deviceAddress
intThe 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
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
SpanByteThe buffer to read the data from the I2C master.
timeout
intThe 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
byteThe byte read from the I2C master.
timeout
intThe 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
SpanByteThe buffer to be written to the I2C master.
timeout
intThe 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
byteThe byte to be written to the I2C master.
timeout
intThe timeout in milliseconds to wait for the write to complete. Default is Infinite