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

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

问题描述

如果 AT 命令执行成功或失败,我如何以编程方式进行检查.

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

我已进行以下检查:

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

我只是想确定这个检查是否可以通用,或者至少可以放在 AT+CUSD 命令上.我无法放置包含检查,因为 ussd 响应本身可以包含ok"或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".

是的,OKERROR 是通用的,但 ERROR 可能会被其他东西代替,并且还有其他响应.V.250 规范定义了大部分最终结果代码但另外还有27.007定义 +CME ERROR:27.005 定义 +CMS 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:.

你可以查看atinout的代码以组合 is_final_result 函数为例,尽管 ST-Ericsson 的 U300 RIL 似乎更接近您的用法.但请注意,CONNECT 不是最终结果代码,而是中间结果代码,因此名称 isFinalResponseSuccess 并非 100% 正确,您很可能不希望包含它.

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.

关于包含与结束无关紧要;最终结果代码总是单独出现在一行1,所以你应该经常检查它.换句话说,您应该始终只从调制解调器读取和缓冲响应数据,直到您收到一个终止 字节对,然后首先开始解析接收到的行(绝对唯一的例外是当在发送有效载荷之前等待 AT+CMGS 的 4 字节响应).

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 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
");
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 前提是没有搞乱行尾配置,例如你应该总是让 S3S4 成为 以及使用 ATV1.

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

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

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