See: Description
| Interface | Description |
|---|---|
| ATDevice |
The
ATDevice interface provides methods for controlling a Data Communication Equipment
such as a modem or a cellular module using AT commands. |
| ATModem |
The
ATModem provides methods for controlling a Data Communication Equipment such as a modem or a cellular
module using AT commands and modem control signals. |
| CommandResponseHandler |
The
CommandResponseHandler interface defines methods for handling responses to AT commands. |
| DataConnection |
The
DataConnection interface provides methods for reading and writing to a data
connection opened by issuing an AT command (e.g. |
| DataConnectionHandler |
The
DataConnectionHandler interface defines methods for handling connection state
changes. |
| UnsolicitedResponseHandler |
The
UnsolicitedResponseHandler interface defines methods for handling unsolicited result
code responses from an AT device. |
| Class | Description |
|---|---|
| ATDeviceConfig |
The
ATDeviceConfig class encapsulates the hardware addressing information, and static and
dynamic configuration parameters of an AT device. |
| ATPermission |
The
ATPermission class defines permissions for AT device access. |
ATDevice or ATModem
instance for the device the application wants to control, using its numerical ID, name, type
(interface) and/or properties:
ATDevice device = DeviceManager.open(15);
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");
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. The following sample codes give examples of using the AT API to send an SMS:device.close();
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.Copyright © 2012, 2014, Oracle and/or its affiliates. All rights reserved.
Legal Notices