public class I2CBusImpl extends Object implements I2CBus
Modifier and Type | Field and Description |
---|---|
protected int |
busNumber
Used to identifiy the i2c bus within Pi4J
|
protected LinuxFile |
file
File handle for this i2c bus
|
protected String |
filename
File name of this i2c bus
|
protected int |
lastAddress |
protected long |
lockAquireTimeout |
protected TimeUnit |
lockAquireTimeoutUnit |
Modifier | Constructor and Description |
---|---|
protected |
I2CBusImpl(int busNumber,
String fileName,
long lockAquireTimeout,
TimeUnit lockAquireTimeoutUnit)
Constructor of i2c bus implementation.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this i2c bus.
|
int |
getBusNumber() |
I2CDevice |
getDevice(int address)
Returns i2c device implementation (
I2CDeviceImpl ). |
void |
ioctl(I2CDevice device,
long command,
ByteBuffer values,
IntBuffer offsets) |
void |
ioctl(I2CDevice device,
long command,
int value) |
protected void |
open()
Opens the bus.
|
int |
readByte(I2CDevice device,
int localAddress) |
int |
readByteDirect(I2CDevice device) |
int |
readBytes(I2CDevice device,
int localAddress,
int size,
int offset,
byte[] buffer) |
int |
readBytesDirect(I2CDevice device,
int size,
int offset,
byte[] buffer) |
<T> T |
runBusLockedDeviceAction(I2CDevice device,
Callable<T> action)
Selects a device on the bus for an action, and locks parallel access around file descriptor operations.
|
protected void |
selectBusSlave(I2CDevice device)
Selects the slave device if not already selected on this bus.
|
protected void |
testForProperOperationConditions(I2CDevice device) |
String |
toString() |
int |
writeAndReadBytesDirect(I2CDevice device,
int writeSize,
int writeOffset,
byte[] writeBuffer,
int readSize,
int readOffset,
byte[] readBuffer) |
void |
writeByte(I2CDevice device,
int localAddress,
byte data) |
void |
writeByteDirect(I2CDevice device,
byte data) |
void |
writeBytes(I2CDevice device,
int localAddress,
int size,
int offset,
byte[] buffer) |
void |
writeBytesDirect(I2CDevice device,
int size,
int offset,
byte[] buffer) |
protected int lastAddress
protected int busNumber
protected long lockAquireTimeout
protected TimeUnit lockAquireTimeoutUnit
protected I2CBusImpl(int busNumber, String fileName, long lockAquireTimeout, TimeUnit lockAquireTimeoutUnit)
busNumber
- used to identifiy the i2c bus within Pi4JIOException
- thrown in case that file cannot be openedpublic I2CDevice getDevice(int address) throws IOException
I2CDeviceImpl
).getDevice
in interface I2CBus
address
- address of i2c deviceIOException
- never in this implementationprotected void open() throws IOException
IOException
- thrown in case there are problems opening the i2c bus.public void close() throws IOException
close
in interface I2CBus
IOException
- never in this implementationpublic int readByteDirect(I2CDevice device) throws IOException
IOException
public int readBytesDirect(I2CDevice device, int size, int offset, byte[] buffer) throws IOException
IOException
public int readByte(I2CDevice device, int localAddress) throws IOException
IOException
public int readBytes(I2CDevice device, int localAddress, int size, int offset, byte[] buffer) throws IOException
IOException
public void writeByteDirect(I2CDevice device, byte data) throws IOException
IOException
public void writeBytesDirect(I2CDevice device, int size, int offset, byte[] buffer) throws IOException
IOException
public void writeByte(I2CDevice device, int localAddress, byte data) throws IOException
IOException
public void writeBytes(I2CDevice device, int localAddress, int size, int offset, byte[] buffer) throws IOException
IOException
public int writeAndReadBytesDirect(I2CDevice device, int writeSize, int writeOffset, byte[] writeBuffer, int readSize, int readOffset, byte[] readBuffer) throws IOException
IOException
public void ioctl(I2CDevice device, long command, int value) throws IOException
IOException
public void ioctl(I2CDevice device, long command, ByteBuffer values, IntBuffer offsets) throws IOException
IOException
public <T> T runBusLockedDeviceAction(I2CDevice device, Callable<T> action) throws IOException
The timeout used for the acquisition of the lock may be defined on getting the I2CBus from I2CFactory.
The 'run'-method of 'action' may throw an 'IOExceptionWrapperException' to wrap IOExceptions. The wrapped IOException is unwrapped by this method and rethrown as IOException.
T
- The result-type of the methoddevice
- Device to be selected on the busaction
- The action to be runRuntimeException
- thrown by the custom codeIOException
- see method description aboveI2CFactory.getInstance(int, long, java.util.concurrent.TimeUnit)
protected void selectBusSlave(I2CDevice device) throws IOException
device
- Device to selectIOException
protected void testForProperOperationConditions(I2CDevice device) throws IOException
IOException
public int getBusNumber()
getBusNumber
in interface I2CBus
Copyright © 2012–2019 Pi4J. All rights reserved.