首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GSM发送文本失败

GSM发送文本失败
EN

Stack Overflow用户
提问于 2016-11-28 13:14:11
回答 1查看 491关注 0票数 0

我正在尝试使用带有Raspberry Pi 3的- GSM屏蔽发送文本。我正在使用GSM附带的示例python代码尝试发送文本,并收到以下错误:

代码语言:javascript
复制
^CTraceback (most recent call last):
  File "./sendSMS.py", line 96, in <module>
    res = sendSMS(destinationNumber, "129", message)#domestic format numbers
  File "/home/wvandiver/gsm/RPI_examples/a-gsm-RPI-examples-py-library-based-v1_                                                                                        2/agsm_SMS_Lib.py", line 36, in sendSMS
    res = recUARTdata(">","ERROR",12)
  File "/home/wvandiver/gsm/RPI_examples/a-gsm-RPI-examples-py-library-based-v1_                                                                                        2/agsm_Serial_Lib.py", line 88, in recUARTdata
    dt = agsm.read(tm)
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 447, in re                                                                                        ad
    ready,_,_ = select.select([self.fd],[],[], self._timeout)

我认为这个问题与/usr/lib/python2.7/dist-packages/serial/serialposix.py.中第444行的"read = bytearray()“有关由于某些原因,"read“在调用bytearray()后打印时不返回值。

代码语言:javascript
复制
# select based implementation, proved to work on many systems
def read(self, size=1):
    """Read size bytes from the serial port. If a timeout is set it may
       return less characters as requested. With no timeout it will block
       until the requested number of bytes is read."""
    if not self._isOpen: raise portNotOpenError
    read = bytearray()
    print "Loosing it at bytearray: ",read  #read is an empty string
    while len(read) < size:
        ready,_,_ = select.select([self.fd],[],[], self._timeout)
        # If select was used with a timeout, and the timeout occurs, it
        # returns with empty lists -> thus abort read operation.
        # For timeout == 0 (non-blocking operation) also abort when there
        # is nothing to read.
        if not ready:
            break   # timeout
        buf = os.read(self.fd, size-len(read))
        # read should always return some data as select reported it was
        # ready to read when we get to this point.
        if not buf:
            # Disconnected devices, at least on Linux, show the
            # behavior that they are always ready to read immediately
            # but reading returns nothing.
            raise SerialException('device reports readiness to read but returned no data (device disconnected?)')
        read.extend(buf)
    return bytes(read)

下面是我用来发送文本消息的python代码的副本。

代码语言:javascript
复制
############################################################################################################################################
#a-gsm-send-SMS.py v1.01/13 June 2016 - a-gsm 2.064 send SMS utility / demo
#COPYRIGHT (c) 2016 Dragos Iosub / R&D Software Solutions srl
#
#You are legaly entitled to use this SOFTWARE ONLY IN CONJUNCTION WITH a-gsm DEVICES USAGE. Modifications, derivates and redistribution
#of this software must include unmodified this COPYRIGHT NOTICE. You can redistribute this SOFTWARE and/or modify it under the terms
#of this COPYRIGHT NOTICE. Any other usage may be permited only after written notice of Dragos Iosub / R&D Software Solutions srl.
#
#This SOFTWARE is distributed is provide "AS IS" in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
#warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
#Dragos Iosub, Bucharest 2016.
#http://itbrainpower.net
############################################################################################################################################
#HEALTH AND SAFETY WARNING!!!!!!!!!!!!!!!!!!!!
#High power audio (around 700mW RMS)! You can damage your years! Use it with care when headset is connected.
#We recomend to use AT+CLVL=20 (as maximum value), audio setup command in order to limit the output power.
#
# WARNING: WIRING the a-gsm-gsm board with u-controllers/boards(RPi) must be made with boards UNPOWERED!!
#
# LEGAL DISCLAIMER:
# Incorrect or faulty wiring and/or connection can damage your RPi and/or your a-gsm board!
# Following directives are provided "AS IS" in the hope that it will be useful, but WITHOUT ANY WARRANTY!
# Do the wiring on your own risk!
#
# References:
# http://itbrainpower.net/a-gsm/images/RaspberyPI_a-gsm_shield-wiring.png
# http://itbrainpower.net/a-gsm/downloadables/a-gsm_kickstart_v_0-90.pdf
# http://itbrainpower.net/a-gsm/gsm-shield-Arduino-RaspberryPI-features-code-examples.php
# http://itbrainpower.net/a-gsm/gsm-shield-Arduino-RaspberryPI-projects.php
############################################################################################################################################
# this utility must be runned as root (just use: sudo python yourPythonFileName.py)

