Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable turning down the verbosity of failure messages during reboot of a VISA device #381

Merged
merged 4 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ libusb-package = "^1.0.26.0,!=1.0.26.2" # 1.0.26.2 doesn't work with Python 3.1
packaging = "^24.0"
psutil = "^6.0.0"
pyserial = "^3.5"
python = "^3.8" # This is the main Python version requirement
python = "^3.8,!=3.9.0,!=3.9.1" # This is the main Python version requirement, the excluded versions of Python had major bugs and shouldn't be used
python-dateutil = "^2.8.2"
pyusb = "^1.2.1"
pyvicp = "^1.1.0"
Expand Down
2 changes: 0 additions & 2 deletions src/tm_devices/device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,6 @@ def open(self) -> bool:
_logger.info("Opening Connections to Devices")
for device_name, device_config in self.__config.devices.items():
self.__create_device(device_name, device_config, 3)
if self.__setup_cleanup_enabled:
self.cleanup_all_devices()
self.__is_open = True
self._suppress_protection = False

Expand Down
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
Loading