public class I2CDevice extends Object implements Closeable, I2CConstants
ADDR_SIZE_10, ADDR_SIZE_7, BUS_0, BUS_1, DEFAULT_CLOCK_FREQUENCY, SUB_ADDRESS_SIZE_1_BYTE, SUB_ADDRESS_SIZE_2_BYTES, UNASSIGNED
Constructor and Description |
---|
I2CDevice(I2CDeviceFactoryInterface deviceFactory,
int controller,
int address,
int addressSize,
int clockFrequency,
ByteOrder order) |
I2CDevice(int controller,
int address) |
I2CDevice(int controller,
int address,
ByteOrder order) |
I2CDevice(int controller,
int address,
int addressSize,
int clockFrequency) |
I2CDevice(int controller,
int address,
int addressSize,
int clockFrequency,
ByteOrder order) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
int |
getAddress() |
int |
getAddressSize() |
int |
getClockFrequency() |
int |
getController() |
boolean |
isOpen() |
void |
read(ByteBuffer dst) |
byte[] |
read(int count) |
void |
read(int address,
ByteBuffer dst) |
ByteBuffer |
read(int address,
int count) |
void |
read(int address,
int subAddressSize,
ByteBuffer buffer) |
byte[] |
read(int address,
int subAddressSize,
int count) |
boolean |
readBit(int regAddr,
int bitNum)
Read a single bit from an 8-bit device register.
|
byte |
readBits(int regAddr,
int bitStart,
int length)
Read multiple bits from an 8-bit device register.
|
byte |
readByte() |
byte |
readByte(int regAddr)
Read single byte from an 8-bit device register.
|
byte |
readByte(int register,
int subAddressSize) |
byte[] |
readBytes(int regAddr,
int length)
Read multiple bytes from an 8-bit device register.
|
short |
readShort(int address) |
short |
readShort(int address,
int subAddressSize) |
short |
readShort(int address,
int subAddressSize,
ByteOrder order) |
short |
readUByte(int regAddr) |
long |
readUInt(int address) |
long |
readUInt(int address,
ByteOrder order) |
long |
readUInt(int address,
int subAddressSize,
int length) |
long |
readUInt(int address,
int subAddressSize,
int length,
ByteOrder order) |
int |
readUShort(int address) |
int |
readUShort(int address,
int subAddressSize) |
int |
readUShort(int address,
int subAddressSize,
ByteOrder order) |
void |
write(byte[] data) |
void |
write(byte[] data,
ByteOrder order) |
void |
write(ByteBuffer buffer,
int payloadLength) |
void |
write(ByteBuffer buffer,
int payloadLength,
ByteOrder order) |
void |
write(int registerAddress,
ByteBuffer buffer,
int payloadLength) |
void |
write(int register,
int subAddressSize,
byte value)
Writes a single byte to a register
|
void |
write(int register,
int subAddressSize,
byte[] value)
Writes a single byte to a register
|
void |
write(int registerAddress,
int addressSize,
ByteBuffer buffer,
int payloadLength,
ByteOrder order) |
void |
writeBit(int regAddr,
int bitNum,
boolean value)
write a single bit in an 8-bit device register.
|
void |
writeBit(int regAddr,
int bitNum,
int value)
write a single bit in an 8-bit device register.
|
void |
writeBits(int regAddr,
int bitStart,
int length,
int data)
Write multiple bits in an 8-bit device register.
|
void |
writeByte(byte data) |
void |
writeByte(int regAddr,
byte data)
Write single byte to an 8-bit device register.
|
void |
writeByte(int regAddr,
int data)
Write single byte to an 8-bit device register.
|
void |
writeBytes(int regAddr,
int length,
byte[] data)
Write multiple bytes to an 8-bit device register.
|
void |
writeBytes(int regAddr,
int length,
byte[] data,
int offset) |
void |
writeShort(int regAddr,
short val) |
void |
writeWord(int regAddr,
int data)
Write single word to a 16-bit device register.
|
public I2CDevice(int controller, int address) throws RuntimeIOException
controller
- I2C bus.address
- I2C device address.RuntimeIOException
- If an I/O error occurred.public I2CDevice(int controller, int address, ByteOrder order) throws RuntimeIOException
controller
- I2C bus.address
- I2C device address.order
- Default byte order for this deviceRuntimeIOException
- If an I/O error occurred.public I2CDevice(int controller, int address, int addressSize, int clockFrequency) throws RuntimeIOException
controller
- I2C bus.address
- I2C device address.addressSize
- I2C device address size. Can be 7 or 10.clockFrequency
- I2C clock frequency.RuntimeIOException
- If an I/O error occurred.public I2CDevice(int controller, int address, int addressSize, int clockFrequency, ByteOrder order) throws RuntimeIOException
controller
- I2C bus.address
- I2C device address.addressSize
- I2C device address size. Can be 7 or 10.clockFrequency
- I2C clock frequency.order
- Default byte order for this deviceRuntimeIOException
- If an I/O error occurred.public I2CDevice(I2CDeviceFactoryInterface deviceFactory, int controller, int address, int addressSize, int clockFrequency, ByteOrder order) throws RuntimeIOException
deviceFactory
- Device factory to use to provision this device.controller
- I2C bus.address
- I2C device address.addressSize
- I2C device address size. Can be 7 or 10.clockFrequency
- I2C clock frequency.order
- Default byte order for this deviceRuntimeIOException
- If an I/O error occurred.public int getController()
public int getAddress()
public int getAddressSize()
public int getClockFrequency()
public void close() throws RuntimeIOException
close
in interface Closeable
close
in interface AutoCloseable
RuntimeIOException
public final boolean isOpen()
public void write(int register, int subAddressSize, byte[] value) throws RuntimeIOException
register
- Register to writesubAddressSize
- sub-address size in bytes (1 or 2)value
- Bytes to be writtenRuntimeIOException
- if an I/O error occurspublic void writeShort(int regAddr, short val) throws RuntimeIOException
RuntimeIOException
public ByteBuffer read(int address, int count)
public void read(int address, ByteBuffer dst) throws RuntimeException
RuntimeException
public void read(int address, int subAddressSize, ByteBuffer buffer) throws RuntimeIOException
RuntimeIOException
public byte[] read(int address, int subAddressSize, int count) throws RuntimeIOException
RuntimeIOException
public byte readByte(int regAddr) throws RuntimeIOException
regAddr
- Register regAddr to read fromRuntimeIOException
- if an I/O error occurspublic short readUByte(int regAddr) throws RuntimeIOException
RuntimeIOException
public byte readByte(int register, int subAddressSize) throws RuntimeIOException
RuntimeIOException
public short readShort(int address) throws RuntimeIOException
RuntimeIOException
public short readShort(int address, int subAddressSize) throws RuntimeIOException
RuntimeIOException
public short readShort(int address, int subAddressSize, ByteOrder order) throws RuntimeIOException
RuntimeIOException
public int readUShort(int address) throws RuntimeIOException
RuntimeIOException
public int readUShort(int address, int subAddressSize) throws RuntimeIOException
RuntimeIOException
public int readUShort(int address, int subAddressSize, ByteOrder order) throws RuntimeIOException
RuntimeIOException
public long readUInt(int address) throws RuntimeIOException
RuntimeIOException
public long readUInt(int address, ByteOrder order) throws RuntimeIOException
RuntimeIOException
public long readUInt(int address, int subAddressSize, int length) throws RuntimeIOException
RuntimeIOException
public long readUInt(int address, int subAddressSize, int length, ByteOrder order) throws RuntimeIOException
RuntimeIOException
public boolean readBit(int regAddr, int bitNum) throws RuntimeIOException
regAddr
- Register regAddr to read frombitNum
- Bit position to read (0-7)RuntimeIOException
- if an I/O error occurspublic byte readBits(int regAddr, int bitStart, int length) throws RuntimeIOException
regAddr
- Register regAddr to read frombitStart
- First bit position to read (0-7)length
- Number of bits to read (not more than 8)RuntimeIOException
- if an I/O error occurspublic byte[] readBytes(int regAddr, int length) throws RuntimeIOException
regAddr
- First register regAddr to read fromlength
- Number of bytes to readRuntimeIOException
- if an I/O error occurspublic void writeBit(int regAddr, int bitNum, int value) throws RuntimeIOException
regAddr
- Register regAddr to write tobitNum
- Bit position to write (0-7)value
- New bit value to writeRuntimeIOException
- if an I/O error occurspublic void writeBit(int regAddr, int bitNum, boolean value) throws RuntimeIOException
regAddr
- Register regAddr to write tobitNum
- Bit position to write (0-7)value
- New bit value to writeRuntimeIOException
- if an I/O error occurspublic void writeBits(int regAddr, int bitStart, int length, int data) throws RuntimeIOException
regAddr
- Register regAddr to write tobitStart
- First bit position to write (0-7)length
- Number of bits to write (not more than 8)data
- Right-aligned value to writeRuntimeIOException
- if an I/O error occurspublic void write(int register, int subAddressSize, byte value) throws RuntimeIOException
register
- Register to writesubAddressSize
- sub-address size in bytes (1 or 2)value
- Byte to be writtenRuntimeIOException
- if an I/O error occurspublic void writeByte(int regAddr, int data) throws RuntimeIOException
regAddr
- Register address to write todata
- New byte value to writeRuntimeIOException
- if an I/O error occurspublic void writeByte(int regAddr, byte data) throws RuntimeIOException
regAddr
- Register address to write todata
- New byte value to writeRuntimeIOException
- if an I/O error occurspublic void writeWord(int regAddr, int data) throws RuntimeIOException
regAddr
- Register address to write todata
- New word value to writeRuntimeIOException
- if an I/O error occurspublic void writeBytes(int regAddr, int length, byte[] data) throws RuntimeIOException
regAddr
- First register address to write tolength
- Number of bytes to writedata
- Buffer to copy new data fromRuntimeIOException
- if an I/O error occurspublic void writeBytes(int regAddr, int length, byte[] data, int offset) throws RuntimeIOException
RuntimeIOException
public void read(ByteBuffer dst) throws RuntimeException
RuntimeException
public byte readByte() throws RuntimeIOException
RuntimeIOException
public byte[] read(int count) throws RuntimeException
RuntimeException
public void write(byte[] data) throws RuntimeException
RuntimeException
public void write(byte[] data, ByteOrder order) throws RuntimeException
RuntimeException
public void write(ByteBuffer buffer, int payloadLength, ByteOrder order) throws RuntimeException
RuntimeException
public void write(ByteBuffer buffer, int payloadLength) throws RuntimeException
RuntimeException
public void write(int registerAddress, int addressSize, ByteBuffer buffer, int payloadLength, ByteOrder order) throws RuntimeException
RuntimeException
public void write(int registerAddress, ByteBuffer buffer, int payloadLength) throws RuntimeException
RuntimeException
public void writeByte(byte data) throws RuntimeException
RuntimeException
Copyright © 2016–2017 mattjlewis. All rights reserved.