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


Python GsmModem.connect方法代码示例

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


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

示例1: send_sms_at

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import connect [as 别名]
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,代码行数:37,代码来源:send_sms_at.py

示例2: text

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import connect [as 别名]
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,代码行数:31,代码来源:main.py

示例3: getAllText

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import connect [as 别名]
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,代码行数:27,代码来源:main.py

示例4: Modem

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import connect [as 别名]
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,代码行数:32,代码来源:modem.py

示例5: getUnreadText

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import connect [as 别名]
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,代码行数:27,代码来源:main.py

示例6: main

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import connect [as 别名]
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,代码行数:10,代码来源:sendData.py

示例7: main

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import connect [as 别名]
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,代码行数:12,代码来源:own_number_demo.py

示例8: main

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import connect [as 别名]
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,代码行数:12,代码来源:incoming_call_demo.py

示例9: main

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import connect [as 别名]
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,代码行数:14,代码来源:sms_handler_demo.py

示例10: ModemWorker

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import connect [as 别名]
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,代码行数:50,代码来源:worker.py

示例11: main

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import connect [as 别名]
def main():
    args = parseArgsPy26() if sys.version_info[0] == 2 and sys.version_info[1] < 7 else parseArgs()
    if args.port == None:
        sys.stderr.write('Error: No port specified. Please specify the port to which the GSM modem is connected using the -i argument.\n')
        sys.exit(1)
    modem = GsmModem(args.port, args.baud, AT_CNMI=args.CNMI)
    if args.debug:
        # enable dump on serial port
        logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
    
    print('Connecting to GSM modem on {0}...'.format(args.port))
    try:
        modem.connect(args.pin, waitingForModemToStartInSeconds=args.wait)
    except PinRequiredError:
        sys.stderr.write('Error: SIM card PIN required. Please specify a PIN with the -p argument.\n')
        sys.exit(1)
    except IncorrectPinError:
        sys.stderr.write('Error: Incorrect SIM card PIN entered.\n')
        sys.exit(1)
    print('Checking for network coverage...')
    try:
        modem.waitForNetworkCoverage(5)
    except TimeoutException:
        print('Network signal strength is not sufficient, please adjust modem position/antenna and try again.')
        modem.close()
        sys.exit(1)
    else:
        if args.message is None:
            print('\nPlease type your message and press enter to send it:')
            text = raw_input('> ')
        else:
            text = args.message
        if args.deliver:
            print ('\nSending SMS and waiting for delivery report...')
        else:
            print('\nSending SMS message...')
        try:
            sms = modem.sendSms(args.destination, text, waitForDeliveryReport=args.deliver)
        except TimeoutException:
            print('Failed to send message: the send operation timed out')
            modem.close()
            sys.exit(1)
        else:
            modem.close()
            if sms.report:
                print('Message sent{0}'.format(' and delivered OK.' if sms.status == SentSms.DELIVERED else ', but delivery failed.'))
            else:
                print('Message sent.')
开发者ID:tomchy,项目名称:python-gsmmodem,代码行数:50,代码来源:sendsms.py

示例12: main

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import connect [as 别名]
def main():
    if NUMBER == None or NUMBER == '00000':
        print('Error: Please change the NUMBER variable\'s value before running this example.')
        sys.exit(1)
    print('Initializing modem...')
    logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
    modem = GsmModem(PORT, BAUDRATE)
    modem.connect(PIN)
    print('Waiting for network coverage...')
    modem.waitForNetworkCoverage(30)
    print('Dialing number: {0}'.format(NUMBER))
    call = modem.dial(NUMBER, callStatusUpdateCallbackFunc=callStatusCallback)
    global waitForCallback
    while waitForCallback:
        time.sleep(0.1)
    print('Done')
开发者ID:0x90,项目名称:python-gsmmodem,代码行数:18,代码来源:dial_callback_demo.py

示例13: main

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import connect [as 别名]
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,代码行数:18,代码来源:ussd_demo.py

