Class SpiDevice
The communications channel to a device on a SPI bus.
public class SpiDevice : IDisposable
- Inheritance
-
SpiDevice
- Implements
- Inherited Members
- Extension Methods
Constructors
SpiDevice(SpiConnectionSettings)
Creates a communications channel to a device on a SPI bus running on the current hardware.
public SpiDevice(SpiConnectionSettings settings)
Parameters
settings
SpiConnectionSettingsThe connection settings of a device on a SPI bus.
Exceptions
- ArgumentException
ChipSelectLine is not valid.
- or -
The specified BusId is not available.
- or -
One, or more of the GPIOs for the SPI bus are already used.
- or -
Some other invalid property in the specified SpiConnectionSettings.
- ArgumentOutOfRangeException
Maximum number of SPI devices for the specified bus has been reached.
- SpiDeviceAlreadyInUseException
If ChipSelectLine it's already in use.
Properties
ConnectionSettings
The connection settings of a device on a SPI bus. The connection settings are immutable after the device is created so the object returned will be a clone of the settings object.
public SpiConnectionSettings ConnectionSettings { get; }
Property Value
Methods
Create(SpiConnectionSettings)
Creates a communications channel to a device on a SPI bus running on the current hardware.
public static SpiDevice Create(SpiConnectionSettings settings)
Parameters
settings
SpiConnectionSettingsThe connection settings of a device on a SPI bus.
Returns
- SpiDevice
A communications channel to a device on a SPI bus.
Dispose()
Disposes this instance
public void Dispose()
Dispose(bool)
Disposes this instance
protected void Dispose(bool disposing)
Parameters
Finalize()
protected override void Finalize()
GetBusInfo(int)
Retrieves the info about a certain bus.
public static SpiBusInfo GetBusInfo(int busId)
Parameters
busId
intThe id of the bus.
Returns
- SpiBusInfo
The bus info requested.
Exceptions
- ArgumentOutOfRangeException
If the
busId
is not available in the device.
Read(SpanByte)
Reads data from the SPI device.
public void Read(SpanByte buffer)
Parameters
buffer
SpanByteThe buffer to read the data from the SPI device. The length of the buffer determines how much data to read from the SPI device.
Read(ushort[])
Reads data from the SPI device.
public void Read(ushort[] buffer)
Parameters
buffer
ushort[]The buffer to read the data from the SPI device. The length of the buffer determines how much data to read from the SPI device.
ReadByte()
Reads a byte from the SPI device.
public byte ReadByte()
Returns
- byte
A byte read from the SPI device.
TransferFullDuplex(SpanByte, SpanByte)
Writes and reads data from the SPI device.
public void TransferFullDuplex(SpanByte writeBuffer, SpanByte readBuffer)
Parameters
writeBuffer
SpanByteThe buffer that contains the data to be written to the SPI device.
readBuffer
SpanByteThe buffer to read the data from the SPI device.
Exceptions
- InvalidOperationException
If the ConnectionSettings for this SpiDevice aren't configured for FullDuplex.
TransferFullDuplex(ushort[], ushort[])
Writes and reads data from the SPI device.
public void TransferFullDuplex(ushort[] writeBuffer, ushort[] readBuffer)
Parameters
writeBuffer
ushort[]The buffer that contains the data to be written to the SPI device.
readBuffer
ushort[]The buffer to read the data from the SPI device.
Exceptions
- InvalidOperationException
If the ConnectionSettings for this SpiDevice aren't configured for FullDuplex.
Write(SpanByte)
Writes data to the SPI device.
public void Write(SpanByte buffer)
Parameters
buffer
SpanByteThe buffer that contains the data to be written to the SPI device.
Write(ushort[])
Writes data to the SPI device.
public void Write(ushort[] buffer)
Parameters
buffer
ushort[]The buffer that contains the data to be written to the SPI device.
WriteByte(byte)
Writes a byte to the SPI device.
public void WriteByte(byte value)
Parameters
value
byteThe byte to be written to the SPI device.