Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)

Connecting to Android Phone via Putty and sending at+cimi command shows my IMSI number. (XX[..]XX are numeric values)

at+cimi 

XXXXXXXXXXXXXXX

OK

With below python code (at command g+cgpaddr):

def open_serial(com_port):

    my_serial = serial.Serial(com_port, baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=1, rtscts=0)

    return my_serial

s = open_serial('COM35')

s.write(b'at+cgpaddr\r')

temp = s.readlines()

print(temp)

The output is:

[b'at+cgpaddr\r\r\n', b'+CGPADDR: 1,"XXX.XXXX.XXX.XXX"\r\n', b'\r\n', b'OK\r\n']

If I only change at+cgpaddr to at+cimi:

s = open_serial('COM35')

s.write(b'at+cimi\r')

temp = s.readlines()

print(temp)

The output is empty string:

[]

Is there a solution for that problem?

1 Answer

0 votes
by (25.1k points)

You need to set timeout before calling readlines().

Like this: ser.timeout=1.0

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...