当前位置: 首页>>代码示例>>Python>>正文


Python modem.GsmModem类代码示例

本文整理汇总了Python中gsmmodem.modem.GsmModem的典型用法代码示例。如果您正苦于以下问题:Python GsmModem类的具体用法?Python GsmModem怎么用?Python GsmModem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GsmModem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main():
    print('Initializing modem...')
    #logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
    modem = GsmModem(PORT, BAUDRATE, incomingCallCallbackFunc=handleIncomingCall)
    modem.connect(PIN)
    print('Waiting for incoming calls...')
    try:
        modem.rxThread.join(2**31) # Specify a (huge) timeout so that it essentially blocks indefinitely, but still receives CTRL+C interrupt signal
    finally:
        modem.close()
开发者ID:tomchy,项目名称:python-gsmmodem,代码行数:10,代码来源:incoming_call_demo.py

示例2: main

def main():
    print('Initializing modem...')
    # Uncomment the following line to see what the modem is doing:
    logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
    modem = GsmModem(PORT, BAUDRATE)
    modem.connect(PIN)

    number = modem.ownNumber
    print("The SIM card phone number is:")
    print(number)
开发者ID:tomchy,项目名称:python-gsmmodem,代码行数:10,代码来源:own_number_demo.py

示例3: send_sms_at

def send_sms_at(data, action_config):
  """Send SMS via local modem with AT commands

  Meact configuration:
  action_config = {
    "recipient": ["your-number", "your-number2'],
    "port": "/dev/ttyUSB1",
    "speed": 19200,
    "enabled": 1
  }
  """
  if not action_config.get('enabled'):
    sys.exit(1)

  LOG.info('Sending SMS via AT')

  modem = GsmModem(action_config['port'], action_config['speed'])

  while True:
    try:
      modem.connect()
      modem.waitForNetworkCoverage()
    except TimeoutException:
      pass
    else:
      break

  for rcpt in action_config['recipient']:
    try:
      sms = modem.sendSms(rcpt, data['message'])
    except TimeoutException:
      LOG.warning('Got exception in send_sms_at')
      sys.exit(2)
  modem.close()
  sys.exit(0)
开发者ID:bkupidura,项目名称:meact,代码行数:35,代码来源:send_sms_at.py

示例4: text

def text(number, message, key):
    if key.strip() == '9703BB8D5A':
        print "Creating modem instance"
        modem = GsmModem('/dev/ttyUSB0', 9600)

        try:
            print "Connecting modem"
            modem.connect()
        except PinRequiredError:
            print "Pin required"

        try:
            print "Waiting for Network coverage info"
            modem.waitForNetworkCoverage(5)
        except TimeoutException:
            print "Signal strength not strong enough"
            return "No signal"
        else:
            try:
                print "Sending %s to %s" % (message, number)
                sms = modem.sendSms(number, message)
            except TimeoutException:
                print "Failed to send message"
                return 'Error encountered'
            print "Closing modem"
            modem.close()
            return True
    else:
        return 'Key is not correct'
开发者ID:akimtke,项目名称:arke,代码行数:29,代码来源:main.py

示例5: ModemWorker

class ModemWorker(Actor):

    def __init__(self, dev, serial_info, serial_manager):
        self.serial_manager = serial_manager
        self.dev = dev
        self.imsi = None
        self.serial_info = serial_info
        self.modem_info = None
        self.sim_config = None

        self.modem = None
        self.concat_pool = ConcatPool(self)
        self.concat_pool.start()
        self.state = 'initialized'
        super(ModemWorker, self).__init__('Modem %s' % dev)

    @property
    def state(self):
        return self._state

    @state.setter
    def state(self, new_state):
        if hasattr(self, '_state') and new_state != self._state:
            logger.info('STATE %s -> %s', self._state, new_state)
        self._state = new_state

    def run(self):
        step = self.connect
        try:
            while True:
                step = step()
                if step is None:
                    break
        finally:
            self._try_modem_close()

    # ~~~~~ STATES ~~~~~

    def connect(self):
        self.state = 'connecting'
        try:
            self.modem = GsmModem(self.dev, 19200)
            self.modem.connect()
        except TimeoutException:
            self.state = 'no modem detected'
        except Exception, e:
            self.state = 'error %s' % e
        else:
