Add enumerate_devices with filter, shows only GPIB
This commit is contained in:
parent
9d2c35f466
commit
37049663a1
@ -14,7 +14,7 @@ def list_devices() -> dict[str,list[str]]:
|
|||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
from .impl import keithley2700
|
from .impl import keithley2700
|
||||||
devices["VISA"] = ["example visa device"] #keithley2700.enumerate_devices()
|
devices["VISA"] = keithley2700.enumerate_devices()
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
return devices
|
return devices
|
||||||
|
@ -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)
|
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:
|
if len(resources) < 1:
|
||||||
raise Exception("No resources found.")
|
raise Exception("No resources found.")
|
||||||
elif len(resources) == 1:
|
elif len(resources) == 1:
|
||||||
@ -41,7 +75,8 @@ def select_visa_device(visa_backend=""):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
print(f"Enter a number between 1 and {len(resources)}")
|
print(f"Enter a number between 1 and {len(resources)}")
|
||||||
continue
|
continue
|
||||||
|
raise Exception("This should never happen")
|
||||||
|
|
||||||
|
|
||||||
class Keithley2700(VoltageMeasurementDevice):
|
class Keithley2700(VoltageMeasurementDevice):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user