Skip to content

Commit

Permalink
Accept error messages like '+CME ERROR:58' without a space after ':'
Browse files Browse the repository at this point in the history
My A6 GSM modem returns such error codes. This caused the library to
hang, waiting for a response indefinitely.  After this change modem
initialization succeeds and it's possible to send SMS messages etc.

It could be also the cause of #24, the symptoms are very similar.
  • Loading branch information
ppetr committed Oct 28, 2017
1 parent 834c68b commit 3e87b1f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gsmmodem/serial_comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SerialComms(object):
# End-of-line read terminator
RX_EOL_SEQ = '\r\n'
# End-of-response terminator
RESPONSE_TERM = re.compile(r'^OK|ERROR|(\+CM[ES] ERROR: \d+)|(COMMAND NOT SUPPORT)$')
RESPONSE_TERM = re.compile(r'^OK|ERROR|(\+CM[ES] ERROR: ?\d+)|(COMMAND NOT SUPPORT)$')
# Default timeout for serial port reads (in seconds)
timeout = 1

Expand Down
2 changes: 2 additions & 0 deletions test/test_serial_comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ def test_write(self):
""" Tests basic writing operations """
tests = ((['OK\r\n'], ['OK']),
(['ERROR\r\n'], ['ERROR']),
(['+CMS ERROR: 58\r\n'], ['+CMS ERROR: 58']),
(['+CME ERROR:58\r\n'], ['+CME ERROR:58']),
(['first line\r\n', 'second line\r\n', 'OK\r\n'], ['first line', 'second line', 'OK']),
# Some Huawei modems issue this response instead of ERROR for unknown commands; ensure we detect it correctly
(['COMMAND NOT SUPPORT\r\n'], ['COMMAND NOT SUPPORT']))
Expand Down

0 comments on commit 3e87b1f

Please sign in to comment.