我正在使用以下代码连接到手机以发送 SMS 消息:
import serial
import time
phone = serial.Serial()
phone.baudrate = 38400
phone.bytesize = 8
phone.stopbits = 1
phone.xonxoff = 0
phone.rtscts = 0
phone.timeout = 0
phone.port = 3 #try different ports here, if this doesn't work.
phone.parity=serial.PARITY_NONE
phone.open()
print phone.portstr
recipient = "+929409778"
message = "We did it!"
print ("I did come after it")
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")
print (message)
time.sleep(0.5)
phone.write(bytes([26]))
time.sleep(0.5)
phone.readall()
finally:
phone.close()
我可以连接手机,但无法发送消息。它没有给我一个错误,所以我不确定从哪里开始调试。
我的代码有什么问题我没有看到吗?