示例14: main

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import connect [as 别名]
def main():
    port = '/dev/ttyUSB0'
    baud = 460800
    deliver = False
    destination = "0711661919"
    message = "Testing_message \n new line \t tab \n n \n e \n l"
    modem = GsmModem(port, baud)
    # Uncomment the following line to see what the modem is doing:
    # logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)

    print('Connecting to GSM modem on {0}...'.format(port))
    try:
        modem.connect()
    except PinRequiredError:
        sys.stderr.write('Error: SIM card PIN required. Please specify a PIN. \n')
        sys.exit(1)
    except IncorrectPinError:
        sys.stderr.write('Error: Incorrect SIM card PIN entered.\n')
        sys.exit(1)
    print('Checking for network coverage...')
    try:
        modem.waitForNetworkCoverage(5)
    except TimeoutException:
        print('Network signal strength is not sufficient, please adjust modem position/antenna and try again.')
        modem.close()
        sys.exit(1)
    else:
        print('\nPlease type your message and press enter to send it:')
        text = message
        if deliver:
            print ('\nSending SMS and waiting for delivery report...')
        else:
            print('\nSending SMS message...')
        try:
            sms = modem.sendSms(destination, text, waitForDeliveryReport=deliver)
        except TimeoutException:
            print('Failed to send message: the send operation timed out')
            modem.close()
            sys.exit(1)
        else:
            modem.close()
            if sms.report:
                print('Message sent{0}'.format(
                    ' and delivered OK.' if sms.status == SentSms.DELIVERED else ', but delivery failed.'))
            else:
                print('Message sent.')
开发者ID:ckqqck,项目名称:fleet-management-system,代码行数:48,代码来源:sms.py

示例15: main

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import connect [as 别名]
def main():
    args = parseArgsPy26() if sys.version_info[0] == 2 and sys.version_info[1] < 7 else parseArgs()
    print ('args:',args)
    modem = GsmModem(args.port, args.baud)    
    
    print('Connecting to GSM modem on {0}...'.format(args.port))
    try:
        modem.connect(args.pin, waitingForModemToStartInSeconds=args.wait)
    except PinRequiredError:
        sys.stderr.write('Error: SIM card PIN required. Please specify a PIN with the -p argument.\n')
        sys.exit(1)
    except IncorrectPinError:
        sys.stderr.write('Error: Incorrect SIM card PIN entered.\n')
        sys.exit(1)

    if args.debug:
        # Print debug info
        print('\n== MODEM DEBUG INFORMATION ==\n')
        print('ATI', modem.write('ATI', parseError=False))
        print('AT+CGMI:', modem.write('AT+CGMI', parseError=False))
        print('AT+CGMM:', modem.write('AT+CGMM', parseError=False))
        print('AT+CGMR:', modem.write('AT+CGMR', parseError=False))
        print('AT+CFUN=?:', modem.write('AT+CFUN=?', parseError=False))
        print('AT+WIND=?:', modem.write('AT+WIND=?', parseError=False))
        print('AT+WIND?:', modem.write('AT+WIND?', parseError=False))
        print('AT+CPMS=?:', modem.write('AT+CPMS=?', parseError=False))
        print('AT+CNMI=?:', modem.write('AT+CNMI=?', parseError=False))
        print('AT+CVHU=?:', modem.write('AT+CVHU=?', parseError=False))
        print('AT+CSMP?:', modem.write('AT+CSMP?', parseError=False))
        print('AT+GCAP:', modem.write('AT+GCAP', parseError=False))
        print('AT+CPIN?', modem.write('AT+CPIN?', parseError=False))
        print('AT+CLAC:', modem.write('AT+CLAC', parseError=False))
        print()
    else:
        # Print basic info
        print('\n== MODEM INFORMATION ==\n')
        print('Manufacturer:', modem.manufacturer)
        print('Model:', modem.model)
        print('Revision:', modem.revision if modem.revision != None else 'N/A')
        print('\nIMEI:', modem.imei if modem.imei != None else 'N/A')
        print('IMSI:', modem.imsi if modem.imsi != None else 'N/A')
        print('\nNetwork:', modem.networkName)
        print('Signal strength:', modem.signalStrength)
        print()
开发者ID:PeteLawler,项目名称:python-gsmmodem,代码行数:46,代码来源:identify-modem.py


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