2

你好!连接到 gsm 模块时出现错误

这是我从rhydolabz得到的代码

import serial
import RPi.GPIO as GPIO     
import os, time

GPIO.setmode(GPIO.BOARD)   

# Enable Serial Communication
port = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=1)

# Transmitting AT Commands to the Modem
# '\r\n' indicates the Enter key

port.write('AT'+'\r\n')
rcv = port.read(10)
print rcv
time.sleep(1)

port.write('ATE0'+'\r\n')      # Disable the Echo
rcv = port.read(10)
print rcv
time.sleep(1)

port.write('AT+CMGF=1'+'\r\n')  # Select Message format as Text mode
rcv = port.read(10)
print rcv
time.sleep(1)

port.write('AT+CNMI=2,1,0,0,0'+'\r\n')   # New SMS Message Indications
rcv = port.read(10)
print rcv
time.sleep(1)

# Sending a message to a particular Number

port.write('AT+CMGS="+6xxxxxxxxx68"'+'\r\n')
rcv = port.read(10)
print rcv
time.sleep(1)

port.write('Hello User'+'\r\n')  # Message
rcv = port.read(10)
print rcv

port.write("\x1A") # Enable to send SMS
for i in range(10):
    rcv = port.read(10)
    print rcv

以下是错误:

OSError: [Errno 11] Resource temporarily unavailable

raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected?)

raise SerialException('write failed: %s' % (v,))
serial.serialutil.SerialException: write failed: [Errno 5] Input/output error

有时它发送

Hello User
Login incorrect
raspberrypi login:

有时

>
>
> 
(100+ more '>')
Hello User

但几乎总是无法连接并给出错误 11

你也有这种经历吗?在我继续发送消息之前,有没有办法可以等待 gsm 连接?

4

1 回答 1

2

您是否断开了 uart 与内部蓝牙和内核控制台的连接?

如果不这样做,您将无法访问设备。您需要禁用使用它的服务:

sudo systemctl disable hciuart

还禁用该 UART 上的内核控制台,从而消除

console=serial0,115200

从内核命令行(/boot/cmdline.txt)。你需要在设备树上启用两个覆盖(/boot/config.txt)也许这可以帮助你:

dtoverlay=pi3-disable-bt 
dtoverlay=pi3-miniuart-bt

rasberrypi.org 的完整解决方案:https ://www.raspberrypi.org/documentation/configuration/uart.md

于 2018-09-26T10:56:28.713 回答