def main(): p = OptionParser("usage: %prog [options]") p.add_option( '-l', '--list', type='string', dest='list', default='all', help='list messages. Values supported: all,unread. Default - all') (opts, args) = p.parse_args() if opts.list == 'all': smsType = 'ALL' elif opts.list == 'unread': smsType = 'REC UNREAD' else: p.print_help() exit(-1) try: m = humod.Modem() m.enable_textmode(True) print m.sms_list(smsType) #m.sms_read(i) except humod.errors.AtCommandError, e: print e exit(-1)
def __init__(self, tty_device_file, pin): try: self.MODEM = humod.Modem(tty_device_file, tty_device_file) signal.signal(signal.SIGALRM, self._handler_timeout_signal) signal.alarm(10) self.MODEM.show_model() signal.alarm(0) except: self.handle_error(self.ERR_MSG_INIT_MODEM) try: self.CMD_CPIN = Command(self.MODEM, self.CMD_STR_CPIN) pin_status = self.CMD_CPIN.get()[0] except: self.handle_error(self.ERR_MSG_PIN_QUERY) if 'IM PUK' in pin_status: self.handle_error(self.ERR_MSG_PUK) if 'IM PIN' in pin_status: if pin == '': self.handle_error(self.ERR_MSG_PIN_EMPTY) try: self.CMD_CPIN.set(pin) except: self.handle_error(self.ERR_MSG_PIN_APPLY) try: pin_status = self.CMD_CPIN.get()[0] except: self.handle_error(self.ERR_MSG_PIN_QUERY) if 'EADY' not in pin_status: self.handle_error(self.ERR_MSG_PIN_WRONG) return if 'EADY' not in pin_status: self.handle_error(self.ERR_MSG_PIN_UNDEFINED) try: self.CMD_CPOS = Command(self.MODEM, self.CMD_STR_COPS) self.CMD_CPOS.set(0) except: self.handle_error(self.ERR_MSG_CMD_CPOS_FAILED) time.sleep(10) try: self.CMD_CSCS = Command(self.MODEM, self.CMD_STR_CSCS) self.CMD_CSCS.set('"GSM"') except: self.handle_error(self.ERR_MSG_SET_CHARACTER_SET_FAILED) try: self.MODEM.enable_textmode(True) except: self.handle_error(self.ERR_MSG_SET_TEXTMODE_FAILED)
def get_modems(): """Return a list of modems plugged into the computer. Switched to text mode. """ ports = list_ports.comports() ports = [s.device for s in ports if s.device.startswith(pre)] no1 = True if 'Modem' in ''.join(ports) else False ports = [int(p.replace(pre, '')) for p in ports if p[-1].isdigit()] ports = [(y, z) for x, y, z in seq(ports, 3)] if no1: ports.append(('Modem', 'Pcui')) modems, info = {}, [] for i, pair in enumerate(ports): try: modems[i] = humod.Modem(pre + str(pair[0]), pre + str(pair[1])) modems[i].enable_textmode(True) except SerialException as e: info.append(('Not connected.', str(e), i + 1)) except OSError as e: info.append(('Power off.', str(e), i + 1)) except humod.errors.AtCommandError as e: info.append(('', str(e), i + 1)) del modems[i] return modems, info
def setUp(self): self.modem = humod.Modem()
import humod, sys, string, lockfile lock = lockfile.FileLock("/tmp/sms_client_huawei") if lock.is_locked(): print "modem locked, so we will wait..." try: lock.acquire(timeout=TIMEOUT) except lockfile.LockTimeout: print "couldn't acquire lock on modem in within timeout ", TIMEOUT, " seconds." sys.exit(2) errcode = 0 try: m = humod.Modem() if m.get_pin_status() == 'SIM PIN': m.enter_pin(PIN) foundmodel = m.show_model() if foundmodel != MODEMMODEL: print "detected modem model: ", foundmodel, " not expected model: ", MODEMMODEL errcode = 2 else: print "3G modem model found as Huawei ", foundmodel except Exception, e: print "error running 3g modem check script:", e errcode = 2 lock.release()
logger.setLevel(logging.DEBUG) logger.debug('start script') if not (os.path.exists("swpibak.cfg")): os.system("sudo cp swpi.cfg swpibak.cfg") logger.debug('create copy of swpi.cfg') if (filecmp.cmp('swpibak.cfg', 'swpi.cfg')): os.system("sudo cp swpi.cfg swpibak.cfg") logger.debug('cfg file is changed-new copy') configfile = 'swpibak.cfg' cfg = config.config(configfile, False) logger.debug('Wait for first control') modem = humod.Modem(cfg.dongleDataPort, cfg.dongleAudioPort, cfg.dongleCtrlPort, cfg) time.sleep(240) while True: if checkswpi(): logger.debug('SwPi work') if standby() > 10: logger.error('SwPi not Update') controlloswpi() else: logger.debug('Swpi ok') else: logger.error('SwPi not Work') controlloswpi()