End of response to an AT command

后端 未结 5 1983
Happy的楠姐
Happy的楠姐 2020-12-21 06:36

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

相关标签:
5条回答
  • 2020-12-21 06:56

    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.

    0 讨论(0)
  • 2020-12-21 06:58

    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

    0 讨论(0)
  • 2020-12-21 07:01

    Depending on mode and command I.e.

    <CR> or <CR><LF>
    

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

    0 讨论(0)
  • 2020-12-21 07:06

    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.

    0 讨论(0)
  • 2020-12-21 07:08

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

    0 讨论(0)
提交回复
热议问题