Example #1
0
def xlBalance(ttyUsbx):
    try:
        p = "/dev/" + ttyUsbx
        num = "*123#"
        enc = gsmpdu.encode(num)
        cmd = 'AT+CUSD=1,"' + enc + '",15\r'
        modem = serial.Serial(port=p,
                              baudrate=115200,
                              timeout=5,
                              rtscts=0,
                              xonxoff=0)
        modem.write("AT+CUSD=2\r")
        modem.write(cmd)
        rspn = modem.read(1024)
        pattern = r'"([A-Za-z0-9_]*)"'
        texts = re.findall(pattern, rspn)
        dec = gsmpdu.decode(texts[1])
        print "dec"
        print dec
        balMatcher = re.compile("Pulsa (\d+)")
        balance = balMatcher.findall(dec)
        return balance[0]
        modem.close()
    except:
        #print "!!! XL Balance error !!!"
        modem.close()
        return "None"
Example #2
0
def indosatBalance(ttyUsbx):
    try:
        p = "/dev/" + ttyUsbx
        num = "*555#"
        enc = gsmpdu.encode(num)
        cmd = 'AT+CUSD=1,"' + enc + '",15\r'
        modem = serial.Serial(port=p,
                              baudrate=115200,
                              timeout=5,
                              rtscts=0,
                              xonxoff=0)
        modem.write("AT+CUSD=2\r")
        modem.write(cmd)
        rspn = modem.read(1024)
        pattern = r'"([A-Za-z0-9_]*)"'
        texts = re.findall(pattern, rspn)
        dec = gsmpdu.decode(texts[1])
        balPattern = r'Rp.([0-9_]*).'
        balance = re.findall(balPattern, dec)
        return balance[0]
        modem.close()
    except:
        #print "!!! INDOSAT Balance error !!!"
        modem.close()
        return "None"
Example #3
0
    def send_ussd(self,
                  ussd=None,
                  pdu=None,
                  write_term="\r",
                  raise_errors=True):
        """'
        A response looks like this:
        +CUSD: 0,"D9775D0E0A8FC7EFBA9B0E1287D961F7B80C4ACF4130170
        C063A22872E10F50D0755E1A07B9A8E061D914319C8040A8BDFF63288FE26
        87F32013A8EC56BFF32074986D06C1E5E97119F47683826939BDCC068DC36
        CF61C444FB3D920E7FBED06D1D1E939685A7793C379",15      
        """
        if pdu is None:
            if ussd:
                pdu = gsmpdu.encode(ussd)
            else:
                raise

        try:
            # run USSD code; the '1' indicates that we
            # want the result presented to us cast as string
            with self._modem_lock:
                self._write("AT+CUSD=1,\"%s\",15%s" % (str(pdu), write_term))
        except errors.GsmError, err:
            if not raise_errors:
                return None
            else:
                raise (err)
Example #4
0
 def send_ussd(self, ussd=None, pdu=None, write_term="\r", 
               raise_errors=True):
     
     """'
     A response looks like this:
     +CUSD: 0,"D9775D0E0A8FC7EFBA9B0E1287D961F7B80C4ACF4130170
     C063A22872E10F50D0755E1A07B9A8E061D914319C8040A8BDFF63288FE26
     87F32013A8EC56BFF32074986D06C1E5E97119F47683826939BDCC068DC36
     CF61C444FB3D920E7FBED06D1D1E939685A7793C379",15      
     """
     if pdu is None:
         if ussd:
             pdu = gsmpdu.encode(ussd)
         else:
             raise
           
     try:
         # run USSD code; the '1' indicates that we
         # want the result presented to us cast as string
         with self._modem_lock:
             self._write("AT+CUSD=1,\"%s\",15%s" % (str(pdu), write_term))
     except errors.GsmError, err:
         if not raise_errors:
             return None
         else:
             raise(err)
Example #5
0
def indosatBalance(ttyUsbx):
    try:
        p = "/dev/"+ttyUsbx
        num = "*555#"
        enc = gsmpdu.encode(num)
        cmd = 'AT+CUSD=1,"' + enc + '",15\r'
        modem = serial.Serial(port=p,baudrate=115200,timeout=5,rtscts=0,xonxoff=0)
        modem.write("AT+CUSD=2\r")
        modem.write(cmd)
        rspn = modem.read(1024)
        pattern = r'"([A-Za-z0-9_]*)"'
        texts = re.findall(pattern,rspn)
        dec = gsmpdu.decode(texts[1])
        balPattern = r'Rp.([0-9_]*).'
        balance = re.findall(balPattern,dec)
        return balance[0]
        modem.close()
    except:
        #print "!!! INDOSAT Balance error !!!"
        modem.close()
        return "None"
Example #6
0
def xlBalance(ttyUsbx):
    try:
        p = "/dev/"+ttyUsbx
        num = "*123#"
        enc = gsmpdu.encode(num)
        cmd = 'AT+CUSD=1,"' + enc + '",15\r'
        modem = serial.Serial(port=p,baudrate=115200,timeout=5,rtscts=0,xonxoff=0)
        modem.write("AT+CUSD=2\r")
        modem.write(cmd)
        rspn = modem.read(1024)
        pattern = r'"([A-Za-z0-9_]*)"'
        texts = re.findall(pattern,rspn)
        dec = gsmpdu.decode(texts[1])
        print "dec"
        print dec
        balMatcher = re.compile("Pulsa (\d+)")
        balance = balMatcher.findall(dec)
        return balance[0]
        modem.close()
    except:
        #print "!!! XL Balance error !!!"
        modem.close()
        return "None"