Skip to content

Commit

Permalink
ENH: removed verbose logging option
Browse files Browse the repository at this point in the history
  • Loading branch information
mjmucha committed May 28, 2024
1 parent 55fe8fa commit 4c242ec
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions basil/utils/USBBinds.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def find_usb_binds(rm, log,
instruments,
binds_to_skip=[],
memorized_binds=[],
timeout=1000 * 4,
verbose=False,
timeout=1000 * 4
):
"""
Finds the USB bind for each instrument in the given list of instruments.
Expand All @@ -59,8 +58,6 @@ def find_usb_binds(rm, log,
Defaults to an empty list.
timeout (int, optional): Timeout value in milliseconds.
Defaults to 4000.
verbose (bool, optional): Flag indicating whether to log verbose messages.
Defaults to False.
Returns:
dict: A dictionary mapping the identification strings of the instruments
Expand All @@ -87,34 +84,28 @@ def find_usb_binds(rm, log,
resources = (instrument["port"],) + resources

for i, res in enumerate(resources):
if verbose:
log.debug(f"[{i}] Trying {res}")
log.debug(f"[{i}] Trying {res}")

if "USB" not in res: # Only search for USB devices
if verbose:
log.debug(f"Skipping non USB bind {res}")
log.debug(f"Skipping non USB bind {res}")
continue

if any(bind in res for bind in skip_binds):
if verbose:
log.debug(f"Skipping USB bind {res}")
log.debug(f"Skipping USB bind {res}")
continue

try:
if verbose:
log.info(f"Trying {res} with baud rate {instrument['baud_rate']}")
log.debug(f"Trying {res} with baud rate {instrument['baud_rate']}")

if any(res in bind for bind in memorized_binds):
if verbose:
log.info(f"Found memorized bind {res}")
log.debug(f"Found memorized bind {res}")
result = memorized_binds[res]
else:
result = query_identification(rm, res, instrument['baud_rate'], instrument['read_termination'], instrument['write_termination'], timeout=timeout)

memorized_binds.append({res, result})

if verbose:
log.info(f"Found {result.strip()}")
log.debug(f"Found {result.strip()}")

if result.lower().strip() in [inst["identification"].lower().strip() for inst in instruments]:
substring = res.split("/")[2].split("::")[0]
Expand All @@ -127,8 +118,7 @@ def find_usb_binds(rm, log,
if len(results) == len(instruments):
return results

if verbose:
log.debug(f"Found {len(results)} out of {len(instruments)}")
log.debug(f"Found {len(results)} out of {len(instruments)}")

break

Expand Down Expand Up @@ -192,7 +182,7 @@ def load_yaml_with_comments(conf):
return conf_dict


def modify_basil_config(conf, log, skip_binds=[], save_modified=None, verbose=False):
def modify_basil_config(conf, log, skip_binds=[], save_modified=None):
"""
Modifies the basil configuration file by finding USB binds for devices.
Expand All @@ -201,7 +191,6 @@ def modify_basil_config(conf, log, skip_binds=[], save_modified=None, verbose=Fa
log: The logger object for logging messages.
skip_binds (list, optional): List of USB binds to skip. Defaults to [].
save_modified (str, optional): Path to save the modified basil configuration file. Defaults to None.
verbose (bool, optional): Flag to enable verbose logging. Defaults to False.
Returns:
dict: The modified basil configuration dictionary.
Expand All @@ -220,8 +209,7 @@ def modify_basil_config(conf, log, skip_binds=[], save_modified=None, verbose=Fa
or "read_termination" not in tf["init"].keys()
or not any(e in tf["init"].keys() for e in ["baud_rate", "baudrate"])
):
if verbose:
log.debug(f"Skipping {tf['type']} transfer layer with name {tf['name']}")
log.debug(f"Skipping {tf['type']} transfer layer with name {tf['name']}")
continue

instrument = tf["init"]["identification"]
Expand All @@ -240,7 +228,7 @@ def modify_basil_config(conf, log, skip_binds=[], save_modified=None, verbose=Fa

insts_idx_map[instrument.lower().strip()] = i

found_binds = find_usb_binds(rm, log=log, instruments=instruments, binds_to_skip=skip_binds, verbose=verbose)
found_binds = find_usb_binds(rm, log=log, instruments=instruments, binds_to_skip=skip_binds)

for inst in found_binds.keys():
if found_binds[inst] is None:
Expand Down

0 comments on commit 4c242ec

Please sign in to comment.