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 int |
fd
File handle for this i2c bus
|
protected String |
filename
File name of this i2c bus
|
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 ). |
protected void |
open()
Opens the bus.
|
int |
readByte(I2CDeviceImpl device,
int localAddress) |
int |
readByteDirect(I2CDeviceImpl device) |
int |
readBytes(I2CDeviceImpl device,
int localAddress,
int size,
int offset,
byte[] buffer) |
int |
readBytesDirect(I2CDeviceImpl device,
int size,
int offset,
byte[] buffer) |
protected <T> T |
runActionOnExclusivLockedBus(Callable<T> action)
Sometimes communication to an i2c device must not be disturbed by communication to another i2c device.
|
String |
toString() |
int |
writeAndReadBytesDirect(I2CDeviceImpl device,
int writeSize,
int writeOffset,
byte[] writeBuffer,
int readSize,
int readOffset,
byte[] readBuffer) |
int |
writeByte(I2CDeviceImpl device,
int localAddress,
byte data) |
int |
writeByteDirect(I2CDeviceImpl device,
byte data) |
int |
writeBytes(I2CDeviceImpl device,
int localAddress,
int size,
int offset,
byte[] buffer) |
int |
writeBytesDirect(I2CDeviceImpl device,
int size,
int offset,
byte[] buffer) |
protected int fd
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(I2CDeviceImpl device) throws IOException
IOException
public int readBytesDirect(I2CDeviceImpl device, int size, int offset, byte[] buffer) throws IOException
IOException
public int readByte(I2CDeviceImpl device, int localAddress) throws IOException
IOException
public int readBytes(I2CDeviceImpl device, int localAddress, int size, int offset, byte[] buffer) throws IOException
IOException
public int writeByteDirect(I2CDeviceImpl device, byte data) throws IOException
IOException
public int writeBytesDirect(I2CDeviceImpl device, int size, int offset, byte[] buffer) throws IOException
IOException
public int writeByte(I2CDeviceImpl device, int localAddress, byte data) throws IOException
IOException
public int writeBytes(I2CDeviceImpl device, int localAddress, int size, int offset, byte[] buffer) throws IOException
IOException
public int writeAndReadBytesDirect(I2CDeviceImpl device, int writeSize, int writeOffset, byte[] writeBuffer, int readSize, int readOffset, byte[] readBuffer) throws IOException
IOException
protected <T> T runActionOnExclusivLockedBus(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 methodaction
- The action to be runRuntimeException
- thrown by the custom codeIOException
- see method description aboveI2CFactory.getInstance(int, long, java.util.concurrent.TimeUnit)
public int getBusNumber()
getBusNumber
in interface I2CBus
Copyright © 2012–2019 Pi4J. All rights reserved.