我寫了下面的Python程序來等待來電並接受或拒絕它們。基於this文檔和this文檔,接受來電的適當的AT命令是ATA
或ATS0
或ATS0<n>
。而且拒絕來電的適當命令是ATH
或AT H
。如何使用Python中的AT命令拒絕或接受來電到我的GSM調制解調器?
我嘗試了所有上述命令,但來電既沒有應答也沒有被拒絕!
我的Python程序:
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()
結果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'
結果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'
個
結果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'
結果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'
正如你在上面看到,GSM調制解調器,無論AT命令的,我發微博,繼續振盪。我的程序有什麼問題?
請注意,我的調制解調器是D-Link DWM-156,我可以在Python中使用它發送短信或撥打電話。 在此先感謝。
你有什麼類型的GSM模塊? –
@ KhalilAmmour-خليلعمور這是[D-Link DWM-156](http://www.dlink.com/uk/en/support/product/dwm-156-3-75-hsupa-usb-adapter)。 – Abraham
那麼你應該參考其正確的AT命令的手冊!...讓我看看 –