开发者ID:paolo-losi,项目名称:msgbox,代码行数:48,代码来源:worker.py

示例6: Modem

class Modem(threading.Thread):
    def __init__(self, smsq, device, *a,**kw):
        self.modem = GsmModem(device,9600,dsrdtr=True,rtscts=True)
        self.smsq = smsq

        return super(Modem,self).__init__(*a,**kw)

    def run(self):
        while True:
            try:
                self.modem.connect()
            except (TimeoutException,IOError) as e:
                self.modem.close()
                exc_type, exc_value, exc_traceback = sys.exc_info()
                logging.debug(traceback.format_tb(exc_traceback))
                time.sleep(10)
                continue
            try:        
                while True:
                    phone,text = self.smsq.get()
                    logging.debug(u'modem to {} text: {}'.format(phone,text))
                    sms = self.modem.sendSms(phone,text)
                    self.smsq.task_done()
                    time.sleep(10)
            except Exception as e:
                self.modem.close()
                exc_type, exc_value, exc_traceback = sys.exc_info()
                logging.error(type(e))
                logging.error(e.message)
                logging.debug(traceback.format_tb(exc_traceback))
开发者ID:alex-eri,项目名称:smsd,代码行数:30,代码来源:modem.py

示例7: connect

 def connect(self):
     self.state = 'connecting'
     try:
         self.modem = GsmModem(self.dev, 19200)
         self.modem.connect()
     except TimeoutException:
         self.state = 'no modem detected'
     except Exception, e:
         self.state = 'error %s' % e
开发者ID:paolo-losi,项目名称:msgbox,代码行数:9,代码来源:worker.py

示例8: autodetect_modem

def autodetect_modem(pin=None, check_fn=None, modem_options={'baudrate': 9600}):
    """ Autodetect a suitable cellular modem connected to the system.

    :param pin: Security PIN to unlock the SIM.
    :param check_cn: Callable that should take a single ``modem`` argument
        and return True if the modem instance is suitable.
    :param modem_options: Structure to pass as keyword arguments to
        ``GsmModem`` initialisation.
    :type modem_options: dict-like
    :returns: Connected modem instance
    :rtype: :class:`gsmmodem.modem.GsmModem`

    This method will iterate through all potential serial ports on the system
    and attempt to ``connect()`` to each of them in turn.  The first serial
    port that connects successfully, and passes the ``check_fn(modem)`` call
    (if ``check_fn`` is specified), will be returned.

    All other unsuccessful connections will be closed during the process.

    This method will return ``None`` if no modems could be detected.
    """
    ports = enumerate_serial()
    if not ports:
        log.error('No modem ports detected on system.')
        return

    modem = None

    for port in ports:
        modem = GsmModem(port, **modem_options)
        try:
            log.debug('Attempting to connect to modem at %s' % port)
            modem.connect(pin=pin)
            if not check_fn or check_fn and check_fn(modem):
                log.debug('Successfully detected modem at %s' % port)
                return modem
        except SerialException:
            log.warn('Serial communication problem for port %s' % port)
        except TimeoutException:
            log.warn('Timeout detected on port %s' % port)

        log.debug('Closing modem at %s' % port)
        modem.close()
开发者ID:davidjb,项目名称:telstra.mobile,代码行数:43,代码来源:modem.py

示例9: getUnreadText

def getUnreadText(key):
    if key.strip() == '9703BB8D5A':
        modem = GsmModem('/dev/ttyUSB0', 9600)

        try:
            print "Connecting mode"
            modem.connect()
        except:
            return "Error connecting"

        try:
            messages = modem.listStoredSms(status=Sms.STATUS_RECEIVED_UNREAD)
        except Exception as e:
            return str(e)

        modem.close()

        retString = ""
        print "Got %d messages" % len(messages)
        for message in messages:
            retString = retString + "%s : %s" % (message.number, message.text)

        return retString
    else:
        return "Incorrect key"
开发者ID:akimtke,项目名称:arke,代码行数:25,代码来源:main.py

示例10: getAllText

