Created
August 28, 2009 15:01
-
-
Save rgaudin/177018 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/pygsm/gsmmodem.py b/lib/pygsm/gsmmodem.py | |
index 1b89a07..5b9c2c8 100644 | |
--- a/lib/pygsm/gsmmodem.py | |
+++ b/lib/pygsm/gsmmodem.py | |
@@ -850,6 +850,45 @@ class GsmModem(object): | |
# remove the message that has been waiting | |
# longest from the queue, and return it | |
return self.incoming_queue.pop(0) | |
+ | |
+ def ussd(self, cmd, read_term=None, read_timeout=None, write_term="\r", raise_errors=True): | |
+ """Sends the USSD command to the carrier, and returns the | |
+ answer string or None.""" | |
+ | |
+ res = None | |
+ | |
+ # Lock the modem so we're not interupted | |
+ with self.modem_lock: | |
+ | |
+ self._write("ATD" + cmd.__str__() + write_term) | |
+ lines = self._wait( | |
+ read_term=read_term, | |
+ read_timeout=read_timeout) | |
+ | |
+ read_term="+CUSD" | |
+ read_timeout=None | |
+ buffer = [] | |
+ | |
+ while(True): | |
+ buf = self._read( | |
+ read_term=read_term, | |
+ read_timeout=read_timeout) | |
+ | |
+ buf = buf.strip() | |
+ buffer.append(buf) | |
+ | |
+ if read_term == None and buf.find(':') == 0: | |
+ try: | |
+ res = re.split('.*[\d+],"(.*)",[\d+]', buffer[1])[1] | |
+ break | |
+ except: | |
+ res = buffer | |
+ break | |
+ | |
+ if buf.startswith("+CUSD"): | |
+ read_term=None | |
+ | |
+ return res | |
if __name__ == "__main__": |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment