如何使用Python中的AT命令拒绝或接受GSM调制解调器的来电?

如何使用Python中的AT命令拒绝或接受GSM调制解调器的来电?,python,gsm,at-command,pyserial,modem,Python,Gsm,At Command,Pyserial,Modem,我编写了下面的Python程序来等待传入呼叫并接受或拒绝它们。根据文档和文档,接受来电的适当AT命令是ATA或ATS0或ATS0。另外,拒绝来电的适当命令是ATH或AT H 我尝试了上面所有的命令,但是来电既没有应答也没有拒绝 我的Python程序: import time import serial phone = serial.Serial("COM10", 115200, timeout=5) try: time.sleep(1) while(1):

我编写了下面的Python程序来等待传入呼叫并接受或拒绝它们。根据文档和文档,接受来电的适当AT命令是
ATA
ATS0
ATS0
。另外,拒绝来电的适当命令是
ATH
AT H

我尝试了上面所有的命令,但是来电既没有应答也没有拒绝

我的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()
>>> ================================ 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'
>>> ================================ 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'
>>> ================================ 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'
>>> ================================ 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'
H时
的结果

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()
>>> ================================ 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'
>>> ================================ 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'
>>> ================================ 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'
>>> ================================ 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'
ATH的结果:

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()
>>> ================================ 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'
>>> ================================ 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'
>>> ================================ 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'
>>> ================================ 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'
ATA的结果:

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()
>>> ================================ 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'
>>> ================================ 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'
>>> ================================ 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'
>>> ================================ 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'
ATS0的结果:

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()
>>> ================================ 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'
>>> ================================ 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'
>>> ================================ 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'
>>> ================================ 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命令是什么,它都会继续鸣响。我的程序怎么了

请注意,我的调制解调器是一个,我可以在Python中使用它成功地发送SMS或拨打电话。
提前感谢。

在每个
AT
命令的末尾添加一个CR以使其成为有效的
AT
命令

我们不能直接拒绝来电。要拒绝来电,我们应该配置语音挂断控制命令

AT+CVHU(语音挂断命令)


ATH命令取决于AT+CVHU。

您有什么类型的GSM模块?@KhalilAmmour-它是a。然后您应该参考它的手册了解正确的AT命令!。。。让我检查一下out@KhalilAmmour-每个调制解调器类型的AT命令是否不同?我认为这些是所有GSM调制解调器的标准配置。我错了吗?不确定,但是你,你自己,为我们提供了不同的命令,不是吗?
phone = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=1)

try:
    time.sleep(1)

    while(1):
        x = phone.readline()
        print(x)
        if (x == b'RING\r\n'):
            phone.write('ATH'+'\r\n') 
            time.sleep(2)

finally:
    phone.close()