def getAllText(key):
    if key.strip() == '9703BB8D5A':
        modem = GsmModem('/dev/ttyUSB0', 9600)

        try:
            print "Connecting modem"
            modem.connect()
        except Exception as e:
            return str(e)

        try:
            messages = modem.listStoredSms()
        except Exception as e:
            return str(e)

        modem.close()

        retString = ""
        print "Got %d messages" % len(messages)
        for message in messages:
            retString = retString + "%s : %s" % (message.number, message.text) + "\n"

        return retString
    else:
        return "Incorrect key"
开发者ID:akimtke,项目名称:arke,代码行数:25,代码来源:main.py

示例11: main

def main(): 
	print("Iniciando modem...")
	logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
	modem = GsmModem(PORT, BAUDRATE)
	modem.smsTextMode = False 
	modem.connect(PIN)
	sms=text()
	modem.sendSms('649886178',sms )
开发者ID:Gynoid-M,项目名称:Oxypi-Project,代码行数:8,代码来源:sendData.py

示例12: main

def main():
    print('Initializing modem...')
    #logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
    modem = GsmModem(PORT, BAUDRATE)
    modem.connect(PIN)
    modem.waitForNetworkCoverage(10)
    print('Sending USSD string: {0}'.format(USSD_STRING))
    response = modem.sendUssd(USSD_STRING) # response type: gsmmodem.modem.Ussd
    print('USSD reply received: {0}'.format(response.message))
    if response.sessionActive:
        print('Closing USSD session.')
        # At this point, you could also reply to the USSD message by using response.reply()
        response.cancel()
    else:
        print('USSD session was ended by network.')
    modem.close()
开发者ID:0x90,项目名称:python-gsmmodem,代码行数:16,代码来源:ussd_demo.py

示例13: __init__

	def __init__(self, user):

		dispgsm._user=user
		self.logger = logging.getLogger(user.user_code+'.dispgsm')
		self.logger.info('Initializing GSM device %s',user.user_code)

		self._config = ConfigParser.ConfigParser()
                self._config.read('./config.cfg')

		self._msisdn = ast.literal_eval(self._config.get('GSM_CREDENTIALS',user.user_code))['msisdn']
                self._pin = ast.literal_eval(self._config.get('GSM_CREDENTIALS',user.user_code))['pin']
		self._port = ast.literal_eval(self._config.get('GSM_CREDENTIALS',user.user_code))['port']
		self._baudrate = ast.literal_eval(self._config.get('GSM_CREDENTIALS',user.user_code))['baudrate']
		self._modem = GsmModem(self._port, int(self._baudrate), incomingCallCallbackFunc=dispgsm.handleIncomingCall, smsReceivedCallbackFunc=dispgsm.handleSms, smsStatusReportCallback=dispgsm.handleSmsDeliveryReport)
开发者ID:albertobaselga,项目名称:e2eprobe,代码行数:14,代码来源:dispgsm.py

示例14: GSM

class GSM(object):
    def __init__(self, port, baudrate, pin=None):
        self.sms_callbacks = []
        self.port = port
        self.baudrate = baudrate
        self.pin = pin

    def run(self):
        self.modem = GsmModem(self.port, self.baudrate,
                              smsReceivedCallbackFunc=self.sms_callback)
        self.modem.smsTextMode = False
        self.modem.connect(self.pin)

    def sms_callback(self, sms):
        logger.info(sms_receive_log_template.format(sms.number,
                                                    sms.time, sms.text))
        for callback in self.sms_callbacks:
            tornado.ioloop.IOLoop.instance().add_callback(callback, sms)

    def add_sms_callback(self, callback):
        self.sms_callbacks.append(callback)

    def process_stored_sms(self, delete=False):
        self.modem.processStoredSms()
开发者ID:senghoo,项目名称:operator,代码行数:24,代码来源:gsm.py

示例15: main

def main():
    print('Initializing modem...')
    # Uncomment the following line to see what the modem is doing:
    logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
    modem = GsmModem(PORT, BAUDRATE, smsReceivedCallbackFunc=handleSms)
    modem.smsTextMode = False
    modem.connect(PIN)
    print('Waiting for SMS message...')
    try:
        modem.rxThread.join(2**31) # Specify a (huge) timeout so that it essentially blocks indefinitely, but still receives CTRL+C interrupt signal
    finally:
        modem.close();
开发者ID:tomchy,项目名称:python-gsmmodem,代码行数:12,代码来源:sms_handler_demo.py


注:本文中的gsmmodem.modem.GsmModem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。