Cep Terminals GSM/GPRS TERMINAL CT63 JAVA 6203 用户手册

产品代码
6203
下载
页码 109
Java User’s Guide
12.1 Using the AT Command API
109
wm_java_usersguide_v19
Page 104 of 109
2012-01-27
Confidential / Released
12.1.1.4
Synchronization
For performance reasons no synchronization is done in the ATCommand class. If an instance 
of this class has to be accessed from different threads ensure that the send() functions, the re-
lease()
 function, the cancelCommand() function and the breakConnection() function are syn-
chronized in the user implementation.
12.1.2
ATCommandResponseListener Interface
The ATCommandResponseListener interface defines the capabilities for receiving the re-
sponse to an AT command sent to one of the module's AT parsers. When the user wants to 
use the non blocking version of the ATCommand.send function of an implementation class of 
the ATCommandResponseListener interface must be created first. The single method of this 
class, ATResponse(), must contain the processing code for the possible response to the AT 
command sent. 
12.1.2.1
Non-Blocking ATCommand.send() Method
After creating an instance of the ATCommandResponseListener class, the class instance can 
be passed as the second parameter of the non-blocking ATCommand.send() method. After the 
AT command has been passed to the AT parser, the function returns immediately and the re-
sponse to the AT command is passed to this callback class later when it becomes available
Somewhere in the application:
A running AT command sent with the non-blocking send function can be cancelled with AT-
Command.cancelCommand()
. Any possible responses to the cancellation are sent to the wait-
ing callback instance.
Note: Using the send methods with incorrect AT command syntax in the strings will cause er-
rors.
class MyListener implements ATCommandResponseListener {
  String listen_for;
  public MyListener(String awaited_response) {
    listen_for = awaited_response;
  }
  void ATResponse(String Response) {
    if (Response.indexOf(listen_for) >= 0) {
      System.out.println("received: " + strRcv);
    }
  } 
}
MyListener connect_list = new MyListener("CONNECT");
atc.send("ATD" + CALLED_NO + "\r", connect_list);
/* Application continues while the AT command is processed*/
/* When the module delivers its response to the AT command the callback
 * method ATResponse is called. If the response is "CONNECT", we will see
 * the printed message from ATResponse in MyListener. */