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


Python GsmModem.write方法代码示例

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


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

示例1: run

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import write [as 别名]
  def run(self):
    logging.info("Modem thread running")
    global modem
    rxListenLength = 10
    init_count = 0
    
    while self.running and init_count > -1:
      try:
        init_count = init_count + 1
        modem = GsmModem(PORT, BAUDRATE, incomingCallCallbackFunc=handleIncomingCall)
        logging.info("Initializing modem, try {0}.".format(init_count))
        modem.connect(PIN)
        init_count = -1
      except TimeoutException as e:
        logging.critical("Failed to initialize the GSM module: {0}", e)
        modem.close()

    logging.info('Waiting for incoming calls...')
    while self.running:
      try:
        #waitForNetworkCoverage()
        self.signalStrength = modem.signalStrength
        self.networkName = modem.networkName
        serving_cell=self.CGED_REGEX.match(modem.write("AT+CGED=3")[0])
        if serving_cell:
          mcc=serving_cell.group(1)
          mnc=serving_cell.group(2)
          lac=serving_cell.group(3)
          ci=serving_cell.group(4)
          self.cellInfo="{0}/{1}/{2}/{3}".format(mcc, mnc, lac, ci)

        # Comms are handled elsewhere so we could eventually just sleep, waiting
        #time.sleep(rxListenLength)
        modem.rxThread.join(rxListenLength) 
      except (InterruptedException, PinRequiredError, IncorrectPinError, TimeoutException):
        logging.error("rxThread died: {0}".format(sys.exc_info()[0]))

    modem.close()
    logging.info("Modem closed.")
开发者ID:ChroustJan,项目名称:balon,代码行数:41,代码来源:monitor.py

示例2: listen

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import write [as 别名]
def listen():
	global gsm
	jeedom_socket.open()
	logging.debug("Start listening...")
	try:
		logging.debug("Connecting to GSM Modem...")
		gsm = GsmModem(_device, int(_serial_rate), smsReceivedCallbackFunc=handleSms)
		if _text_mode == 'yes' : 
			logging.debug("Text mode true")
			gsm.smsTextMode = True 
		else :
			logging.debug("Text mode false")
			gsm.smsTextMode = False 
		if _pin != 'None':
			logging.debug("Enter pin code : "+_pin)
			gsm.connect(_pin)
		else :
			gsm.connect()
		if _smsc != 'None' :
			logging.debug("Configure smsc : "+_smsc)
			gsm.write('AT+CSCA="{0}"'.format(_smsc))
		logging.debug("Waiting for network...")
		gsm.waitForNetworkCoverage()
		logging.debug("Ok")
		try:
			jeedom_com.send_change_immediate({'number' : 'network_name', 'message' : str(gsm.networkName) });
		except Exception, e:
			if str(e).find('object has no attribute') <> -1:
				pass
			logging.error("Exception: %s" % str(e))

		try:
			gsm.write('AT+CPMS="ME","ME","ME"')
			gsm.write('AT+CMGD=1,4')
		except Exception, e:
			if str(e).find('object has no attribute') <> -1:
				pass
			logging.error("Exception: %s" % str(e))
开发者ID:jeedom,项目名称:plugin-sms,代码行数:40,代码来源:smsd.py

示例3: main

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import write [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

示例4: run

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import write [as 别名]
  def run(self):
    # Initialize the GPIO interface
    #exportpins()
    #writepins('1')
    
    logging.info("Modem thread running.")

    global modem
    global ppp_requested
    global sms_queue
    global beat
    global modem_failure

    rxListenLength = 5
    init_count = 0
    
    while self.running:
      beat += 1
      while self.running and not ppp_requested and init_count > -1:
        if (init_count > 10):
          # Let's exit after 10 fails 
          self.running = False
          modem_failure = True
          return(1)
        try:
          init_count = init_count + 1
          modem = GsmModem(PORT, BAUDRATE, incomingCallCallbackFunc=handleIncomingCall, smsReceivedCallbackFunc=handleSms)
          logging.info("Initializing modem, try {0}.".format(init_count))
          modem.connect(PIN)
          modem.write('AT+CFUN=1') 
          init_count = -1
        except (OSError, TimeoutException,CommandError):
          # OSError means pppd is likely running
          logging.error("Failed to initialize the GSM module.")
          try:
            modem.close()
          except AttributeError:
            True 
          time.sleep(5)
          #self.modemPowerCycle()

      logging.info('Waiting for incoming calls...')
      while self.running and not ppp_requested and init_count < 0:
        try:
          #waitForNetworkCoverage()
          self.signalStrength = modem.signalStrength
          self.networkName = modem.networkName
          data['signalStrength'] = self.signalStrength
          data['networkName'] = self.networkName
          #modem.write("AT+CFUN=1")
          serving_cell=self.CGED_REGEX.match(modem.write("AT+CGED=3")[0])
          if serving_cell:
            mcc=serving_cell.group(1)
            mnc=serving_cell.group(2)
            lac=serving_cell.group(3)
            ci=serving_cell.group(4)
            self.cellInfo="{0}/{1}/{2}/{3}".format(mcc, mnc, lac, ci)
            data['cellInfo'] = self.cellInfo

          # Comms are handled elsewhere so we could eventually just sleep, waiting
          #time.sleep(rxListenLength)
          if (self.signalStrength > 5):
            sent_position = 0
            if sms_enabled: 
              while (len(sms_queue) > 0):
                text=sms_queue.pop()
                if (text == 'position') and sent_position:
                  logging.info('Not resending position in the same interval')
                elif (text == 'position'):
                  send_position_via_sms(default_destination)  
                  sent_position = 1
                else:
                  try:
                    modem.sendSms(default_destination, text, waitForDeliveryReport=False)
                  except (CommandError, TimeoutException):
                    sms_queue.append(text)
          else:
            logging.info('Waiting for better network coverage')

          modem.rxThread.join(rxListenLength) 
          
          if self.do_shutdown:
            logging.warn('Disabling radio RX/TX.')
            modem.write('AT+CFUN=0') 
            self.running = False
            modem.close()

        except (CommandError, InterruptedException, PinRequiredError, IncorrectPinError, TimeoutException):
          logging.error("rxThread died: {0}".format(sys.exc_info()[0]))
          modem.close()
          time.sleep(5)
          init_count = 0

      # If PPP was requested, now it's the time
      if self.running and ppp_requested and self.signalStrength > 5 and init_count < 0:
        try:
          self.signalStrength = 101
          logging.info('Launching PPP session.') 
          if sms_enabled:
            while (len(sms_queue) > 0):
#.........这里部分代码省略.........
开发者ID:ODZ-UJF-AV-CR,项目名称:balon,代码行数:103,代码来源:m_gsm.py


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