36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
import pyvisa
|
|
|
|
import logging
|
|
log = logging.getLogger(__name__)
|
|
|
|
def enumerate_devices(device_name, query="(GPIB)|(USB)?*:INSTR", cmd="*IDN?", visa_backend=""):
|
|
"""
|
|
Return all available visa resources that match the query and the device name
|
|
Parameters
|
|
----------
|
|
device_name
|
|
A part of the name that the device is supposed to return upon the '*IDN?' command
|
|
cmd
|
|
The command to send to ALL devices matching the query
|
|
query
|
|
A query to the visa resource manager, to filter the resources
|
|
visa_backend
|
|
The visa backend to use, if not the default one
|
|
|
|
Returns
|
|
-------
|
|
List of visa resource names
|
|
|
|
"""
|
|
rm = pyvisa.ResourceManager(visa_backend)
|
|
res = []
|
|
for r in rm.list_resources(query):
|
|
try:
|
|
instr = rm.open_resource(r)
|
|
name = instr.query(cmd)
|
|
if device_name in name:
|
|
res.append(r)
|
|
instr.close()
|
|
except:
|
|
log.debug(f"Could not open Visa resources {r}")
|
|
return res |