I am trying to read the result of an AT command (command executed to do various operation to a GSM modem from console). I have seen and successfully tested using the Java OuputStream class to get the result of an AT command as output stream but what I need to do is to get the result not as outputstream but into a variable (String for now) in my class.
If it is possible to do like
outStream.write(("Some At command").getBytes());
which works fine, how can it be possibe to do something like this
Strign resultOfCommmand=.....result of some AT command;
I am trying it in this way
InputStream is = new ByteArrayInputStream(("some at commamd").getBytes());
String result = getStringFromInputStream(is);
System.out.println("66666666666666666666-----"+result);
/////////////////////
private static String getStringFromInputStream(InputStream is) {
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
String line;
try {
br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return sb.toString();
}
but insted of getting the result iam getting the at command itself as a string like this.... output:
66666666666666666666-----AT+CMGR=20