How to reject or accept an incoming call to my GSM modem using AT commands in Python?
Question: I've wrote the below Python program to wait for incoming calls and accept or
reject them. Based on [this](http://www.zeeman.de/wp-
content/uploads/2007/09/ubinetics-at-command-set.pdf) document and
[this](https://www.sparkfun.com/datasheets/Cellular%20Modules/AT_Commands_Reference_Guide_r0.pdf)
document, the appropriate AT commands to accept an incoming call is `ATA` or
`ATS0` or `ATS0<n>`. And also the appropriate commands to reject the incoming
call is `ATH` or `AT H`.

I tried all the above commands, but the incoming call neither answered nor
rejected!

**My Python program :**

    
    
    import time
    import serial
    
    phone = serial.Serial("COM10",  115200, timeout=5)
    
    try:
        time.sleep(1)
    
        while(1):
            x = phone.readline()
            print(x)
            if (x == b'RING\r\n'):
                phone.write(b'AT H') # I replaced this 'AT H' with all the above
                                     # commands, but nothing changed about the
                                     # incoming call. It always ringing.
                time.sleep(2)
    
    finally:
        phone.close()
    

**Results for`AT H`:**

    
    
    >>> ================================ RESTART ================================
    >>> 
    b''
    b''
    b'\r\n'
    b'RING\r\n'
    b'AT H\r\n'
    b'RING\r\n'
    b'AT H\r\n'
    b'RING\r\n'
    b'AT H\r\n'
    b'RING\r\n'
    b'AT H\r\n'
    b'RING\r\n'
    

**Results for`ATH`:**

    
    
    >>> ================================ RESTART ================================
    >>> 
    b''
    b''
    b''
    b'\r\n'
    b'RING\r\n'
    b'ATH\r\n'
    b'RING\r\n'
    b'ATH\r\n'
    b'RING\r\n'
    b'ATH\r\n'
    b'RING\r\n'
    

**Results for`ATA`:**

    
    
    >>> ================================ RESTART ================================
    >>> 
    b''
    b''
    b''
    b'\r\n'
    b'RING\r\n'
    b'ATA\r\n'
    b'RING\r\n'
    b'ATA\r\n'
    b'RING\r\n'
    b'ATA\r\n'
    b'RING\r\n'
    

**Results for`ATS0`:**

    
    
    >>> ================================ RESTART ================================
    >>> 
    b''
    b''
    b''
    b'\r\n'
    b'RING\r\n'
    b'ATS0\r\n'
    b'RING\r\n'
    b'ATS0\r\n'
    b'RING\r\n'
    

As you see above, the GSM modem regardless of the AT command that I send to
it, continue to ringing. What's wrong about my program?

_Note that my modem is a[D-Link
DWM-156](http://www.dlink.com/uk/en/support/product/dwm-156-3-75-hsupa-usb-
adapter) and I can send SMS or make a call successfully using it in Python._
Thanks in advance.


Answer: Add to the end of each `AT` command a **CR** to make it a valid `AT` command

