def __init__(self): app = QApplication(sys.argv) self.window = QWidget() self.ui = Ui_Form() self.ui.setupUi(self.window) self.session = None probes = ConnectHelper.get_all_connected_probes(blocking=False) for probe in probes: self.ui.daplink_list.addItem(probe.description) if len(probes) > 0: self.probe = probes[0] # print(self.probe) else: self.probe = None # logger = logging.getLogger(__name__) # logger.setLevel(level=logging.DEBUG) # StreamHandler # stream_handler = logging.StreamHandler(self.ui.log.append) # stream_handler.setLevel(level=logging.DEBUG) # logger.addHandler(stream_handler) self.ui.flash.clicked.connect(self.flash_device_run) self.ui.update_dap.clicked.connect(self.update_daplink) self.ui.connect.clicked.connect(self.open_session) self.ui.selsec_firmware.clicked.connect(self.select_file) self.ui.daplink_list.currentIndexChanged.connect(self.daplink_change) self.ui.flash.setDisabled(True) self.ui.progressBar.setValue(0) self.window.show() app.exec_()
def daplink_change(self): probes = ConnectHelper.get_all_connected_probes(blocking=False) for probe in probes: if probe.description == self.ui.daplink_list.currentText(): self.probe = probe else: self.probe = None
def update_daplink(self): self.ui.daplink_list.clear() probes = ConnectHelper.get_all_connected_probes(blocking=False) for probe in probes: self.ui.daplink_list.addItem(probe.description) if len(probes) > 0: self.probe = probes[0] else: self.probe = None
def get_connected_probes(cls, hardware_id: str = None ) -> List[ProbeDescription]: """Get all connected probes over PyOCD. This functions returns the list of all connected probes in system by PyOCD package. :param hardware_id: None to list all probes, otherwice the the only probe with matching hardware id is listed. :return: probe_description """ from .utils import DebugProbes probes = DebugProbes() connected_probes = ConnectHelper.get_all_connected_probes( blocking=False, unique_id=hardware_id) for probe in connected_probes: probes.append( ProbeDescription("PyOCD", probe.unique_id, probe.description, DebugProbePyOCD)) return probes
def get_connected_probes(cls, hardware_id: str = None, user_params: Dict = None) -> list: """Get all connected probes over PyOCD. This functions returns the list of all connected probes in system by PyOCD package. :param hardware_id: None to list all probes, otherwise the the only probe with matching hardware id is listed. :param user_params: The user params dictionary :return: probe_description """ # pylint: disable=import-outside-toplevel from .utils import DebugProbes, ProbeDescription probes = DebugProbes() connected_probes = ConnectHelper.get_all_connected_probes( blocking=False, unique_id=hardware_id) for probe in connected_probes: probes.append( ProbeDescription("PyOCD", probe.unique_id, probe.description, DebugProbePyOCD)) return probes
def main(): parser = argparse.ArgumentParser(description='pyOCD automated testing') parser.add_argument('-d', '--debug', action="store_true", help='Enable debug logging') parser.add_argument('-q', '--quiet', action="store_true", help='Hide test progress for 1 job') parser.add_argument('-j', '--jobs', action="store", default=1, type=int, metavar="JOBS", help='Set number of concurrent board tests (default is 1)') parser.add_argument('-b', '--board', action="append", metavar="ID", help="Limit testing to boards with specified unique IDs. Multiple boards can be listed.") args = parser.parse_args() # Allow CI to override the number of concurrent jobs. if 'CI_JOBS' in os.environ: args.jobs = int(os.environ['CI_JOBS']) # Disable multiple jobs on macOS prior to Python 3.4. By default, multiprocessing uses # fork() on Unix, which doesn't work on the Mac because CoreFoundation requires exec() # to be used in order to init correctly (CoreFoundation is used in hidapi). Only on Python # version 3.4+ is the multiprocessing.set_start_method() API available that lets us # switch to the 'spawn' method, i.e. exec(). if args.jobs > 1 and sys.platform.startswith('darwin') and sys.version_info[0:2] < (3, 4): print("WARNING: Cannot support multiple jobs on macOS prior to Python 3.4. Forcing 1 job.") args.jobs = 1 # Setup logging based on concurrency and quiet option. level = logging.DEBUG if args.debug else logging.INFO if args.jobs == 1 and not args.quiet: log_file = LOG_FILE_TEMPLATE.format(get_env_file_name()) # Create common log file. if os.path.exists(log_file): os.remove(log_file) logToConsole = True commonLogFile = open(log_file, "a") else: logToConsole = False commonLogFile = None board_list = [] result_list = [] # Put together list of boards to test board_list = ConnectHelper.get_all_connected_probes(blocking=False) board_id_list = sorted(b.unique_id for b in board_list) # Filter boards. if args.board: board_id_list = [b for b in board_id_list if any(c for c in args.board if c.lower() in b.lower())] # If only 1 job was requested, don't bother spawning processes. start = time() if args.jobs == 1: for n, board_id in enumerate(board_id_list): result_list += test_board(board_id, n, level, logToConsole, commonLogFile) else: # Create a pool of processes to run tests. try: pool = mp.Pool(args.jobs) # Issue board test job to process pool. async_results = [pool.apply_async(test_board, (board_id, n, level, logToConsole, commonLogFile)) for n, board_id in enumerate(board_id_list)] # Gather results. for r in async_results: result_list += r.get(timeout=JOB_TIMEOUT) finally: pool.close() pool.join() stop = time() test_time = (stop - start) print_summary(test_list, result_list, test_time) summary_file = SUMMARY_FILE_TEMPLATE.format(get_env_file_name()) with open(summary_file, "w") as output_file: print_summary(test_list, result_list, test_time, output_file) generate_xml_results(result_list) exit_val = 0 if Test.all_tests_pass(result_list) else -1 exit(exit_val)
def main(): parser = argparse.ArgumentParser(description='pyOCD automated testing') parser.add_argument('-d', '--debug', action="store_true", help='Enable debug logging') parser.add_argument('-q', '--quiet', action="store_true", help='Hide test progress for 1 job') parser.add_argument('-j', '--jobs', action="store", default=1, type=int, metavar="JOBS", help='Set number of concurrent board tests (default is 1)') parser.add_argument('-b', '--board', action="append", metavar="ID", help="Limit testing to boards with specified unique IDs. Multiple boards can be listed.") args = parser.parse_args() # Force jobs to 1 when running under CI until concurrency issues with enumerating boards are # solved. Specifically, the connect test has intermittently failed to open boards on Linux and # Win7. This is only done under CI, and in this script, to make testing concurrent runs easy. if 'CI_TEST' in os.environ: args.jobs = 1 # Disable multiple jobs on macOS prior to Python 3.4. By default, multiprocessing uses # fork() on Unix, which doesn't work on the Mac because CoreFoundation requires exec() # to be used in order to init correctly (CoreFoundation is used in hidapi). Only on Python # version 3.4+ is the multiprocessing.set_start_method() API available that lets us # switch to the 'spawn' method, i.e. exec(). if args.jobs > 1 and sys.platform.startswith('darwin') and sys.version_info[0:2] < (3, 4): print("WARNING: Cannot support multiple jobs on macOS prior to Python 3.4. Forcing 1 job.") args.jobs = 1 # Setup logging based on concurrency and quiet option. level = logging.DEBUG if args.debug else logging.INFO if args.jobs == 1 and not args.quiet: # Create common log file. if os.path.exists(LOG_FILE): os.remove(LOG_FILE) logToConsole = True commonLogFile = open(LOG_FILE, "a") else: logToConsole = False commonLogFile = None board_list = [] result_list = [] # Put together list of boards to test board_list = ConnectHelper.get_all_connected_probes(blocking=False) board_id_list = sorted(b.unique_id for b in board_list) # Filter boards. if args.board: board_id_list = [b for b in board_id_list if any(c for c in args.board if c.lower() in b.lower())] # If only 1 job was requested, don't bother spawning processes. start = time() if args.jobs == 1: for n, board_id in enumerate(board_id_list): result_list += test_board(board_id, n, level, logToConsole, commonLogFile) else: # Create a pool of processes to run tests. try: pool = mp.Pool(args.jobs) # Issue board test job to process pool. async_results = [pool.apply_async(test_board, (board_id, n, level, logToConsole, commonLogFile)) for n, board_id in enumerate(board_id_list)] # Gather results. for r in async_results: result_list += r.get(timeout=JOB_TIMEOUT) finally: pool.close() pool.join() stop = time() test_time = (stop - start) print_summary(test_list, result_list, test_time) with open(SUMMARY_FILE, "w") as output_file: print_summary(test_list, result_list, test_time, output_file) generate_xml_results(result_list) exit_val = 0 if Test.all_tests_pass(result_list) else -1 exit(exit_val)
def __init__(self, parent, ctr): self.ctr = ctr prjBase = self.ctr.GetProjectPath() wx.Dialog.__init__(self, name='ProgEditor', parent=parent, title=_('Prog with Serial')) ports = [ d.product_name for d in ConnectHelper.get_all_connected_probes(blocking=False) ] + [d.device for d in list_ports.comports()] self.choices = ports + [_('ESP-Link')] self._init_ctrls(parent) self._init_sizers() self.CenterOnParent() self.Log = LogPseudoFile(self.LogConsole, self.output) # self.Log = LogViewer(self.LogConsole, self) # self.LogConsole.SetLogSource(logging) self.verify = False self.boot = 0 self.reset = 1 try: prjBase = self.ctr.GetProjectPath() app_path = self.ctr.GetIECLibPath() progBase = os.path.abspath(os.path.join( app_path, '../../..', )) board = self.ctr.GetChildByName('board_0') if not board: dialog = wx.MessageDialog( parent, _('Can not Found "board_0",Please attach one board.'), style=wx.YES_DEFAULT | wx.CENTRE) dialog.ShowModal() wx.CallAfter(self.Close) return node = board.GetBoardFile() self.model = node['class'].custom_model or node['class'].model self.dev_id = node.get('dev_id', None) builder = self.ctr.GetBuilder() self.appBin = builder.GetBinaryPath() Board = board.BoardRoot.getBoard()[0] rte = Board.getFirmware() if not rte: dialog = wx.MessageDialog(parent, '未选择使用的RTE固件,请检查board配置.', style=wx.YES_DEFAULT | wx.CENTRE) dialog.ShowModal() wx.CallAfter(self.Close) return model = node['class'] self.rtes = node.get('class').rtes self.rtebin = None for x in self.rtes.values(): if x['name'] == rte: self.rte = x break if self.rte.get('bin'): self.rtebin = os.path.join(progBase, "firmware", self.rte.get('bin')) self.BlkRte = self.rte.get('blocks') self.BlkApp = self.rte.get('app_blocks') self.adrRte = self.rte.get('start') self.adrApp = self.rte.get('app_start') self.BlkBoot = None bootloader = self.rte.get('bootloader') bootName = None self.boot = model.prog_boot self.reset = model.prog_reset if bootloader: self.BlkBoot = bootloader.get('blocks') bootName = bootloader.get('bin') else: self.prgBoot.SetValue(False) self.prgBoot.Hide() if bootName: self.bootbin = os.path.join(progBase, "firmware", bootName) if not exists(self.bootbin): dialog = wx.MessageDialog(parent, _("Cannot Get Boot bin."), style=wx.YES_DEFAULT | wx.CENTRE) dialog.ShowModal() return if self.rtebin and not exists(self.rtebin): dialog = wx.MessageDialog(parent, _("Cannot Get Rte bin."), style=wx.YES_DEFAULT | wx.CENTRE) dialog.ShowModal() wx.CallAfter(self.Close) if not exists(self.appBin): dialog = wx.MessageDialog( parent, _("Cannot Get PLC Firmware.Please Exec Build."), style=wx.YES_DEFAULT | wx.CENTRE) dialog.ShowModal() wx.CallAfter(self.Close) if not self.rtebin: self.prgRte.SetValue(False) self.prgRte.Hide() except Exception as ex: print(traceback.print_exc()) dialog = wx.MessageDialog(parent, str(ex), style=wx.YES_DEFAULT | wx.CENTRE) dialog.ShowModal() wx.CallAfter(self.Close)
def __init__(self): app = QApplication(sys.argv) self.window = QWidget() self.ui = Ui_Form() self.ui.setupUi(self.window) self.cache = cmsis_pack_manager.Cache(True, True) managedpack = ManagedPacks() self.packs = ManagedPacks().get_installed_packs() vendors = [] current_packs = [] self.current_targets = [] for pack in self.packs: pack_path = os.path.join(self.cache.data_path, pack.get_pack_name()) pack_temp = CmsisPack(pack_path) if len(pack_temp.devices) > 0: target_vendor = pack_temp.devices[0].vendor else: continue if target_vendor in vendors: pass else: vendors.append(target_vendor) for vendor in vendors: self.ui.vendor_list.addItem(vendor) for pack in self.packs: pack_path = os.path.join(self.cache.data_path, pack.get_pack_name()) pack_temp = CmsisPack(pack_path) if len(pack_temp.devices) > 0: target_vendor = pack_temp.devices[0].vendor else: continue if target_vendor == self.ui.vendor_list.currentText(): current_packs.append(pack) # print(ui.vendor_list.currentText()) for current_pack in current_packs: # print(type(current_pack)) pack_path = os.path.join(self.cache.data_path, current_pack.get_pack_name()) # print(pack_path) pack = CmsisPack(pack_path) for device in pack.devices: self.current_targets.append(device) # print(current_targets) for target in self.current_targets: self.ui.device_list.addItem(target.part_number) probes = ConnectHelper.get_all_connected_probes(blocking=False) for probe in probes: self.ui.daplink_list.addItem(probe.description) if len(probes) > 0: self.probe = probes[0] print(self.probe) else: self.probe = None logger = logging.getLogger(__name__) logger.setLevel(level=logging.DEBUG) # StreamHandler stream_handler = logging.StreamHandler(self.ui.log.append) stream_handler.setLevel(level=logging.DEBUG) logger.addHandler(stream_handler) self.ui.vendor_list.currentTextChanged.connect(self.vendor_change) self.ui.device_list.currentIndexChanged.connect(self.device_change) self.ui.erase.clicked.connect(self.erase_device) self.ui.flash.clicked.connect(self.flash_device) self.ui.update_dap.clicked.connect(self.update_daplink) self.ui.connect.clicked.connect(self.open_session) self.ui.selsec_firmware.clicked.connect(self.select_file) self.ui.daplink_list.currentIndexChanged.connect(self.daplink_change) self.ui.flash_run.clicked.connect(self.flash_device_run) self.ui.halt.clicked.connect(self.device_halt) self.ui.run.clicked.connect(self.device_reset) self.ui.resume.clicked.connect(self.device_resume) self.ui.run.setDisabled(True) self.ui.halt.setDisabled(True) self.ui.erase.setDisabled(True) self.ui.flash.setDisabled(True) self.ui.flash_run.setDisabled(True) self.ui.resume.setDisabled(True) self.device_change() self.window.show() app.exec_()
def get_probe_list(): """ Gets list of all connected probes """ return ConnectHelper.get_all_connected_probes(blocking=False)