當前位置: 首頁>>代碼示例>>Python>>正文


Python GsmModem.dial方法代碼示例

本文整理匯總了Python中gsmmodem.modem.GsmModem.dial方法的典型用法代碼示例。如果您正苦於以下問題:Python GsmModem.dial方法的具體用法?Python GsmModem.dial怎麽用?Python GsmModem.dial使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gsmmodem.modem.GsmModem的用法示例。


在下文中一共展示了GsmModem.dial方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from gsmmodem.modem import GsmModem [as 別名]
# 或者: from gsmmodem.modem.GsmModem import dial [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

示例2: main

# 需要導入模塊: from gsmmodem.modem import GsmModem [as 別名]
# 或者: from gsmmodem.modem.GsmModem import dial [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)
    print('Waiting for call to be answered/rejected')
    wasAnswered = False
    while call.active:
        if call.answered:
            wasAnswered = True
            print('Call has been answered; waiting a while...')
            # Wait for a bit - some older modems struggle to send DTMF tone immediately after answering a call
            time.sleep(3.0)
            print('Playing DTMF tones...')
            try:
                if call.active: # Call could have been ended by remote party while we waited in the time.sleep() call
                    call.sendDtmfTone('9515999955951')
            except InterruptedException as e:
                # Call was ended during playback
                print('DTMF playback interrupted: {0} ({1} Error {2})'.format(e, e.cause.type, e.cause.code))
            except CommandError as e:
                print('DTMF playback failed: {0}'.format(e))
            finally:
                if call.active: # Call is still active
                    print('Hanging up call...')
                    call.hangup()
                else: # Call is no longer active (remote party ended it)
                    print('Call has been ended by remote party')
        else:
            # Wait a bit and check again
            time.sleep(0.5)
    if not wasAnswered:
        print('Call was not answered by remote party')
    print('Done.')
    modem.close()
開發者ID:0x90,項目名稱:python-gsmmodem,代碼行數:44,代碼來源:dial_polling_demo.py

示例3: GsmModem

# 需要導入模塊: from gsmmodem.modem import GsmModem [as 別名]
# 或者: from gsmmodem.modem.GsmModem import dial [as 別名]
logging.basicConfig(filename="logs/" + unit + ".log", level = logging.DEBUG, format='%(asctime)s %(levelname)s: %(message)s');

# logging.info("Use file %s", file)
# logging.info("Use dev %s", device)

logging.info("Initializing modem...")

modem = GsmModem(device, BAUDRATE)
modem.smsTextMode = False
modem.connect()

logging.info("Waiting for network coverage...")
modem.waitForNetworkCoverage(30)

logging.info("Loading %s with %s", unit, cardcode)
call = modem.dial( LOADCODE + cardcode)

wasAnswered = False

while call.active:
    if call.answered:
        wasAnswered = True
        logging.info("Call answered")
        time.sleep(10.0)
        if call.active:
            logging.info("Hanging up")
            call.hangup()
        else:
            logging.info("Call ended by remote party")
    else:
        time.sleep(0.5)
開發者ID:radbasa,項目名稱:py-smsmachine,代碼行數:33,代碼來源:loadsmart.py

示例4: GsmModem

# 需要導入模塊: from gsmmodem.modem import GsmModem [as 別名]
# 或者: from gsmmodem.modem.GsmModem import dial [as 別名]
logging.basicConfig(filename="logs/" + unit + ".log", level = logging.DEBUG, format='%(asctime)s %(levelname)s: %(message)s');

# logging.info("Use file %s", file)
# logging.info("Use dev %s", device)

logging.info("Initializing modem...")

modem = GsmModem(device, BAUDRATE)
modem.connect()

logging.info("Waiting for network coverage...")
modem.waitForNetworkCoverage(30)

logging.info("Loading %s with %s %s", unit, cardcode, cardpin)
call = modem.dial( LOADCODE)

wasAnswered = False

