'Sends an SMS to _recipient_ containing _text_. Some networks
will automatically chunk long messages into multiple parts,
and reassembled them upon delivery, but some will silently
drop them. At the moment, pyGSM does nothing to avoid this,
so try to keep _text_ under 160 characters.'

def send_sms(self, recipient, text):

    old_mode = None
    try:
        try:
            try:
                text = str(text)
            except UnicodeEncodeError:
                csmp = self.modem.query('AT+CSMP?', '+CSMP:')
                if (csmp is not None):
                    old_mode = csmp.split(',')
                    mode = old_mode[:]
                    mode[3] = '8'
                    self.modem.command('AT+CSCS="HEX"')
                    self.modem.command(('AT+CSMP=%s' % ','.join(mode)))
                    text = text.encode('utf-16').encode('hex')
            result = self.modem.command(('AT+CMGS="%s"' % recipient), read_timeout=1)
        except errors.GsmReadTimeoutError as err:
            if (err.pending_data[0] == '>'):
                self.modem.command(text, write_term=chr(26))
                return True
            else:
                raise
    except Exception as err:
        traceback.print_exc(err)
        self.modem.break_out_of_prompt()
        return None
    finally:
        if (old_mode is not None):
            self.modem.command(('AT+CSMP=%s' % ','.join(old_mode)))
            self.modem.command('AT+CSCS="GSM"')
