如何检查AT命令执行成功还是失败 [英] How to check if an AT command executed successfully or failed

查看:281
本文介绍了如何检查AT命令执行成功还是失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式检查AT命令执行成功还是失败.

我已进行了以下检查:

boolean success = response.endsWith("OK");
boolean failed = response.endsWith("ERROR");

我只想确定此支票是否可以通用放置,或至少放在AT + CUSD命令上.由于usdd响应本身可以包含"ok"或"error"字符串,因此我无法放置包含检查.

解决方案

代表您采取出色的步骤来研究如何正确地做事,而不是仅仅停留在好吧,这似乎是通过反复试验而起作用".

是的,OKERROR是通用的,但ERROR可能会被其他内容代替,并且还存在其他响应. V.250 规范定义了大多数最终结果代码,但另外 27.007 定义+CME ERROR:,而 27.005 定义+CMS ERROR:.

您可以查看 atinout 的代码.作为组合is_final_result函数的示例,尽管ST-Ericsson的

如果您想在最终结果代码出现之前使用任何中间信息文本响应,则需要稍微改变一下循环(例如,在继续处理中间响应之前先检查最终结果代码).


1 前提是没有弄乱行尾配置,例如您应该始终将S3S4设置为\r\n,并使用ATV1.

How do I place a check programmatically if the AT command executed successfully or failed.

I have placed following check:

boolean success = response.endsWith("OK");
boolean failed = response.endsWith("ERROR");

I just want to be sure if this check can be placed universally, or atleast on AT+CUSD command. I cannot place contains check since the ussd response can itself contain 'ok' or 'error' strings.

解决方案

Excellent step on your behalf to investigate how to do things properly instead of just stopping on "well, this seems to work by trial and error".

Yes, OK and ERROR are universal but ERROR might be substituted with something else and there exists other responses as well. The V.250 specification defines most of the Final Result Codes but additionally 27.007 defines +CME ERROR: and 27.005 defines +CMS ERROR:.

You can look at the code for atinout for an example for a combined is_final_result function, although the two split isFinalResponseError and isFinalResponseSuccess functions in ST-Ericsson's U300 RIL seems closer to your usage. Note however that CONNECT is not a final result code, it is an intermediate result code, so the name isFinalResponseSuccess is not 100% correct and you most likely do not want to include that.

Regarding contains versus endsWith it does not matter; the final result codes always comes on a line all by itself1, so you should always check that. In other words you should always only read and buffer response data from the modem until you have received a terminating \r\n pair of bytes and first then start parsing that received line (the absolutely only exception is when waiting for the 4 byte response from AT+CMGS before sending the payload).

So your structure should look something like

Write(port, "AT+SOMECMD\r");
do {
         input = ReadLine(port, responseTimeout);
} while (!isFinalResultCode(input));

If you want to consume any intermediate information text responses before the final result code comes you need to change the loop a little (e.g. check for final result code first before continuing processing the intermediate response).


1 Provided that the end of line configuration has not been messed up, e.g. you should always let S3 and S4 be \r and \n as well as using ATV1.

这篇关于如何检查AT命令执行成功还是失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