hit counter script

Sending An At Command To The Device, The Send() Method; Data Connections - Siemens Java TC65 User Manual

Java user's guide
Hide thumbs Also See for Java TC65:
Table of Contents

Advertisement

TC65 JAVA User's Guide
Strictly confidential / Released
12.1.1.2

Sending an AT Command to the Device, the send() Method

An AT command is sent to the device by using the send() method. The AT command is sent
as a string which must include the finalizing line feed "\r" or the corresponding line end
character.
String response = atc.send("at+cpin?\r");
/* method returns when the module returns a response */
System.out.println(response);
Possible response printed to System.out:
+CPIN: READY OK
This send function is a blocking call, which means that the calling thread will be interrupted
until the module returns a response. The function returns the response, the result code of the
AT command, as a string.
Occasionally it may be infeasible to wait for an AT command that requires some time to be
processed, such as at+cops?. There is a second, non-blocking, send function which takes a
second parameter in addition to the AT command. This second parameter is a callback
instance, ATCommandResponseListener. Any response to the AT command is delivered to
the callback instance when it becomes available. The method itself returns immediately. The
ATCommandResponseListener and the non-blocking send method are described in Section
12.1.2.
Note: Using the send methods with strings with incorrect AT command syntax will cause
errors.
12.1.1.3

Data Connections

If a data connection is created with the ATCommand class, for instance with 'atd', an input
stream is opened to receive the data from the connection. Similarly, an output stream can be
opened to send data on the connection.
/* Please note that this example would not work unless the module had
* been initialized and logged into a network. */
System.out.println("Dialing: ATD" + CALLED_NO);
response = atc.send("ATD" + CALLED_NO + "\r");
System.out.println("received: " + response);
if (response.indexOf("CONNECT") >= 0) {
try {
// We have a data connection, now we do some streaming...
// IOException will be thrown if any of the Stream methods fail
OutputStream dataOut = ATCmd.getDataOutputStream();
InputStream dataIn = ATCmd.getDataInputStream();
// out streaming...
dataOut.write(new String("\n\rHello world\n\r").getBytes());
dataOut.write(new String("\n\rThis data was sent by a Java " +
dataOut.write(new String("Press 'Q' to close the " +
// ...and in streaming
System.out.println("Waiting for incoming data, currently " +
rcv = 0;
TC65 JAVA User's Guide_V05
"MIDlet!\n\r").getBytes());
"connection\n\r").getBytes());
dataIn.available() + " bytes in buffer.");
Page 83 of 90
s
26.09.2005

Advertisement

Table of Contents
loading

Table of Contents