How to obtain answer's value from commands? through java code | Telit Cinterion IoT Developer Community
October 13, 2016 - 3:54pm, 9867 views
Hello
Im using this class (public class ATCommand) sucesfully.I can see answer from commands into console, but I would like to have access to this date through Java.
This is what I have:
answer=atc.send( new String(cmd) + 0x0D);
System.out.println(answer);
I got command and his answer on console.
This is the method
public String send(String ATCmd) throws ATCommandFailedException, IllegalStateException, IllegalArgumentException
- Parameters:
ATCmd
- The command to send.- Returns:
- The complete answer of the device corresponding to the send command.
- How to access to this "complete answer" through java code in ATCommand class isnt a method as getCommandAnswer, so how is posible ?
Hello, thanks, I understood the problem, but cannot find the way to solve it...
maybe problem is in the way how the user writes incomming commands through
while ((cmd[i]=(byte)is.read())!=0x0D) { i++; }
in this case is taking \r and maybe this is the '0' character that you mean...
or maybe in answer=atc.send(new String(cmd)+0x0D);
0x0D again,,,, but I already proved deleting it and doesnt work....
in your example you got this answer:
AT^SCTM?^SCTM;1,0,29 OK
how could you take the answer without the spaces that are troubling me?
Hello,
It is 0x00 character (NULL according to ASCII table) which is added to the command.
There's a byte buffer in the code to collect the command form the serial interface. The table is initiated with zeroes by default. Then you convert the whole buffer to String, add 0x0D and send as AT command. All the 0x00 characters are sent to the AT command interpreter and it seems that it echoes only one of 0x00 characters back.
So you should only send the command either by converting to String only the part of buffer that contains the valid data or you could try to use trim() on the created String.
The 0x0D is mandatory in the end as it is interpreted as the end of the command by the command interpreter - you will not be able to send the command without it.
I send the whole rsponse to the platform and the new line characters are removed on the platform to present the text in one line.
Regards,
Bartłomiej
thanks, and could you write these part of code to see how you got it ??
I did what you said, trying answer=atc.send( new String(cmd).trim() +0x0D ) but doesnt work
You are right, there should be a cast to char: (char)0x0D. I'm usually using this '\r' that's why I forgot to add the cast.
Regards,
Bartłomiej
yes !!!! is working !!!! thanks a lot !