2016-11-28 75 views
0

我正在嘗試使用帶有Raspberry Pi 3的gsm屏蔽發送文本。我正在使用帶有GSM隨附的示例python代碼嘗試發送文本,並且收到以下錯誤:GSM發送文本失敗

^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()後打印時不返回值。

# 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代碼的副本。

############################################################################################################################################ 
#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()返回一個空字符串。

回答

-2

這個問題在2014年12月/ 2015年1月的a-gsm文檔(介紹文檔的v1.03)中得到修復。 請經常檢查itbrainpower.net GSM的最後一個版本/ 3G/4G調制解調器/盾文件:

http://itbrainpower.net/downloads