【问题标题】:Getting serial response data in python在python中获取串行响应数据
【发布时间】:2018-09-12 00:06:09
【问题描述】:

我一直在使用此代码在我的 Raspberry Pi 上使用 Python 发送短信。

How to Send/Receive SMS using AT commands?

import time
import serial

recipient = "+1234567890"
message = "Hello, World!"

phone = serial.Serial("/dev/ttyUSB3",  460800, 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()

脚本运行时没有错误但没有文本消息到达。我已经在 minicom shell 中直接运行 AT 命令,并且成功发送了短信。

当命令被发送到调制解调器时,是否有任何方式打印 python 脚本来筛选来自调制解调器的响应?例如,如果我发送 ATZ,最好能打印“OK”。

【问题讨论】:

    标签: python serial-port sms


    【解决方案1】:

    很抱歉,我在最初的搜索中错过了这个。

    Read response AT command with pySerial

    串行响应显示为:

    response =  ser.read(2)
    

    还有代码

    phone.write(bytes([26]))
    

    我能够从 IDLE 中发送 SMS,但它不会从命令提示符发送任何内容。为了解决这个问题,我不得不将其更改为

    phone.write('\x1A')
    

    【讨论】:

      猜你喜欢
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多