DAAPI B (b02)
- Java ME Embedded 3.3 Release

Package com.oracle.deviceaccess.uart

Interfaces and classes for controlling and reading and writing from/to Universal Asynchronous Receiver/Transmitter (UART), with optional Modem signals control.

See: Description

Package com.oracle.deviceaccess.uart Description

Interfaces and classes for controlling and reading and writing from/to Universal Asynchronous Receiver/Transmitter (UART), with optional Modem signals control.

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 numerical ID, name, type (interface) and/or properties:

Using its ID
 UART uart = (UART) PeripheralManager.open(1);
 
Using its name and interface
 UART uart = (UART) PeripheralManager.open("HOST", UART.class, null);
 
Or (with modem signals control properties),
 ModemUART uart = (ModemUART) PeripheralManager.open("MODEM", ModemUART.class, null);
 
Once opened, an application can obtain an input stream and an output stream using the 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.
 InputStream input = uart.getInputStream();
 OutputStream output = uart.getOutputStream();
 
When done, the application should call the UART.close() method to release UART device.
 uart.close();
 
The following sample codes give examples of using the UART API to communicate with some host terminal:
 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.

Security

UARTs are opened by invoking one of the com.oracle.deviceaccess.PeripheralManager.open methods. The "com.oracle.deviceaccess.uart" permission allows access to be granted to UART devices as a whole.
DAAPI B (b02)
5-February-2013 04:40

Copyright (c) 2012, Oracle and/or its affiliates. All Rights Reserved. Use of this specification is subject to license terms.