Hey guys,
This issue is puzzling to me. I'm trying to read responses from my GSM Shield 2, but I have an issue where I get incomplete responses using ser.read() as opposed to screen. For example, pySerial doesn't return any OK responses:
In Python I'm using ser.read() at the end, for debugging purposes, so I should be getting byte for byte response, but the OK reponse is missing:
import serial
ser = serial.Serial(
port='/dev/tty.usbmodemFD111',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
)
str_modem_ready="Enter your AT commands (with CR & NL)..."
com_set_sms_mode="AT+CMGF=1".encode('utf-8')
modem_state=0
while(modem_state==0):
x = ser.read_until()
if str_modem_ready in x.decode('utf-8'):
modem_state=1
print("Modem ready")
ser.write(com_set_sms_mode)
while True:
print(ser.read())
Returns:
Modem ready
b'A'
b'T'
b'+'
b'C'
b'M'
b'G'
b'F'
b'='
b'1'
As opposed to screen, where I get the OK response:
Start Reset
End Reset
Enter your AT commands (with CR & NL)...
AT+CMGF=1%13%%13%%10%
OK%13%%10%
Strangely enough, when I send an SMS to the SIM, the responses from pySerial and screen are identical:
screen:
%13%%10%
+CMTI: "SM",12%13%%10%
Python:
b'%'
b'1'
b'3'
b'%'
b'%'
b'1'
b'0'
b'%'
b'\r'
b'\n'
b'+'
b'C'
b'M'
b'T'
b'I'
b':'
b' '
b'"'
b'S'
b'M'
b'"'
b','
b'1'
b'3'
b'%'
b'1'
b'3'
b'%'
b'%'
b'1'
b'0'
b'%'
b'\r'
b'\n'