|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jcontrol.comm.I2C
public class I2C
Controls I2C devices connected to JControl.
The I2C bus is a de facto standard for on board inter integrated
circuit communication invented by
Phillips (NXP).
Many chips are supporting this bus, including the JControl
RTC
on some Boards.
Currently JControl only works as I2C busmaster, so it can only send data
and send requests for data actively. It can't poll the bus as slave and reply for
requests of other masters. It is a simple hardware layer implementation so any
bus error and any lost arbitration results in an IOException
after
some retries. To avoid blocking there is contrary to the specification a bus timeout
also resulting in an IOException
.
Another bus system based on I2C is the SM (system management) bus available on some PC motherboards, for monitoring tempeartures and controlling fans.
Field Summary | |
---|---|
static int |
MODE_10BIT
Selects I2C mode with 10-bit addresses. |
static int |
MODE_7BIT
Selects I2C mode with 7-bit addresses (default). |
Constructor Summary | |
---|---|
I2C(int address)
Constructs a new I2C object for 7-bit addresseing. |
|
I2C(int address,
int mode)
Constructs a new I2C object. |
Method Summary | |
---|---|
int |
available()
Note: not supported |
void |
close()
Closes this I2C instance, further reads or writes are not possible. |
void |
flush()
Note: not supported |
void |
mark(int readlimit)
Note: not supported |
boolean |
markSupported()
Note: not supported, always returning false |
int |
read()
Just reads a single byte from the I2C device. |
int |
read(byte[] data)
Reads a data stream from a I2C device. |
int |
read(byte[] cmd,
byte[] data,
int startindex,
int length)
Writes a command stream to a I2C device and reads a reply in the same transaction. |
int |
read(byte[] data,
int startindex,
int length)
Reads a data stream from a I2C device. |
void |
reset()
Note: not supported |
int |
skip(int n)
Note: not supported |
void |
write(byte[] data)
Writes a data stream to a I2C device. |
void |
write(byte[] cmd,
byte[] data,
int startindex,
int length)
Writes a command stream and a data stream to a I2C device in the same transaction. |
void |
write(byte[] data,
int startindex,
int length)
Writes a data stream to a I2C device. |
void |
write(int data)
Just writes a single byte to the I2C device. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, notifyAll, toString, wait |
Field Detail |
---|
public static final int MODE_7BIT
public static final int MODE_10BIT
Constructor Detail |
---|
public I2C(int address)
address
- 7-bit address of the the device to send data topublic I2C(int address, int mode)
address
- of the the device to send data tomode
- bus mode (addressing etc)MODE_7BIT
,
MODE_10BIT
Method Detail |
---|
public void write(byte[] data, int startindex, int length) throws IOException
write
in interface BasicOutputStream
data
- the buffer that holds the data to writestartindex
- the index to start reading the array (and writing to I2C)length
- number of bytes to write; the array is read from startindex
to startindex
+length
-1
IOException
- if an error occurspublic int read(byte[] data, int startindex, int length) throws IOException
read
in interface BasicInputStream
data
- the buffer to fillstartindex
- the index to start filling the array (with data read from I2C)length
- number of bytes to read; the array is filled from startindex
to startindex
+length
-1, it may be partially filled
according to the I2C slave device
IOException
- if an error occursInputStream.read()
public void write(byte[] data) throws IOException
write
in interface BasicOutputStream
data
- the buffer that holds the data to write
IOException
- if an error occursOutputStream.write(byte[], int, int)
public int read(byte[] data) throws IOException
read
in interface BasicInputStream
data
- the buffer to fill
IOException
- if an error occursInputStream.read(byte[], int, int)
public void write(byte[] cmd, byte[] data, int startindex, int length) throws IOException
cmd
- the buffer with command to write
(all bytes of array, null
for command omission)data
- the buffer to read data to transmitstartindex
- the index to start reading the array (and writing to I2C)length
- number of bytes to read; the array is accessed from startindex
to startindex
+length
-1
IOException
- if an error occurspublic int read(byte[] cmd, byte[] data, int startindex, int length) throws IOException
cmd
- the buffer with command to write
(all bytes of array, null
for command omission)data
- the buffer to write received datastartindex
- the index to start writing the array (and reading from to I2C)length
- number of bytes to write; the array is accessed from startindex
to startindex
+length
-1, it may be partially filled
according to the I2C slave device
IOException
- if an error occurspublic void close()
close
in interface BasicInputStream
close
in interface BasicOutputStream
BasicOutputStream.close()
public void write(int data) throws IOException
write
in interface BasicOutputStream
data
- I2C Data to transmit (range 0...255)
IOException
- if an I/O error occurs. In particular,
an IOException
may be thrown if the
output stream has been closed.BasicOutputStream#write(char)
public int read() throws IOException
read
in interface BasicInputStream
IOException
- if an I/O error occurs.BasicInputStream.read()
public int skip(int n) throws IOException
skip
in interface BasicInputStream
n
- the number of bytes to be skipped.
IOException
- if an I/O error occurs.public int available() throws IOException
available
in interface BasicInputStream
IOException
- if an I/O error occurs.public void mark(int readlimit)
mark
in interface BasicInputStream
readlimit
- the maximum limit of bytes that can be read before
the mark position becomes invalid.public void reset() throws IOException
reset
in interface BasicInputStream
IOException
- if this stream has not been makred or if the
mark has been invalidated.public boolean markSupported()
markSupported
in interface BasicInputStream
true
if this stream instance supports the mark
and reset methods; false
otherwise.public void flush() throws IOException
flush
in interface BasicOutputStream
IOException
- if an I/O error occurs.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |