Package com.pi4j.io.i2c.impl
Class I2CDeviceImpl
- java.lang.Object
- 
- com.pi4j.io.i2c.impl.I2CDeviceImpl
 
- 
- All Implemented Interfaces:
- I2CDevice
 
 public class I2CDeviceImpl extends Object implements I2CDevice Implementation of i2c device. This class only holds reference to i2c bus (so it can use its handle) and device address.- Author:
- Daniel Sendula, refactored by RasPelikan
 
- 
- 
Constructor SummaryConstructors Constructor Description I2CDeviceImpl(I2CBusImpl bus, int address)Constructor.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetAddress()voidioctl(long command, int value)Runs an ioctl on this device.voidioctl(long command, ByteBuffer data, IntBuffer offsets)Runs an ioctl on this device.protected StringmakeDescription()This helper method creates a string describing bus file name and device address (in hex).protected StringmakeDescription(int address)This helper method creates a string describing bus file name, device address (in hex) and local i2c address.intread()This method reads one byte from the i2c device.intread(byte[] data, int offset, int size)This method reads bytes from the i2c device to given buffer at asked offset.intread(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 callintread(int address)This method reads one byte from the i2c device.intread(int address, byte[] data, int offset, int size)This method reads bytes from the i2c device to given buffer at asked offset.voidwrite(byte data)This method writes one byte to i2c device.voidwrite(byte[] buffer)This method writes all bytes included in the given buffer directly to the i2c device.voidwrite(byte[] data, int offset, int size)This method writes several bytes to the i2c device from given buffer at given offset.voidwrite(int address, byte data)This method writes one byte to i2c device.voidwrite(int address, byte[] buffer)This method writes all bytes included in the given buffer directory to the register address on the i2c devicevoidwrite(int address, byte[] data, int offset, int size)This method writes several bytes to the i2c device from given buffer at given offset.
 
- 
- 
- 
Constructor Detail- 
I2CDeviceImplpublic I2CDeviceImpl(I2CBusImpl bus, int address) Constructor.- Parameters:
- bus- i2c bus
- address- i2c device address
 
 
- 
 - 
Method Detail- 
getAddresspublic int getAddress() - Specified by:
- getAddressin interface- I2CDevice
- Returns:
- The address for which this instance is constructed for.
 
 - 
writepublic void write(byte data) throws IOExceptionThis method writes one byte to i2c device.- Specified by:
- writein interface- I2CDevice
- Parameters:
- data- byte to be written
- Throws:
- IOException- thrown in case byte cannot be written to the i2c device or i2c bus
 
 - 
writepublic void write(byte[] data, int offset, int size) throws IOExceptionThis method writes several bytes to the i2c device from given buffer at given offset.- Specified by:
- writein interface- I2CDevice
- Parameters:
- data- buffer of data to be written to the i2c device in one go
- offset- offset in buffer
- size- number of bytes to be written
- Throws:
- IOException- thrown in case byte cannot be written to the i2c device or i2c bus
 
 - 
writepublic void write(byte[] buffer) throws IOExceptionThis method writes all bytes included in the given buffer directly to the i2c device.- Specified by:
- writein interface- I2CDevice
- Parameters:
- buffer- buffer of data to be written to the i2c device in one go
- Throws:
- IOException- thrown in case byte cannot be written to the i2c device or i2c bus
 
 - 
writepublic void write(int address, byte data) throws IOExceptionThis method writes one byte to i2c device.- Specified by:
- writein interface- I2CDevice
- Parameters:
- address- local address in the i2c device
- data- byte to be written
- Throws:
- IOException- thrown in case byte cannot be written to the i2c device or i2c bus
 
 - 
writepublic void write(int address, byte[] data, int offset, int size) throws IOExceptionThis method writes several bytes to the i2c device from given buffer at given offset.- Specified by:
- writein interface- I2CDevice
- Parameters:
- address- local address in the i2c device
- data- buffer of data to be written to the i2c device in one go
- offset- offset in buffer
- size- number of bytes to be written
- Throws:
- IOException- thrown in case byte cannot be written to the i2c device or i2c bus
 
 - 
writepublic void write(int address, byte[] buffer) throws IOExceptionThis method writes all bytes included in the given buffer directory to the register address on the i2c device- Specified by:
- writein interface- I2CDevice
- Parameters:
- address- local address in the i2c device
- buffer- buffer of data to be written to the i2c device in one go
- Throws:
- IOException- thrown in case byte cannot be written to the i2c device or i2c bus
 
 - 
readpublic int read() throws IOExceptionThis method reads one byte from the i2c device. Result is between 0 and 255 if read operation was successful, else a negative number for an error.- Specified by:
- readin interface- I2CDevice
- Returns:
- byte value read: positive number (or zero) to 255 if read was successful. Negative number if reading failed.
- Throws:
- IOException- thrown in case byte cannot be read from the i2c device or i2c bus
 
 - 
readpublic int read(byte[] data, int offset, int size) throws IOExceptionThis 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.- Specified by:
- readin interface- I2CDevice
- Parameters:
- data- buffer of data to be read from the i2c device in one go
- offset- offset in buffer
- size- number of bytes to be read
- Returns:
- number of bytes read
- Throws:
- IOException- thrown in case byte cannot be read from the i2c device or i2c bus
 
 - 
readpublic int read(int address) throws IOExceptionThis method reads one byte from the i2c device. Result is between 0 and 255 if read operation was successful, else a negative number for an error.- Specified by:
- readin interface- I2CDevice
- Parameters:
- address- local address in the i2c device
- Returns:
- byte value read: positive number (or zero) to 255 if read was successful. Negative number if reading failed.
- Throws:
- IOException- thrown in case byte cannot be read from the i2c device or i2c bus
 
 - 
readpublic int read(int address, byte[] data, int offset, int size) throws IOExceptionThis 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.- Specified by:
- readin interface- I2CDevice
- Parameters:
- address- local address in the i2c device
- data- buffer of data to be read from the i2c device in one go
- offset- offset in buffer
- size- number of bytes to be read
- Returns:
- number of bytes read
- Throws:
- IOException- thrown in case byte cannot be read from the i2c device or i2c bus
 
 - 
ioctlpublic void ioctl(long command, int value) throws IOExceptionDescription copied from interface:I2CDeviceRuns an ioctl on this device.- Specified by:
- ioctlin interface- I2CDevice
- Throws:
- IOException
- See Also:
- LinuxFile.ioctl(long, int)
 
 - 
ioctlpublic void ioctl(long command, ByteBuffer data, IntBuffer offsets) throws IOExceptionDescription copied from interface:I2CDeviceRuns an ioctl on this device.- Specified by:
- ioctlin interface- I2CDevice
- Throws:
- IOException
- See Also:
- LinuxFile.ioctl(long, ByteBuffer, IntBuffer)
 
 - 
readpublic int read(byte[] writeData, int writeOffset, int writeSize, byte[] readData, int readOffset, int readSize) throws IOExceptionThis method writes and reads bytes to/from the i2c device in a single method call- Specified by:
- readin interface- I2CDevice
- Parameters:
- writeData- buffer of data to be written to the i2c device in one go
- writeOffset- offset in write buffer
- writeSize- number of bytes to be written from buffer
- readData- buffer of data to be read from the i2c device in one go
- readOffset- offset in read buffer
- readSize- number of bytes to be read
- Returns:
- number of bytes read
- Throws:
- IOException- thrown in case byte cannot be read from the i2c device or i2c bus
 
 - 
makeDescriptionprotected String makeDescription() This helper method creates a string describing bus file name and device address (in hex).- Returns:
- string with all details
 
 - 
makeDescriptionprotected String makeDescription(int address) This helper method creates a string describing bus file name, device address (in hex) and local i2c address.- Parameters:
- address- local address in i2c device
- Returns:
- string with all details
 
 
- 
 
-