def run(self, fullmode=False, reset=None, select=None): """Switch to a pure serial terminal application""" if self._no_term: return if select is not None: selmode = to_bool(select) self._port.setRTS(selmode) if reset is not None: hwreset = to_bool(reset) self._port.setDTR(hwreset) time.sleep(0.200) self._port.setDTR(not hwreset) time.sleep(0.100) # wait forever, although Windows is stupid and does not signal Ctrl+C, # so wait use a 1/2-second timeout that gives some time to check for a # Ctrl+C break then polls again... self.screen_string_blue() self.screen_print('Entering minicom mode') self.screen_string_black() stdout.flush() self._port.timeout = 0.5 self._resume = True # start the reader (target to host direction) within a dedicated thread r = threading.Thread(target=self._reader) r.setDaemon(1) r.start() # start the writer (host to target direction) self._writer(fullmode)
def _build_device(self, container): devdesc = None configs = [] properties = {} for ykey, yval in container.items(): if ykey == 'descriptor': if not isinstance(yval, dict): raise ValueError('Device descriptor not a dict') devdesc = self._build_device_descriptor(yval) continue if ykey == 'configurations': if not isinstance(yval, list): raise ValueError('Configurations not a list') configs = [self._build_configuration(conf) for conf in yval] continue if ykey == 'noaccess': yval = to_bool(yval) if ykey == 'speed' and isinstance(yval, str): try: yval = USBCONST.speeds[yval] except KeyError: raise ValueError(f'Invalid device speed {yval}') properties[ykey] = yval if not devdesc: raise ValueError('Missing device descriptor') if not configs: configs = [self._build_configuration({})] device = MockDevice(devdesc, **properties) for config in configs: device.add_configuration(config) return device
def main(): testmod(modules[__name__]) debug = to_bool(environ.get('FTDI_DEBUG', 'off')) if debug: formatter = logging.Formatter( '%(asctime)s.%(msecs)03d %(levelname)-7s' ' %(name)-18s [%(lineno)4d] %(message)s', '%H:%M:%S') else: formatter = logging.Formatter('%(message)s') level = environ.get('FTDI_LOGLEVEL', 'info').upper() try: loglevel = getattr(logging, level) except AttributeError: raise ValueError(f'Invalid log level: {level}') FtdiLogger.log.addHandler(logging.StreamHandler(stdout)) FtdiLogger.set_level(loglevel) FtdiLogger.set_formatter(formatter) # Force PyUSB to use PyFtdi test framework for USB backends UsbTools.BACKENDS = ('backend.usbvirt', ) # Ensure the virtual backend can be found and is loaded backend = UsbTools.find_backend() try: # obtain the loader class associated with the virtual backend global MockLoader MockLoader = backend.create_loader() except AttributeError: raise AssertionError('Cannot load virtual USB backend') ut_main(defaultTest='suite')
def main(): if to_bool(environ.get('FTDI_DEBUG', 'off')): FtdiLogger.log.addHandler(logging.StreamHandler(stdout)) level = environ.get('FTDI_LOGLEVEL', 'info').upper() try: loglevel = getattr(logging, level) except AttributeError: raise ValueError('Invalid log level: %s' % level) FtdiLogger.set_level(loglevel) testmod(modules[__name__]) unittest.main(defaultTest='suite')
def virtualize(): if not to_bool(environ.get('FTDI_VIRTUAL', 'off')): return from pyftdi.usbtools import UsbTools # Force PyUSB to use PyFtdi test framework for USB backends UsbTools.BACKENDS = ('backend.usbvirt', ) # Ensure the virtual backend can be found and is loaded backend = UsbTools.find_backend() try: # obtain the loader class associated with the virtual backend global VirtLoader VirtLoader = backend.create_loader() except AttributeError as exc: raise AssertionError('Cannot load virtual USB backend') from exc
def run(self, fullmode=False, reset=None, select=None): """Switch to a pure serial terminal application""" if select is not None: selmode = to_bool(select) self._port.setRTS(selmode) if reset is not None: hwreset = to_bool(reset) self._port.setDTR(hwreset) time.sleep(0.200) self._port.setDTR(not hwreset) time.sleep(0.100) # wait forever, although Windows is stupid and does not signal Ctrl+C, # so wait use a 1/2-second timeout that gives some time to check for a # Ctrl+C break then polls again... print "Entering minicom mode" sys.stdout.flush() self._port.timeout = 0.5 self._resume = True # start the reader (target to host direction) within a dedicated thread r = threading.Thread(target=self._reader) r.setDaemon(1) r.start() # start the writer (host to target direction) self._writer(fullmode)
def main(): import doctest doctest.testmod(modules[__name__]) debug = to_bool(environ.get('FTDI_DEBUG', 'off')) if debug: formatter = logging.Formatter( '%(asctime)s.%(msecs)03d %(levelname)-7s' ' %(name)-20s [%(lineno)4d] %(message)s', '%H:%M:%S') else: formatter = logging.Formatter('%(message)s') level = environ.get('FTDI_LOGLEVEL', 'warning').upper() try: loglevel = getattr(logging, level) except AttributeError as exc: raise ValueError(f'Invalid log level: {level}') from exc FtdiLogger.log.addHandler(logging.StreamHandler(stdout)) FtdiLogger.set_level(loglevel) FtdiLogger.set_formatter(formatter) virtualize() try: ut_main(defaultTest='suite') except KeyboardInterrupt: pass
def _build_device(self, container): devdesc = None configs = [] properties = {} delayed_load = False for ykey, yval in container.items(): if ykey == 'descriptor': if not isinstance(yval, dict): raise ValueError('Device descriptor not a dict') devdesc = self._build_device_descriptor(yval) continue if ykey == 'configurations': if not isinstance(yval, list): raise ValueError('Configurations not a list') configs = [self._build_configuration(conf) for conf in yval] continue if ykey == 'noaccess': yval = to_bool(yval) if ykey == 'speed' and isinstance(yval, str): try: yval = USBCONST.speeds[yval] except KeyError as exc: raise ValueError(f'Invalid device speed {yval}') from exc if ykey == 'eeprom': if not isinstance(yval, dict): raise ValueError('Invalid EEPROM section') for pkey, pval in yval.items(): if pkey == 'model': if not isinstance(pval, str): raise ValueError('Invalid EEPROM model') continue if pkey == 'load': try: pval = to_bool(pval, permissive=False, allow_int=True) yval[pkey] = pval delayed_load = pval except ValueError as exc: raise ValueError('Invalid EEPROM load option') \ from exc continue if pkey == 'data': if isinstance(pval, str): hexstr = pval.replace(' ', '').replace('\n', '') try: pval = unhexlify(hexstr) yval[pkey] = pval except ValueError as exc: raise ValueError('Invalid EEPROM hex format') \ from exc if not isinstance(pval, bytes): raise ValueError(f'Invalid EEPROM data ' f'{type(pval)}') self._epprom_backup = pval continue raise ValueError(f'Unknown EEPROM option {pkey}') properties[ykey] = yval if not devdesc: raise ValueError('Missing device descriptor') if not configs: configs = [self._build_configuration({})] device = VirtDevice(devdesc, **properties) for config in configs: device.add_configuration(config) if delayed_load: device.ftdi.apply_eeprom_config(device.desc, [cfg.desc for cfg in configs]) return device
def setUpClass(cls): cls.debug = to_bool(environ.get('FTDI_DEBUG', 'off'), permissive=False) cls.url = environ.get('FTDI_DEVICE', 'ftdi:///1') cls.loader = None
def open(self): """Open an SPI connection to a slave""" url = environ.get('FTDI_DEVICE', 'ftdi:///1') debug = to_bool(environ.get('FTDI_DEBUG', 'off')) self._spi.configure(url, debug=debug)
def setUpClass(cls): cls.url = environ.get('FTDI_DEVICE', 'ftdi:///1') cls.debug = to_bool(environ.get('FTDI_DEBUG', 'off'))
def setUpClass(cls): cls.debug = to_bool(environ.get('FTDI_DEBUG', 'off'), permissive=False)