Hi,
I cant send at commands to my usb gsm modem huawei e220 with all serial or and usbserial examples. If i use the code below in pyton/sl4a ( i connect to usb2 gsm = "/dev/ttyUSB2")
i can send and receive data, can you masters please help me on geting this work in b4a?
Thz
I cant send at commands to my usb gsm modem huawei e220 with all serial or and usbserial examples. If i use the code below in pyton/sl4a ( i connect to usb2 gsm = "/dev/ttyUSB2")
i can send and receive data, can you masters please help me on geting this work in b4a?
Thz
B4X:
#-*-coding:utf8;-*-
#qpy:console
#qpy:2
import os
import sys
import serial
import time
print'ok'
import android
droid = android.Android()
os.system("su -c chmod 777 /dev/ttyUSB*")
gsm = "/dev/ttyUSB2"
tries = 5
def GetAllSMS():
retry = tries
while retry > 1:
try:
print "### PI ON ###"
ser = serial.Serial(gsm, 4800, timeout=1)
ser.flushInput()
ser.flushOutput()
ser.write('ATZ\r\n')
ser.read(100)
ff = ser.read(100)
print "1",ff
time.sleep(1)
ser.write('AT\r/n')
time.sleep(1)
ser.read(100)
print "2",ser.read(100)
ser.write('AT+CMGF=1\r\n')
time.sleep(1)
ser.read(100)
ser.write('AT+CMGL="ALL"\r\n')
ser.read(16)
data1 = ser.readlines()
print data1
ser.close()
if data1:
#print "4"
result = data1
#print "5", result
for index, i in enumerate(result):
if i[:5] == "+CMGL":
data = result[index]
index = index + 1
text = result[index]
data = data + ',' + text
data = data.replace('\r\n','')
data = data.replace('"','')
data = data.replace('+CMGL: ','')
return data
else:
return "No SMS"
except:
print "Serial Port Not available READ SMS"
print "Waiting 10 seconds"
retry = retry - 1
time.sleep(1)
while True:
result = GetAllSMS()
print result
droid.makeToast(result)
if result == 'No SMS':
print result
else:
print result
result = result.split(',')
print result
print ".."
if result:
#responce = delmessage(result[0])
command = result[6]
print command
print result[2]
command = command.split(':')
bb = "rrrrrr"
print bb
if command[0] == 'Stop':
print" ############# STOP ON #################"
sendSMS(command[0],result[2])
elif command[0]=="Celia":
sendSMS(command[0],result[2])
print " ############# STOP OFF #################"
elif command[0]=="Abre":
sendSMS(command[0],result[2])
print " ############# ABRE #################"
elif command[0]=="Fecha":
sendSMS(command[0],result[2])
print " ############# Fecha #################"
else:
print "Junk"