End of response to an AT command

喜夏-厌秋 提交于 2019-11-28 09:18:56

问题


How to be sure what is end of an AT command send to GSM module?

I need some character or string that represent end of AT command for every case due to finding when whole response is received.

I guess it have something with "\r\n" sequence but, this sequence could be at the beginning of AT command response?


回答1:


Like you suppose it's \r\n.
This defines the end of a line.

And it makes only sense to process complete lines.

Some commands respons with only OK\r\n, some with some data.
So you should build at first a parser, who can detect complete lines, so they can be processed with a function that handles responses.

Sometimes you can get even responses you don't request, like change events net login or the sim status #QSS: 2\r\n.

So you need to know what answer you expect and wait until you get this




回答2:


Referring the original Hayes command set Wikipedia is stating:

<CR> Carriage return character, is the command line and result code terminator character, which value, in decimal ASCII between 0 and 255, is specified within parameter S3. The default value is 13.

So it should be possible to set any character to indicate the end of the response (and as well the end of any command sent to the modem a well).


Anyhow <CR>s are not only returned as last character by many modem's responses.

So it might be an interesting experiment whether writing a different character value to S3 would just change the last character sent at the end of the modem's response, or if this would change any <CR> sent during the modem's response to be the value stored in S3.




回答3:


Here is what I used in Python. It works. There might be some other better solutions.

ser = serial.Serial(com, baudrate, timeout=5)
while True:
# a simple AT return result parser
    new_char = ser.read(1)
    byte_flow += new_char

    if len(byte_flow) >=4 and byte_flow[-4:] == b'\r\nOK':
        break
    elif len(byte_flow) >= 7 and byte_flow[-7:] == b'\r\nERROR':
        break
byte_flow += ser.read(2)  # the final '\r\n'

You can add more elif if there is any other patterns.




回答4:


The response format is command specific. While there are certain similarities ("OK\r\n"), in the end you need explicit handling for each.




回答5:


Depending on mode and command I.e.

<CR> or <CR><LF>

http://www.3gpp.org/ftp/Specs/html-info/27007.htm



来源:https://stackoverflow.com/questions/13286086/end-of-response-to-an-at-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!