See: Description
| Interface | Description |
|---|---|
| ModemUART |
The
ModemUART interface provides methods for controlling and accessing a UART (Universal Asynchronous
Receiver/Transmitter) with Modem control lines. |
| UART |
The
UART interface provides methods for controlling and accessing a UART (Universal Asynchronous
Receiver/Transmitter). |
| UARTEventListener |
The
UARTEventListener interface defines methods for getting notified of events fired by peripheral devices
that implement the UART interface. |
| Class | Description |
|---|---|
| UARTConfig |
The
UARTConfig class encapsulates the hardware addressing information, and static and dynamic configuration
parameters of a UART. |
| UARTEvent |
The
UARTEvent class encapsulates events fired by peripherals that implement the UART interface. |
UART instance for the UART device using its numerical ID, name, type (interface)
and/or properties:
UART uart = (UART) PeripheralManager.open(1);
UART uart = (UART) PeripheralManager.open("HOST", UART.class, null);
Or (with modem signals control properties),
ModemUART uart = (ModemUART) PeripheralManager.open("MODEM", ModemUART.class, null);
UART.getInputStream() and
UART.getOutputStream() methods and can then read the received data bytes and
respectively write the data bytes to be transmitted through the UART. When done, the application should call theInputStream input = uart.getInputStream(); OutputStream output = uart.getOutputStream();
UART.close() method to
release UART device. The following sample codes give examples of using the UART API to communicate with some host terminal:uart.close();
UART host = null;
InputStream is = null;
OutputStream os = null;
try {
host = (UART) PeripheralManager.open("HOST", UART.class, (String[]) null);
is = host.getInputStream();
os = host.getOutputStream();
StringBuffer cmd = new StringBuffer();
int c = 0;
while (true) {
os.write('$');
os.write(' '); // echo prompt
while (c != '\n' && c != '\003') { // echo input
c = is.read();
os.write(c);
cmd.append(c);
}
if (c == '\003') { // CTL-C
break;
}
// process(cmd);
}
} catch (IOException ioe) {
// Handle exception
} catch (PeripheralException pe) {
// Handle exception
} finally {
if (is != null) {
try {
is.close();
} catch (IOException ex) {
}
}
if (os != null) {
try {
os.close();
} catch (IOException ex) {
}
}
if (host != null) {
try {
host.close();
} catch (IOException ex) {
}
}
}
The following sample codes give examples of using the ModemUART API to additionally control the MODEM
signals:
ModemUART modem = null;
InputStream is = null;
OutputStream os = null;
try {
modem = (ModemUART) PeripheralManager.open("HOST", ModemUART.class, (String[]) null);
is = modem.getInputStream();
os = modem.getOutputStream();
modem.setSignalChangeListener(new ModemSignalListener() {
public void signalStateChanged(ModemSignalEvent event) {
if (event.getSignalState() == false) {
ModemUART modem = (ModemUART) event.getPeripheral();
// Process MODEM hang-up...
}
}
}, ModemSignalsControl.DCD_SIGNAL);
// Process input and output...
} catch (IOException ioe) {
// Handle exception
} catch (PeripheralException pe) {
// Handle exception
} finally {
// Close UART, and input and output streams
}
Note that the preceding example is using a try-with-resources statement and that the
UART.close(), InputStream.close() and OutputStream.close() methods are automatically invoked
by the platform at the end of the statement.
com.oracle.deviceaccess.PeripheralManager.open methods. The "com.oracle.deviceaccess.uart" permission allows
access to be granted to UART devices as a whole.Copyright (c) 1990, 2013, Oracle and/or its affiliates. All rights reserved.