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 retrieving the underlying input and output streams of a
data connection opened by issuing an AT command (such as ATD). |
| 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. |
ATDevice or ATModem instance for the
device the application wants to control, using its numerical ID, name, type (interface) and/or properties:
ATDevice device = (ATDevice) PeripheralManager.open(15);
ATDevice device = (ATDevice) PeripheralManager.open("MODEM", ATDevice.class, new String[] {
"javax.deviceaccess.atcmd.psd=true", "javax.deviceaccess.atcmd.sms=true" });
Or (with modem signals control properties),
ATModem device = (ATModem) PeripheralManager.open("MODEM", ATModem.class, new String[] {
"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 release 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 succesfully
} else if (response.indexOf("ERROR") >= 0) {
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 = (ATDevice) PeripheralManager.open(null, ATDevice.class,
new String[] { "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 succesfully
} catch (IOException ex) {
} catch (PeripheralNotFoundException ex) {
} catch (PeripheralTypeNotSupportedException ex) {
} catch (PeripheralNotAvailableException ex) {
}
return false;
}
public int getStatus() {
return status;
}
public void close() {
if (modem != null) {
try {
modem.close();
} catch (IOException ex) {
// Ignored
}
}
}
com.oracle.deviceaccess.PeripheralManager.open methods. The permissions below allow access to be granted to AT
devices as a whole as well as to to some of their protected functions.
| Permission | Function |
|---|---|
"com.oracle.deviceaccess.atcmd" |
Access to AT devices and modems (as a whole) |
"com.oracle.deviceaccess.atcmd.ATDevice.openDataConnection" |
Opening data connections |
Copyright (c) 1990, 2013, Oracle and/or its affiliates. All rights reserved.