Package com.pi4j.io.spi.impl
Class SpiDeviceImpl
- java.lang.Object
-
- com.pi4j.io.spi.impl.SpiDeviceImpl
-
-
Field Summary
Fields Modifier and Type Field Description protected SpiChannel
channel
protected SpiMode
mode
-
Fields inherited from interface com.pi4j.io.spi.SpiDevice
DEFAULT_SPI_MODE, DEFAULT_SPI_SPEED, MAX_SUPPORTED_BYTES
-
-
Constructor Summary
Constructors Constructor Description SpiDeviceImpl(SpiChannel channel)
Creates the SPI Device at the given SPI and input channel (A default speed of 1 MHz will be used)SpiDeviceImpl(SpiChannel channel, int speed)
Creates the SPI Device at the given spi and input channelSpiDeviceImpl(SpiChannel channel, int speed, SpiMode mode)
Creates the SPI Device at the given spi and input channelSpiDeviceImpl(SpiChannel channel, SpiMode mode)
Creates the SPI Device at the given SPI and input channel (A default speed of 1 MHz will be used)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
write(byte... data)
Attempts to read/write data through this SPI devicebyte[]
write(byte[] data, int start, int length)
Attempts to read/write data through this SPI deviceshort[]
write(short... data)
Attempts to read/write data through this SPI deviceshort[]
write(short[] data, int start, int length)
Attempts to read/write data through this SPI devicebyte[]
write(InputStream input)
Attempts to read/write data through this SPI deviceint
write(InputStream input, OutputStream output)
Attempts to read/write data through this SPI deviceString
write(String data, String charset)
Attempts to read/write data through this SPI deviceString
write(String data, Charset charset)
Attempts to read/write data through this SPI deviceByteBuffer
write(ByteBuffer data)
Attempts to read/write data through this SPI device
-
-
-
Field Detail
-
channel
protected final SpiChannel channel
-
mode
protected final SpiMode mode
-
-
Constructor Detail
-
SpiDeviceImpl
public SpiDeviceImpl(SpiChannel channel, int speed, SpiMode mode) throws IOException
Creates the SPI Device at the given spi and input channel- Parameters:
channel
- spi channel to usespeed
- spi speed/rate (in Hertz) for channel to communicate at (range is 500kHz - 32MHz)mode
- spi mode (see http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus#Mode_numbers)- Throws:
IOException
-
SpiDeviceImpl
public SpiDeviceImpl(SpiChannel channel, int speed) throws IOException
Creates the SPI Device at the given spi and input channel- Parameters:
channel
- spi channel to usespeed
- spi speed/rate (in Hertz) for channel to communicate at (range is 500kHz - 32MHz)- Throws:
IOException
-
SpiDeviceImpl
public SpiDeviceImpl(SpiChannel channel, SpiMode mode) throws IOException
Creates the SPI Device at the given SPI and input channel (A default speed of 1 MHz will be used)- Parameters:
channel
- spi channel to usemode
- spi mode (see http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus#Mode_numbers)- Throws:
IOException
-
SpiDeviceImpl
public SpiDeviceImpl(SpiChannel channel) throws IOException
Creates the SPI Device at the given SPI and input channel (A default speed of 1 MHz will be used)- Parameters:
channel
- spi channel to use- Throws:
IOException
-
-
Method Detail
-
write
public String write(String data, String charset) throws IOException
Description copied from interface:SpiDevice
Attempts to read/write data through this SPI device- Specified by:
write
in interfaceSpiDevice
- Parameters:
data
- bytes (encoded in string) to write to the SPI devicecharset
- character encoding for bytes in string- Returns:
- resulting bytes read from the SPI device after the write operation
- Throws:
IOException
-
write
public String write(String data, Charset charset) throws IOException
Description copied from interface:SpiDevice
Attempts to read/write data through this SPI device- Specified by:
write
in interfaceSpiDevice
- Parameters:
data
- bytes (encoded in string) to write to the SPI devicecharset
- character encoding for bytes in string- Returns:
- resulting bytes read from the SPI device after the write operation
- Throws:
IOException
-
write
public ByteBuffer write(ByteBuffer data) throws IOException
Description copied from interface:SpiDevice
Attempts to read/write data through this SPI device- Specified by:
write
in interfaceSpiDevice
- Parameters:
data
- bytes to write to the SPI device- Returns:
- resulting bytes read from the SPI device after the write operation
- Throws:
IOException
-
write
public byte[] write(InputStream input) throws IOException
Description copied from interface:SpiDevice
Attempts to read/write data through this SPI device- Specified by:
write
in interfaceSpiDevice
- Parameters:
input
- input stream to read from to get bytes to write to the SPI device- Returns:
- resulting bytes read from the SPI device after the write operation
- Throws:
IOException
-
write
public int write(InputStream input, OutputStream output) throws IOException
Description copied from interface:SpiDevice
Attempts to read/write data through this SPI device- Specified by:
write
in interfaceSpiDevice
- Parameters:
input
- input stream to read from to get bytes to write to the SPI deviceoutput
- output stream to write bytes read from the SPI device- Returns:
- number of resulting bytes read from the SPI device and written to the output stream
- Throws:
IOException
-
write
public byte[] write(byte... data) throws IOException
Description copied from interface:SpiDevice
Attempts to read/write data through this SPI device- Specified by:
write
in interfaceSpiDevice
- Parameters:
data
- bytes to write to the SPI device- Returns:
- resulting bytes read from the SPI device after the write operation
- Throws:
IOException
-
write
public short[] write(short... data) throws IOException
Description copied from interface:SpiDevice
Attempts to read/write data through this SPI device- Specified by:
write
in interfaceSpiDevice
- Parameters:
data
- bytes to write to the SPI device (Note: short value should not exceed 255.)- Returns:
- resulting bytes read from the SPI device after the write operation
- Throws:
IOException
-
write
public byte[] write(byte[] data, int start, int length) throws IOException
Description copied from interface:SpiDevice
Attempts to read/write data through this SPI device- Specified by:
write
in interfaceSpiDevice
- Parameters:
data
- bytes to write to the SPI devicestart
- start index position in the data buffer to start writing fromlength
- length of bytes to write from the data buffer- Returns:
- resulting bytes read from the SPI device after the write operation
- Throws:
IOException
-
write
public short[] write(short[] data, int start, int length) throws IOException
Description copied from interface:SpiDevice
Attempts to read/write data through this SPI device- Specified by:
write
in interfaceSpiDevice
- Parameters:
data
- bytes to write to the SPI devicestart
- start index position in the data buffer to start writing fromlength
- length of bytes to write from the data buffer- Returns:
- resulting bytes read from the SPI device after the write operation
- Throws:
IOException
-
-