while call.active:
    if call.answered:
        wasAnswered = True
        logging.info("Call answered")
        time.sleep(5.0)
        logging.info("DTMF card number")
        
        try:
            if call.active:
                call.sendDtmfTone( cardcode )
        except InterruptedException as e:
            logging.info("Card number DTMF playback interrupted: {0} ({1} Error {2})".format(e, e.cause.type, e.cause.code))
開發者ID:radbasa,項目名稱:py-smsmachine,代碼行數:32,代碼來源:loadglobe.py

示例5: __init__

# 需要導入模塊: from gsmmodem.modem import GsmModem [as 別名]
# 或者: from gsmmodem.modem.GsmModem import dial [as 別名]
class dispgsm:

	_user=None
	metrics={}

	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)
		#self._modem.smsTextMode = False
		


	def connect(self):
		self.logger.info('Connecting GSM modem...')
		#self._modem.connect()
		self._modem.connect(self._pin)
		self.logger.info('Waiting for network coverage...')
		try:
			self._modem.waitForNetworkCoverage(30)
		except TimeoutException:
        		self.logger.error('Network signal strength is not sufficient, please adjust modem position/antenna and try again.')
			self.disconnect()

                self.metrics['handled_sms']=[]
                self.metrics['handled_call']=[]
		self.metrics['send_sms']=[]
		self.metrics['dial_call']=[]
		self.logger.info('GSM Device ready to use.')

	def disconnect(self):
		self.logger.info('Disconnecting modem...')
		self._modem.close()
		self.logger.info('Disconnected')

	def send_sms(self, destination, text, waitForDeliveryReport=True, deliveryTimeout=15):
		if text==None:
			text =  str(random.randint(1000000000, 9999999999))

		self.logger.info('Sending SMS with text:%s',text)
		m ={}
		m['sms_text'] = text
		m['sms_delivery_timeout'] = deliveryTimeout
		m['sms_sent_time'] = str(datetime.datetime.now())
		try:
			sms = self._modem.sendSms(destination, text, waitForDeliveryReport, deliveryTimeout)
                	self.logger.info('Message sent with delivery report status:%s reference:%s',sms.status,sms.reference)
			if sms.status==0:
				m['sms_status'] = 'ENROUTE'
			elif sms.status==1:
				m['sms_status'] = 'DELIVERED'
			elif sms.status==2:
				m['sms_status'] = 'FAILED'
			else:
				m['sms_status'] = 'ERROR'
		except TimeoutException:
			self.logger.warning('Fail to deliver message: the send operation timed out')
		m['sms_end'] = str(datetime.datetime.now())
		self.metrics['send_sms'].append(m)


	def dial(self, destination, dtmf):
		if dtmf==None:
			dtmf = str(random.randint(1000000000, 9999999999))
		self.logger.info('Calling number %s and sending DTMF:%s',destination,dtmf)
		m = {}
		m['dial_dtmf'] = dtmf
		m['dial_start'] = str(datetime.datetime.now())
                call = self._modem.dial(destination)
                wasAnswered = False
                while call.active:
                        if call.answered:
                                wasAnswered = True
                                self.logger.info('Call has been answered; waiting a while...')
				m['dial_answered'] = str(datetime.datetime.now())
                                # Wait for a bit - some older modems struggle to send DTMF tone immediately after answering a call
                                time.sleep(3.0)
                                self.logger.info('Playing DTMF tones: %s',dtmf)
                                try:
                                        if call.active: # Call could have been ended by remote party while we waited in the time.sleep() call
                                                call.sendDtmfTone(dtmf)
						self.logger.info('DTMF tones sent')
						time.sleep(10)
                                except InterruptedException as e:
                                        # Call was ended during playback
                                        self.logger.info('DTMF playback interrupted: {0} ({1} Error {2})'.format(e, e.cause.type, e.cause.code))
                                except CommandError as e:
                                        self.logger.error('DTMF playback failed: {0}'.format(e))
                                finally:
                                        if call.active: # Call is still active
#.........這裏部分代碼省略.........
開發者ID:albertobaselga,項目名稱:e2eprobe,代碼行數:103,代碼來源:dispgsm.py


注:本文中的gsmmodem.modem.GsmModem.dial方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。