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

Added a command-line script to print the available VISA resources. #26

Merged
merged 1 commit into from
Oct 16, 2023
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ project adheres to [Semantic Versioning](https://semver.org).

______________________________________________________________________

## Unreleased

### Added

- A command-line script to list all available VISA resources, `list-visa-resources`

______________________________________________________________________

## v0.1.14 (2023-10-03)

### Added
Expand Down
14 changes: 14 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ Installation
Basic Usage
-----------

Print Available VISA Devices
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: console

$ list-visa-resources
[
"TCPIP0::192.168.0.100::inst0::INSTR",
"ASRL4::INSTR"
]

Basic Script
~~~~~~~~~~~~

.. code-block:: python

from tm_devices import DeviceManager
Expand Down
12 changes: 12 additions & 0 deletions docs/basic_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
A collection of examples showing the basics of how to use `tm_devices` in a
project.

## List available VISA devices

This will print the available VISA devices to the console when run from a shell terminal.

```console
> list-visa-resources
[
"TCPIP0::192.168.0.100::inst0::INSTR",
"ASRL4::INSTR"
]
```

## Adding devices

```{literalinclude} ../examples/miscellaneous/adding_devices.py
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ types-requests = ">=2.28.8"
urllib3 = ">=1.26.14"
wheel = ">=0.37.1"

[tool.poetry.scripts]
list-visa-resources = "tm_devices:print_available_visa_devices"

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/tektronix/tm_devices/issues"
"Changelog" = "https://tm_devices.readthedocs.io/en/stable/CHANGELOG.html"
Expand Down
3 changes: 2 additions & 1 deletion src/tm_devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""
from importlib.metadata import version

from tm_devices.device_manager import DeviceManager
from tm_devices.device_manager import DeviceManager, print_available_visa_devices
from tm_devices.helpers.constants_and_dataclasses import (
PACKAGE_NAME,
PYVISA_PY_BACKEND,
Expand All @@ -25,6 +25,7 @@

__all__ = [
"DeviceManager",
"print_available_visa_devices",
"PYVISA_PY_BACKEND",
"SupportedModels",
"SYSTEM_DEFAULT_VISA_BACKEND",
Expand Down
8 changes: 8 additions & 0 deletions src/tm_devices/device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import contextlib
import inspect
import json
import os
import pathlib
import socket
Expand Down Expand Up @@ -1427,3 +1428,10 @@ def __set_options(self, verbose: bool) -> None:
else:
self.__visa_library = ""
self.verbose_visa = bool(self.__config.options.verbose_visa)


def print_available_visa_devices() -> None: # pragma: no cover
"""Print all available VISA devices to the console."""
with contextlib.redirect_stdout(None), contextlib.redirect_stderr(None), DeviceManager() as dm:
available_devices = dm.get_available_devices()
print(json.dumps(available_devices["local"], indent=2))