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. |
UARTPermission |
The
UARTPermission class defines permissions for UART channel access. |
UART
instance for the UART device using its numerical ID, name, type (interface)
and/or properties:
UART uart = (UART) PeripheralManager.open(14);
Or (with modem signals control properties),UART uart = PeripheralManager.open("HOST", UART.class, null);
ModemUART uart = PeripheralManager.open("MODEM", ModemUART.class, null);
ByteChannel
interface. When done, the application should call theByteBuffer buffer = new ByteBuffer(); ... uart.read(buffer); ... uart.write(buffer); ...
Peripheral.close()
method to
close the UART device. The following sample code gives an example of using the UART API to communicate with some host terminal:uart.close();
The following sample codes give examples of using the ModemUART API to additionally control the MODEM signals:try (UART host = PeripheralManager.open("HOST", UART.class, (String) null); InputStream is = Channels.newInputStream(host); OutputStream os = Channels.newOutputStream(host)) { 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); // Procees the command } } catch (IOException ioe) { // Handle exception }
Note that the preceding example is using a try-with-resources statement and that thetry (ModemUART modem = PeripheralManager.open("HOST", ModemUART.class, (String) null); InputStream is = Channels.newInputStream(modem); OutputStream os = Channels.newOutputStream(modem)) { modem.setSignalChangeListener(new ModemSignalListener<ModemUART>() { @Override public void signalStateChanged(ModemSignalEvent<ModemUART> event) { if (event.getSignalState() == false) { ModemUART modem = event.getPeripheral(); // Process MODEM hang-up... } } }, ModemSignalsControl.DCD_SIGNAL); // Process input and output... } catch (IOException ioe) { // Handle exception }
UART.close
, InputStream.close
and OutputStream.close
methods are automatically invoked
by the platform at the end of the statement.
Unless otherwise noted, passing a null
argument to a constructor or method in any class
or interface in this package will cause a NullPointerException
to be thrown.
This package requires the com.oracle.deviceaccess.modem
package.Copyright © 2012, 2014, Oracle and/or its affiliates. All rights reserved.
Legal Notices