title: How to reject or accept an incoming call to my GSM modem using AT commands in Python?
body: <p>I've wrote the below Python program to wait for incoming calls and accept or reject them. Based on <a href="http://www.zeeman.de/wp-content/uploads/2007/09/ubinetics-at-command-set.pdf" rel="nofollow">this</a> document and <a href="https://www.sparkfun.com/datasheets/Cellular%20Modules/AT_Commands_Reference_Guide_r0.pdf" rel="nofollow">this</a> document, the appropriate AT commands to accept an incoming call is <code>ATA</code> or <code>ATS0</code> or <code>ATS0&lt;n&gt;</code>. And also the appropriate commands to reject the incoming call is <code>ATH</code> or <code>AT H</code>. </p>
  
  <p>I tried all the above commands, but the incoming call neither answered nor rejected!</p>
  
  <p><strong>My Python program :</strong></p>
  
  <pre><code>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()
  </code></pre>
  
  <p><strong>Results for <code>AT H</code>:</strong></p>
  
  <pre><code>&gt;&gt;&gt; ================================ RESTART ================================
  &gt;&gt;&gt; 
  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'
  </code></pre>
  
  <p><strong>Results for <code>ATH</code>:</strong></p>
  
  <pre><code>&gt;&gt;&gt; ================================ RESTART ================================
  &gt;&gt;&gt; 
  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'
  </code></pre>
  
  <p><strong>Results for <code>ATA</code>:</strong></p>
  
  <pre><code>&gt;&gt;&gt; ================================ RESTART ================================
  &gt;&gt;&gt; 
  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'
  </code></pre>
  
  <p><strong>Results for <code>ATS0</code>:</strong></p>
  
  <pre><code>&gt;&gt;&gt; ================================ RESTART ================================
  &gt;&gt;&gt; 
  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'
  </code></pre>
  
  <p>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?</p>
  
  <p><em>Note that my modem is a <a href="http://www.dlink.com/uk/en/support/product/dwm-156-3-75-hsupa-usb-adapter" rel="nofollow">D-Link DWM-156</a> and I can send SMS or make a call successfully using it in Python.</em>
  Thanks in advance.</p>