message="Hi!\r\nThis message has been sent from the a-gsm v2.064 shield connected with my RPi board."
destinationNumber="1234567890"  #usually phone number with International prefix eg. +40 for Romania - in some networks you must use domestic numbers

usePoweringControl = 1  #change it to 0 if you do not want to control powerUP/powerDown the a-gsm board. In this case, please be sure the a-gsm board is powered UP(..see a-gsm_kickstart_v_x-yz.pdf) before run this utility

#Do not change under following line! Insteed make one copy of the file and play with!
#Hint: if you make changes of the code, before you run it run clear utility (erase the Python compiled *.pyc files)...
        ###erase .pyc files by         `find . -name '*.pyc' -delete`
############################################################################################################################################

import os
import serial
from time import sleep, time
from string import replace

from globalParVar import *
from agsm2_064_hw_control import *
from agsm_Serial_Lib import *
from agsm_Basic_Lib import *
from agsm_SMS_Lib import *

print "Light example - just send a SMS to a destination number"
sleep(1)

if not os.getuid() == 0:
    print("please use root privileges! try: \"sudo python yourPythonFileName.py\"")
    exit(0)

if destinationNumber=="":
    print("No destination number has been set for your SMS!")
    print("Edit the file and set the destinationNumber in line 35\r\n")
    exit(0)

# set SERIAL/USB communication section start
# bellow chose value bw [SER] Serial /dev/ttyAMA0 or [USB] /dev/ttyUSB0
# if module USB port maps to other port as /dev/ttyUSB1, just edit the moduleName_Serial_lib.py...
serialCommunicationVia = SERIALCON      # OVERRIDE the default value loaded from globalParVar.py. here I use via SERIAL communication
setSerialCom(serialCommunicationVia)    # set the current communication option
startSerialCom()                        # open serial communication bw. RPi and a-gsm shield
# set SERIAL/USB communication section end

# set HARDWARE CONTROL setup & POWER ON section start
if usePoweringControl==1:
    hwControlSetup()                    # setup the RPi I/O ports

sleep(2)#some delay...

if usePoweringControl==1:
    poweron()

sleep(1)
# set HARDWARE CONTROL setup & POWER ON section end

# set MODEM STARTUP SETUP section start
setupMODEM()
# set MODEM STARTUP SETUP section end


# MAIN PROGRAM section start
print "try to send a SMS...."

#check AT command pdf for proper 129/145 parameter/number format usage
res = sendSMS(destinationNumber, "129", message)#domestic format numbers
#res = sendSMS(destinationNumber, "145", message)#international format numbers
if res==0:
        print "SMS has been sent with succes"
# MAIN PROGRAM section end

# stop SERIAL COMMUNICATION section start
stopSerialCom()                             # close modem communication
# stop SERIAL COMMUNICATION section end

# HARDWARE CONTROL release & POWER OFF section start
if usePoweringControl==1:
    poweroff()                              #shutdown modem

if usePoweringControl==1:
    hwControlRelease()                      # free GPIO
# HARDWARE CONTROL release & POWER OFF section end


print("\r\n\r\nThat's all folks!\r\n")

请帮助我理解为什么bytearray()返回空字符串。

EN

回答 1

Stack Overflow用户

发布于 2016-11-30 15:31:13

这种混乱在2014年12月/2015年1月的a-gsm文档(演示文档的v1.03)中得到了解决。请始终查看最新版本的itbrainpower.net gsm/3G/4G调制解调器/屏蔽文档:

http://itbrainpower.net/downloads

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40837571

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档