Add enumerate_devices with filter, shows only GPIB

This commit is contained in:
CPD 2025-03-04 17:51:56 +01:00
parent 9d2c35f466
commit 37049663a1
2 changed files with 39 additions and 4 deletions

View File

@ -14,7 +14,7 @@ def list_devices() -> dict[str,list[str]]:
}
try:
from .impl import keithley2700
devices["VISA"] = ["example visa device"] #keithley2700.enumerate_devices()
devices["VISA"] = keithley2700.enumerate_devices()
except ImportError:
pass
return devices

View File

@ -20,9 +20,43 @@ scripts = {
}
def select_visa_device(visa_backend=""):
def enumerate_devices(visa_backend="", query="GPIB?*::INSTR") -> list[str]:
"""
Enumerate all devices matching the query.
Parameters
----------
visa_backend
The Visa backend to use (eg. "@py" for pyvisa-py, "@sim" for pyvisa-sim).
If not specified, the default backend is used.
query
The query to use to find devices. To list all, use "?*::INSTR".
Returns
-------
"""
rm = pyvisa.ResourceManager(visa_backend)
resources = rm.list_resources()
resources = rm.list_resources(query=query)
return resources
def select_visa_device(visa_backend="", query="GPIB?*::INSTR") -> pyvisa.resources.Resource:
"""
Select a Visa device interactively from the command line
Parameters
----------
visa_backend
The Visa backend to use (eg. "@py" for pyvisa-py, "@sim" for pyvisa-sim).
If not specified, the default backend is used.
query
The query to use to find devices. To list all, use "?*::INSTR".
Returns
-------
pyvisa.resources.Resource : The selected Visa device
"""
rm = pyvisa.ResourceManager(visa_backend)
resources = rm.list_resources(query=query)
if len(resources) < 1:
raise Exception("No resources found.")
elif len(resources) == 1:
@ -41,6 +75,7 @@ def select_visa_device(visa_backend=""):
except ValueError:
print(f"Enter a number between 1 and {len(resources)}")
continue
raise Exception("This should never happen")
class Keithley2700(VoltageMeasurementDevice):