public class I2CDeviceImpl extends Object implements I2CDevice
Constructor and Description |
---|
I2CDeviceImpl(I2CBusImpl bus,
int address)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
getAddress() |
void |
ioctl(long command,
ByteBuffer data,
IntBuffer offsets)
Runs an ioctl on this device.
|
void |
ioctl(long command,
int value)
Runs an ioctl on this device.
|
protected String |
makeDescription()
This helper method creates a string describing bus file name and device address (in hex).
|
protected String |
makeDescription(int address)
This helper method creates a string describing bus file name, device address (in hex) and local i2c address.
|
int |
read()
This method reads one byte from the i2c device.
|
int |
read(byte[] data,
int offset,
int size)
This method reads bytes from the i2c device to given buffer at asked offset.
|
int |
read(byte[] writeData,
int writeOffset,
int writeSize,
byte[] readData,
int readOffset,
int readSize)
This method writes and reads bytes to/from the i2c device in a single method call
|
int |
read(int address)
This method reads one byte from the i2c device.
|
int |
read(int address,
byte[] data,
int offset,
int size)
This method reads bytes from the i2c device to given buffer at asked offset.
|
void |
write(byte data)
This method writes one byte to i2c device.
|
void |
write(byte[] buffer)
This method writes all bytes included in the given buffer directly to the i2c device.
|
void |
write(byte[] data,
int offset,
int size)
This method writes several bytes to the i2c device from given buffer at given offset.
|
void |
write(int address,
byte data)
This method writes one byte to i2c device.
|
void |
write(int address,
byte[] buffer)
This method writes all bytes included in the given buffer directoy to the register address on the i2c device
|
void |
write(int address,
byte[] data,
int offset,
int size)
This method writes several bytes to the i2c device from given buffer at given offset.
|
public I2CDeviceImpl(I2CBusImpl bus, int address)
bus
- i2c busaddress
- i2c device addresspublic int getAddress()
getAddress
in interface I2CDevice
public void write(byte data) throws IOException
write
in interface I2CDevice
data
- byte to be writtenIOException
- thrown in case byte cannot be written to the i2c device or i2c buspublic void write(byte[] data, int offset, int size) throws IOException
write
in interface I2CDevice
data
- buffer of data to be written to the i2c device in one gooffset
- offset in buffersize
- number of bytes to be writtenIOException
- thrown in case byte cannot be written to the i2c device or i2c buspublic void write(byte[] buffer) throws IOException
write
in interface I2CDevice
buffer
- buffer of data to be written to the i2c device in one goIOException
- thrown in case byte cannot be written to the i2c device or i2c buspublic void write(int address, byte data) throws IOException
write
in interface I2CDevice
address
- local address in the i2c devicedata
- byte to be writtenIOException
- thrown in case byte cannot be written to the i2c device or i2c buspublic void write(int address, byte[] data, int offset, int size) throws IOException
write
in interface I2CDevice
address
- local address in the i2c devicedata
- buffer of data to be written to the i2c device in one gooffset
- offset in buffersize
- number of bytes to be writtenIOException
- thrown in case byte cannot be written to the i2c device or i2c buspublic void write(int address, byte[] buffer) throws IOException
write
in interface I2CDevice
address
- local address in the i2c devicebuffer
- buffer of data to be written to the i2c device in one goIOException
- thrown in case byte cannot be written to the i2c device or i2c buspublic int read() throws IOException
read
in interface I2CDevice
IOException
- thrown in case byte cannot be read from the i2c device or i2c buspublic int read(byte[] data, int offset, int size) throws IOException
This method reads bytes from the i2c device to given buffer at asked offset.
Note: Current implementation calls read(int)
. That means for each read byte i2c bus will send (next) address to i2c device.
read
in interface I2CDevice
data
- buffer of data to be read from the i2c device in one gooffset
- offset in buffersize
- number of bytes to be readIOException
- thrown in case byte cannot be read from the i2c device or i2c buspublic int read(int address) throws IOException
read
in interface I2CDevice
address
- local address in the i2c deviceIOException
- thrown in case byte cannot be read from the i2c device or i2c buspublic int read(int address, byte[] data, int offset, int size) throws IOException
This method reads bytes from the i2c device to given buffer at asked offset.
Note: Current implementation calls read(int)
. That means for each read byte i2c bus will send (next) address to i2c device.
read
in interface I2CDevice
address
- local address in the i2c devicedata
- buffer of data to be read from the i2c device in one gooffset
- offset in buffersize
- number of bytes to be readIOException
- thrown in case byte cannot be read from the i2c device or i2c buspublic void ioctl(long command, int value) throws IOException
I2CDevice
ioctl
in interface I2CDevice
IOException
LinuxFile.ioctl(long, int)
public void ioctl(long command, ByteBuffer data, IntBuffer offsets) throws IOException
I2CDevice
ioctl
in interface I2CDevice
IOException
LinuxFile.ioctl(long, ByteBuffer, IntBuffer)
public int read(byte[] writeData, int writeOffset, int writeSize, byte[] readData, int readOffset, int readSize) throws IOException
read
in interface I2CDevice
writeData
- buffer of data to be written to the i2c device in one gowriteOffset
- offset in write bufferwriteSize
- number of bytes to be written from bufferreadData
- buffer of data to be read from the i2c device in one goreadOffset
- offset in read bufferreadSize
- number of bytes to be readIOException
- thrown in case byte cannot be read from the i2c device or i2c busprotected String makeDescription()
protected String makeDescription(int address)
address
- local address in i2c deviceCopyright © 2012–2021 Pi4J. All rights reserved.