Nokia 3310 SMS Application, done:connecting to serial port(linux/win), done:reading some hex like \x00 . . ., problem:write/send command! noresponse

Wolfgang Strobl ws at mystrobl.de
Sat Sep 21 09:30:27 CEST 2002


ptbjrii at hotmail.com (Polerio Babao Jr.II):

>I tried almost three weeks writing or sending a command to the
>cell-phone but this gives me no response. I'm talking here about the
>nokia 3310 connected to my serial port. The command that I send is the
>AT command. From my pyserial I made an initialization like this
>ser=serial.Serial('/dev/ttyS1',19200) 
>ser.readline() 
>ser.write()
>ser.read()
>
>When I connect to the port for the first time I get the ser.read()
>output like this \x00\x0c I think. But that's two response is what I
>get on my first connect. After that when I envoke ser.read() again, I 
>get nothing.

Something like 

import serial
ser=serial.Serial(0,19200,timeout=3)
print ser.portstr
ser.write("ATZ\r")
print "got"
line=ser.read(10)
print line
ser.close()

worked on the first try on my w2k box, when connected to a Siemes S25
via COM1. I bet it will would with the Nokia, too, because "ATZ" is
almost universally understood. :-)

My wife had asked me to dump all her phonebook numbers from her handy
for backup purposes. Siemens only sold an somewhat expensive program
for the S25, which I didn't buy. A program that I've got with a newer
S45 unfortunately didn't even recognize the S25. 

The following qick&dirty snippet did the trick, and it works with both
the s25 and the s45.

# Strobl 19.9.2002  $Id: s25.py,v 1.3 2002/09/21 07:16:12 cvsroot Exp $
# read phonebooks from Siemens S25 or S45

import serial,re

def readuntilok(s):
    ol=[]
    while 1:
        c=s.read()
        if not c:
            break
        ol.append(c)
        ostring="".join(ol)
        if len(ol)>3 and ostring[-4:]=="OK\r\n":
            break
    return ostring

def cmd(s,cmd):
    s.write(cmd+"\r")
    r=readuntilok(s)
    r=r.split("\n")
    for i in range(len(r)):
        r[i]=r[i][:-1]
    return r

def showbook(ser,book):
    select= cmd(ser,'AT+CPBS='+book)
    if select[1]=="ERROR":
        print "Error in showbook"
        print
        return
    booksize=cmd(ser,"AT+CPBR=?")[1]
    print booksize
    siz=re.compile(r"\+CPBR: \((\d+)-(\d+)\)")
    von,bis= siz.match(booksize).groups()
    von=int(von)
    bis=int(bis)
    
    print "Phonebook",book
    for i in range(von,bis+1):
        buch=cmd(ser,"AT+CPBR=%d,%d"%(i,i))
        if buch[1]!="OK": print repr(buch[1])
    print

ser=serial.Serial(0,19200,timeout=3)
print ser.portstr
ser.write("ATZ\r")
print "sent"
line=ser.read(10)
print line

typ=cmd(ser,"AT+CGMI")[1]
print typ,
typ=cmd(ser,"AT+CGMM")[1]
print typ,
typ=cmd(ser,"AT+CGMR")[1]
print "Model",typ

print "IMSI",cmd(ser,"AT+CIMI")[1]
print "IMEI",cmd(ser,"AT+CGSN")[1]

uhrzeit=cmd(ser,"AT+CCLK?")
print "Uhrzeit",uhrzeit[1]

booksstring= cmd(ser,"AT+CPBS=?")[1]
print "Phonebooks",booksstring

for b in re.compile(r'"\w\w"').findall(booksstring):
    print "----Now reading book",b
    showbook(ser,b[1:-1])

print cmd(ser,"ATZ")
print  cmd(ser,'AT+CPBS=SM')
print "writable",cmd(ser,"AT+CPBW=?")

print "Done"
ser.close()


------------------------

>pythonw -u s25.py
COM1
sent
ATZ

OK

SIEMENS S45 Model 23
IMSI xxxxxxxxxxxxxxxxxx
IMEI xxxxxxxxxxxxxxxxxx
Uhrzeit +CCLK: "02/09/21,09:11:57"
Phonebooks +CPBS: ("FD","SM","ON","ME","LD","MC","RC")
----Now reading book "FD"
+CPBR: (1-10),20,16
Phonebook FD

----Now reading book "SM"
+CPBR: (1-125),20,16
Phonebook SM
'+CPBR: 1,"xxxxxxxxxxxxxx",129,"xxxxx!"'
'+CPBR: 2,"xxxxxxxxxxxxxxxx",145,"xxxxx"'

etc.

['ATZ\r', 'OK', '']
['AT+CPBS=SM\r', 'OK', '']
writable ['AT+CPBW=?\r', '+CPBW: (1-125),20,(128-255),16', '', 'OK',
'']
Done

>Exit code: 0

-- 
Wir danken für die Beachtung aller Sicherheitsbestimmungen



More information about the Python-list mailing list