How to obtain answer's value from commands? through java code | Telit Cinterion IoT Developer Community
October 13, 2016 - 3:54pm, 10127 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,
You send the AT commands as text strings with send() method and get the complete reply as test string as a result also. So now you need to parse the answer with Java API to get what you want from it.
Regards,
Bartłomiej
Hello, I still cannot understand from where to take this answer's value.
Doing it atc.send( new String(cmd) + 0x0D); is sent the order to execute command and to get the answer, but where stay this answer?
for example if I type <<at^sctm?>> the answer on screen's console is << at^sctm? ^sctm? 0,0,32 >> but if I try to take the answer value to try to use it in another class I can see only the command that was send, in this case <<at^sctm?>>
thanks for your help
If you are using the send() method from ATCommand class that returns the String it should return the complete answer, the same that you would get sending the command without Java MIDlet.
In your example:
answer=atc.send( new String(cmd) + 0x0D);
System.out.println(answer);
the complete answer should be displayed. Isn't it so in your case? Are you sure that your code does not process the answer anyhow before displaying it? Have you tried the AtCmdDemo example MIDlet which should be on your PC if you have installed the provided environment software?
BR,
Bartłomiej
Hello,
I can see displayed the complete answer in console.
I dont know if the code processed the answer before displaying. I guess not.
Im trying to send answer into:
public class MyDataExchangeUnit extends DataExchangeUnitString
getAnswer();
then in SL portal>device>Data Exchange Device
I can see there only "command" that I sent but not the answer. But by console I can see "command+answer"
I dont know where is lost the answer's value.
I'm using this example as guide:
AT commands via Java MIDlet
https://iot-developer.thalesgroup.com/showcase/commands-java-midlet-uart-java-midlet-interpreter-pipe
So if you get the complete answer from the send() command, everything is OK from the ATCommand's perspective. If you now put this string as an argument for the method from DataExchange API (and you don't cut it before) it should be transferred to the SL server and should be available there.
Please paste your code. If it is correct that would mean that the string is cut somewhere else. You could also try to extract the line with real answer and try to send only this line. Or exchange all white characters with just space and then check.
Regards,
Bartłomiej
Hello, this is my code:
in class public class ATService :
answer=atc.send(new String(cmd)+0x0D);
and
public static String getAnswer() {
return answer;
}
public static void setAnswer(String answer) {
ATService.answer = answer;
}
import com.gemalto.m2m.slagent.services.application.DataExchangeDeviceConfiguration;
import com.gemalto.m2m.slagent.services.application.DataExchangeException;
import com.gemalto.m2m.slagent.services.application.DataExchangeUnitString;
import pipe.ATService;
public class MyDataExchangeUnit extends DataExchangeUnitString {
ATService atService;
DataExchangeUnitString dataExchangeUnitString;
private DataExchangeDeviceConfiguration data_configuration;
protected MyDataExchangeUnit(String id, String label, boolean readOnly,DataExchangeDeviceConfiguration data_configuration) {
super(id, label,readOnly);
}
public String getValue() throws DataExchangeException {
String return1;
return1=ATService.getAnswer();
return return1;
}
Im trying to get through getValue the complete answer including the code, or only the answer, but only is displayed on SL portal the command I sent.
Thanks
Looks fine. On the other hand I have just tried to send the AT^SCTM? reply by a subclass of DataExchangeUnitString. And the whole response was visible on the portal (just all was in one line). Can you check your libraries version? Maybe there's some difference.
Hello
I dont know why but still cannot see the complete answer on SL portal. Still the same problem, just is visible the command. The libraries I'm using are:
cwmlib_1.0 jar
com.cinterion.io
modserv_4.0.1.741.jar
common_4.0.1.741.jar
appserv_4.0.1.741.jar
also: cldc_1.1.jar; cwm_1.0.jar; impng_1.0.jar; jsr75_1.0.jar; jsr177-1.0-crypto.jar: jsr179_1.0.jar:, jsr280_1.0.jar
Maybe I'm missing one?
I have tested with the same libraries version: 4.0.1.741 and the result is a below:
And what's in the application log - is there the whole response?
I see.... yes, in app log is the full answer.
[INFO] [DataExchangeDeviceGRIPConnection: MyDataExchangeDevice id] refreshStringValue: index: 0 value: at^sbv SBV: 4177
I still cannot get the answer as in your image, something I'm doing wrong maybe on ATService class or DataExchangeUnitString instance.
Pages