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 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. |
UARTConfig.Builder |
The
Builder class allows for creating and initializing
UARTConfig objects. |
UARTEvent |
The
UARTEvent class encapsulates events fired by devices that
implement the UART interface. |
UARTPermission |
The
UARTPermission class defines permissions for UART channel access. |
In order to access and control a specific UART device, an application should first open and obtain an
UART
instance for the UART device using its numeric ID, name, type (interface)
and/or properties:
- Using its ID
UART uart = (UART) DeviceManager.open(14);- Using its name and interface
Or (with modem signals control properties),UART uart = DeviceManager.open("HOST", UART.class, null);ModemUART uart = DeviceManager.open("MODEM", ModemUART.class, null);
Once opened, an application can read the received data bytes and write the data bytes to be transmitted through the
UART using methods of the ByteChannel
interface.
ByteBuffer buffer = new ByteBuffer(); ... uart.read(buffer); ... uart.write(buffer); ...
When done, the application should call the Device.close()
method to
close the UART device.
uart.close();
The following sample code gives an example of using the UART API to communicate with some host terminal:
try (UART host = DeviceManager.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); // Process the command } } catch (IOException ioe) { // Handle exception }
The following sample codes give examples of using the ModemUART API to additionally control the MODEM signals:
try (ModemUART modem = DeviceManager.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.getDevice(); // Process MODEM hang-up... } } }, ModemSignalsControl.DCD_SIGNAL); // Process input and output... } catch (IOException ioe) { // Handle exception }
The preceding example is using a try-with-resources statement; the
UART.close
, InputStream.close
and OutputStream.close
methods are automatically invoked
by the platform at the end of the statement.
Unless otherwise noted, permission and security checks that may cause
a SecurityException
to be thrown must be performed
in priority to any other checks or operations once performed the checking of the input parameters
from which the permission target names and action lists are retrieved and assembled.
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 jdk.dio.modem
package.
Copyright © 2012, 2015, Oracle and/or its affiliates. All rights reserved.
Legal Notices