Device I/O API 1.0

Package jdk.dio.atcmd

Interfaces and classes for controlling a Data Communication Equipment such as a modem or a cellular module using AT commands.

See: Description

Package jdk.dio.atcmd Description

Interfaces and classes for controlling a Data Communication Equipment such as a modem or a cellular module using AT commands.

AT commands for GSM phone or modem are standardized through ETSI GSM 07.07 and ETSI GSM 07.05 specifications. A typical modem or an cellular module supports most of its features through AT commands and many manufactures provide additional features by adding proprietary extensions to the AT commands set.

In this specification, a device that can be controlled using AT commands is generically referred to as an AT device.

To control a specific AT device, an application should first open and obtain an ATDevice or ATModem instance for the device the application wants to control, using its numerical ID, name, type (interface) and/or properties:

Using its ID
 ATDevice device = DeviceManager.open(15);
 
Using its name, properties and interface
 ATDevice device = DeviceManager.open("MODEM", ATDevice.class, "javax.deviceaccess.atcmd.psd=true",
         "javax.deviceaccess.atcmd.sms=true");
 
Or (with modem signals control properties),
 ATModem device = DeviceManager.open("MODEM", ATModem.class, "javax.deviceaccess.atcmd.psd=true",
         "javax.deviceaccess.atcmd.sms=true");
 
Once the device opened, the application can issue AT commands to the device using methods of the ATDevice interface such as the sendCommand methods.
 device.sendCommand("AT\n");
 
When done, the application should call the ATDevice.close() method to close AT device.
 device.close();
 
The following sample codes give examples of using the AT API to send an SMS:
 public static final int SUBMITTED = 1;
 public static final int SENT = 2;
 public static final int ERROR = 3;
 private ATDevice modem = null;
 private int status = 0;
 
 private class SMSHandler implements CommandResponseHandler {
 
     String text;
 
     public SMSHandler(String text) {
         this.text = text;
     }
 
     public String processResponse(ATDevice modem, String response) {
         // Assume that command echo has been previously disabled (such as with an ATE0 command).
 
         if (response.equals("> \n")) { // Prompt for text
             return text;
         } else if (response.equals("OK\n")) {
             status = SENT;  // Sent successfully
         } else if (response.contains("ERROR")) {
             status = ERROR; // Failed to send
         }
         return null;
     }
 }
 
 public boolean sendSMS(final String number, final String text) {
     // Acquire a modem with "sms" properties
     try {
         if (modem == null) {
             modem = DeviceManager.open(null, ATDevice.class, "javax.deviceaccess.atcmd.sms=true");
         }
         // Send SMS command
         SMSHandler sh = new SMSHandler(text);
         modem.sendCommand("AT+CMGS=\"" + number + "\"\n", sh);
         status = SUBMITTED;
         return true; // Submitted successfully
     } catch (IOException ioe) {
         return false; // Failed to submit
     }
 }
 
 public int getStatus() {
     return status;
 }
 
 public void close() {
     if (modem != null) {
         try {
             modem.close();
         } catch (IOException ex) {
             // Ignored
         }
     }
 }
 

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.

Device I/O API 1.0