Skip to content

Commit

Permalink
feat: Enable turning down the verbosity of failure messages during re…
Browse files Browse the repository at this point in the history
…boot of a VISA device.
  • Loading branch information
nfelt14 committed Feb 12, 2025
1 parent 7ba1c71 commit a1dc896
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Valid subsections within a version are:

Things to be included in the next release go here.

### Added

- Added a new parameter to the `create_visa_connection()` function which can be used to turn down the verbosity of the printouts to stdout during a reboot from `ERROR` to `DEBUG` to avoid cluttering the console with unnecessary failures while the device is still rebooting.

---

## v3.1.1 (2025-02-04)
Expand Down
1 change: 1 addition & 0 deletions src/tm_devices/driver_mixins/device_control/pi_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ def _open(self) -> bool:
self._visa_resource = create_visa_connection(
self._config_entry,
visa_library=self._visa_library_path,
verbose_connection_failure_logging=False,
)
opened = True
if iteration < 1 and not bool(
Expand Down
17 changes: 12 additions & 5 deletions src/tm_devices/helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ def create_visa_connection(
*,
retry_connection: bool = False,
second_connection_attempt_delay: int = 60,
verbose_connection_failure_logging: bool = True,
) -> MessageBasedResource:
"""Create a VISA resource.
Expand All @@ -314,13 +315,16 @@ def create_visa_connection(
between each attempt.
second_connection_attempt_delay: The number of seconds to wait in between the first and
second connection attempts when `retry_connection=True`.
verbose_connection_failure_logging: Indicates if the connections failures should be logged
with an ERROR level. If False, the failures will be logged with a DEBUG level.
Returns:
A VISA resource that can be passed into the device driver.
Raises:
ConnectionError: The VISA connection couldn't be created to the device.
"""
failure_logging_level = logging.ERROR if verbose_connection_failure_logging else logging.DEBUG
# Set up the VISA resource that will be used for communicating with the VISA device
resource_expression = device_config_entry.get_visa_resource_expression()
try:
Expand Down Expand Up @@ -351,8 +355,9 @@ def create_visa_connection(
f" using the resource expression '{resource_expression}'"
f" and the {repr(visa_library) if visa_library else 'default'} VISA library"
)
_logger.error(error_message) # noqa: TRY400
_logger.error( # noqa: TRY400
_logger.log(failure_logging_level, error_message)
_logger.log(
failure_logging_level,
"1st exception: %s.%s: %s",
error_1.__class__.__module__,
error_1.__class__.__qualname__,
Expand All @@ -379,14 +384,16 @@ def create_visa_connection(
f" using the resource expression '{resource_expression}'"
f" and the {repr(visa_library) if visa_library else 'default'} VISA library"
)
_logger.error(error_message) # noqa: TRY400
_logger.error( # noqa: TRY400
_logger.log(failure_logging_level, error_message)
_logger.log(
failure_logging_level,
"1st exception: %s.%s: %s",
error_1.__class__.__module__,
error_1.__class__.__qualname__,
error_1,
)
_logger.error( # noqa: TRY400
_logger.log(
failure_logging_level,
"2nd exception: %s.%s: %s:",
error_2.__class__.__module__,
error_2.__class__.__qualname__,
Expand Down

0 comments on commit a1dc896

Please sign in to comment.