获取 AT 命令响应 [英] Get AT command response
本文介绍了获取 AT 命令响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用带有 sim900 gps/gprs 模块的 Arduino Uno 并且我正在使用 at 命令,我如何获得 at 命令的响应(即 OK、ERROR)以便我可以做一些事情 if response== "OK"
或 response == "ERROR"
I am using an Arduino Uno with a sim900 gps/gprs module and I'm using at commands, how can I get the response of at command (i.e OK, ERROR) so that I can do something if response == "OK"
or response == "ERROR"
推荐答案
您可以使用以下代码在发出AT命令后立即读取SIM900 GSM模块的响应.
You can use following code to read response from SIM900 GSM Module just after issuing AT command.
char response[200];
for(int i = 0 ; Serial.available() > 0 && i<200 ; i++) {
response[i++] = Serial.read();
}
阅读响应后,您可以使用strstr()
函数来检查它是'OK'还是'ERROR',如下所示:
After reading response you can use strstr()
function to check whether it is 'OK' or 'ERROR', as given below:
if(strstr(responce, "OK"){
/*Do your code to handle OK response*/
}
else if(strstr(responce, "ERROR"){
/*Do your code to handle ERROR response*/
}
else {
/* You got some other response*/
}
这篇关于获取 AT 命令响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文