diff --git a/cpdctrl/voltage_measurement_device/__init__.py b/cpdctrl/voltage_measurement_device/__init__.py index 003cd95..1cb25f8 100644 --- a/cpdctrl/voltage_measurement_device/__init__.py +++ b/cpdctrl/voltage_measurement_device/__init__.py @@ -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 diff --git a/cpdctrl/voltage_measurement_device/impl/keithley2700.py b/cpdctrl/voltage_measurement_device/impl/keithley2700.py index 26209ea..93cad77 100644 --- a/cpdctrl/voltage_measurement_device/impl/keithley2700.py +++ b/cpdctrl/voltage_measurement_device/impl/keithley2700.py @@ -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,7 +75,8 @@ 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): """