尝试在 Python 中使用 GSM 调制解调器拨打电话时收到“NO CARRIER”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30952079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 09:12:51  来源:igfitidea点击:

Receiving "NO CARRIER" error while tring to make a call using GSM modem in Python

pythonpython-3.xgsmat-commandmodem

提问by Abraham

I want to make a call using my GSM modem. So I wrote the below program:

我想使用我的 GSM 调制解调器拨打电话。所以我写了下面的程序:

import time
import serial

recipient = "+98xxxxxxxxxx"

phone = serial.Serial("COM10",  115200, timeout=5)
try:
    time.sleep(0.5)
    phone.write(b'ATZ\r')
    time.sleep(1)
    phone.write(b'ATD"'+recipient.encode() +b'"\r')
    while(1):
        print(phone.readline())
    time.sleep(0.5)
finally:
    phone.close()

But when I run it I receive this output:

但是当我运行它时,我收到了这个输出:

>>> ================================ RESTART ================================
>>> 
b'ATZ\r\r\n'
b'OK\r\n'
b'ATDxxxxxxxxxx\r\r\n'
b'NO CARRIER\r\n'

What does this "NO CARRIER" error means?

这个“NO CARRIER”错误是什么意思?

Note that I can send SMS successfully.

请注意,我可以成功发送短信。



This is the program that I use to send SMS:

这是我用来发送短信的程序:

import time
import serial

recipient = "+98xxxxxxxxxx"
message = "Test"

phone = serial.Serial("COM10",  115200, timeout=5)


try:
    time.sleep(0.5)
    phone.write(b'ATZ\r')
    time.sleep(0.5)
    phone.write(b'AT+CMGF=1\r')
    time.sleep(0.5)
    phone.write(b'AT+CMGS="' + recipient.encode() + b'"\r')
    time.sleep(0.5)
    phone.write(message.encode() + b"\r")
    time.sleep(0.5)
    phone.write(bytes([26]))
    time.sleep(0.5)
finally:
    phone.close()

采纳答案by Abraham

I found the origin of the error :

我找到了错误的根源:

The syntax is ATD+98xxxxxxxxxx;followed by terminating string. I was forgotten to put semicolon at the end after the number.

语法ATD+98xxxxxxxxxx;后跟终止字符串。我忘了在数字后面加分号。

So I replace

所以我替换

phone.write(b'ATD"'+recipient.encode() +b'"\r')

with

phone.write(b'ATD"'+recipient.encode() +b';"\r')

And now it works fine.

现在它工作正常。



Based on the brackets in thisdocuments, I thought that using ";" is optional. But it seems that I was wrong. enter image description here

基于文档中的括号,我认为使用“;” 是可选的。但似乎我错了。 在此处输入图片说明