Class SpiDevice
The communications channel to a device on a SPI bus.
Implements
Inherited Members
Namespace: System.Device.Spi
Assembly: System.Device.Spi.dll
Syntax
public class SpiDevice : IDisposable
Constructors
| Improve this Doc View SourceSpiDevice(SpiConnectionSettings)
Creates a communications channel to a device on a SPI bus running on the current hardware.
Declaration
public SpiDevice(SpiConnectionSettings settings)
Parameters
Type | Name | Description |
---|---|---|
SpiConnectionSettings | settings | The connection settings of a device on a SPI bus. |
Exceptions
Type | Condition |
---|---|
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
| Improve this Doc View SourceConnectionSettings
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.
Declaration
public SpiConnectionSettings ConnectionSettings { get; }
Property Value
Type | Description |
---|---|
SpiConnectionSettings |
Methods
| Improve this Doc View SourceCreate(SpiConnectionSettings)
Creates a communications channel to a device on a SPI bus running on the current hardware.
Declaration
public static SpiDevice Create(SpiConnectionSettings settings)
Parameters
Type | Name | Description |
---|---|---|
SpiConnectionSettings | settings | The connection settings of a device on a SPI bus. |
Returns
Type | Description |
---|---|
SpiDevice | A communications channel to a device on a SPI bus. |
Dispose()
Disposes this instance
Declaration
public void Dispose()
Dispose(Boolean)
Disposes this instance
Declaration
protected void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | disposing | true if explicitly disposing, false if in finalizer |
Finalize()
Declaration
protected void Finalize()
GetBusInfo(Int32)
Retrieves the info about a certain bus.
Declaration
public static SpiBusInfo GetBusInfo(int busId)
Parameters
Type | Name | Description |
---|---|---|
Int32 | busId | The id of the bus. |
Returns
Type | Description |
---|---|
SpiBusInfo | The bus info requested. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | If the |
Read(SpanByte)
Reads data from the SPI device.
Declaration
public void Read(SpanByte buffer)
Parameters
Type | Name | Description |
---|---|---|
SpanByte | buffer | 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. |
Read(UInt16[])
Reads data from the SPI device.
Declaration
public void Read(ushort[] buffer)
Parameters
Type | Name | Description |
---|---|---|
UInt16[] | buffer | 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.
Declaration
public byte ReadByte()
Returns
Type | Description |
---|---|
Byte | A byte read from the SPI device. |
TransferFullDuplex(SpanByte, SpanByte)
Writes and reads data from the SPI device.
Declaration
public void TransferFullDuplex(SpanByte writeBuffer, SpanByte readBuffer)
Parameters
Type | Name | Description |
---|---|---|
SpanByte | writeBuffer | The buffer that contains the data to be written to the SPI device. |
SpanByte | readBuffer | The buffer to read the data from the SPI device. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | If the ConnectionSettings for this SpiDevice aren't configured for FullDuplex. |
TransferFullDuplex(UInt16[], UInt16[])
Writes and reads data from the SPI device.
Declaration
public void TransferFullDuplex(ushort[] writeBuffer, ushort[] readBuffer)
Parameters
Type | Name | Description |
---|---|---|
UInt16[] | writeBuffer | The buffer that contains the data to be written to the SPI device. |
UInt16[] | readBuffer | The buffer to read the data from the SPI device. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | If the ConnectionSettings for this SpiDevice aren't configured for FullDuplex. |
Write(SpanByte)
Writes data to the SPI device.
Declaration
public void Write(SpanByte buffer)
Parameters
Type | Name | Description |
---|---|---|
SpanByte | buffer | The buffer that contains the data to be written to the SPI device. |
Write(UInt16[])
Writes data to the SPI device.
Declaration
public void Write(ushort[] buffer)
Parameters
Type | Name | Description |
---|---|---|
UInt16[] | buffer | The buffer that contains the data to be written to the SPI device. |
WriteByte(Byte)
Writes a byte to the SPI device.
Declaration
public void WriteByte(byte value)
Parameters
Type | Name | Description |
---|---|---|
Byte | value | The byte to be written to the SPI device. |