End of response to an AT command

后端 未结 5 1982
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.

提交回复
热议问题