本文整理汇总了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')
示例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()
示例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)
示例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))
示例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
#.........这里部分代码省略.........