Reputation: 1
Connecting to Android Phone via Putty and sending at+cimi command shows my IMSI number. (XX[..]XX are numeric values)
at+cimi
XXXXXXXXXXXXXXXOK
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?
Upvotes: 0
Views: 563
Reputation: 1
If anyone meets this problem, I solved it by adding spaces between "at" and "cimi".
Before:
s.write(b'at+cimi\r')
After:
s.write(b'at + cimi\r')
I don't know why, but it works. Checked on another phone, PC it works with both versions.
Upvotes: 0
Reputation: 3496
Just a thought: are you sure you need software flow control to be active? If you use XON-XOFF there are some specific byte values that are used to control the communication. That might be interfering with your communication if you're unlucky enough.
And a second thought: some AT commands take longer than 1 second, to be sure you are not giving up before getting an answer you'd be better off increasing the timeout to 5-10 seconds.
Upvotes: 0
Reputation: 111
Try to add a timeout before s.readlines()
ser.timeout=1.0
In fact, I don't understand why it worked with cgpaddr on your side. Without timeout, readlines never returns on my side.
Here is the comments from pyserial doc,
Be careful when using readline(). Do specify a timeout when opening the serial port otherwise it could block forever if no newline character is received. Also note that readlines() only works with a timeout. readlines() depends on having a timeout and interprets that as EOF (end of file). It raises an exception if the port is not opened correctly.
Upvotes: 1