Thales' cellular IoT products business is now part of Telit Cinterion, find out more.

You are here

Telit Cinterion IoT Developer Community

Encapsulate AT command method

FAQ, October 21, 2014 - 2:36pm, 7763 views

Hi,

A convinience way to encapsulate the AT command  method inside your MIDlet for easy use and to avoid to add the string "\r" in every call to the ATCommand class.

A posible way for the implementation:

 private ATCommand ATC;

private String sendCommand(String command) 

{

   try

        {

            if (ATC == null)

             {

               ATC = new ATCommand(False); //no at comand send to the method

             }

             String answer = ATC.send (command + "\r");

             Thread.sleep (100); // Remember at least to implement 100 ms sleep in order to recevie any URC
             return answer; //Return the AT command execution answer

         }

         catch (Exception e)

            {  

             // implemment the treatment for the exceptions in this block

            }

}
 

The call to the Method, examples:

        sendCommand("ATI1");

        sendCommand("AT+GSN");

        sendCommand("AT+CIMI");

Regards

ALopez

Overwrite the existing ATCommand class is a better approch for two reasons.
1) ATCommand is a limited resource and has to be released, but create and release same objects all the time should be avoided for performace and memory reason.

2) Sometimes a AT command has to be terminated by another character than '\r'. e.g. sending an SMS.

Here an example to overwrite the ATCommand class:

import com.cinterion.io.ATCommand;
import com.cinterion.io.ATCommandFailedException;

public class modemATInstance extends ATCommand {

	public modemATInstance(boolean arg0) throws ATCommandFailedException,
			IllegalStateException {
		super(arg0);
	}

	public String sendCr(String cmd) throws IllegalStateException,
			IllegalArgumentException, ATCommandFailedException {
		return super.send(cmd + '\r');
	}

} 

....
I started out with nothing... I still have most of it.

Author

Alopez's picture
Alopez