Skip to content

Commit

Permalink
Add list_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
alexforencich committed Feb 18, 2017
1 parent 8be7fdc commit 4517092
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion usbtmc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
__all__ = ["usbtmc"]

from .version import __version__
from .usbtmc import Instrument, list_devices
from .usbtmc import Instrument, list_devices, list_resources
33 changes: 33 additions & 0 deletions usbtmc/usbtmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,39 @@ def is_usbtmc_device(dev):
return list(usb.core.find(find_all=True, custom_match=is_usbtmc_device))


def list_resources():
"List resource strings for all connected USBTMC devices"

res = []

for dev in list_devices():
idVendor = dev.idVendor
idProduct = dev.idProduct

# "fix" IDs for devices in firmware update mode
if idVendor == 0x0957 and idProduct == 0x2818:
idProduct = 0x2918

if idVendor == 0x0957 and idProduct == 0x4418:
# Agilent U2722A/U2723A firmware update mode
idProduct = 0x4318

# attempt to read serial number
iSerial = None
try:
iSerial = dev.serial_number
except:
pass

# append formatted resource string to list
if iSerial is None:
res.append("USB::%d::%d::INSTR" % (idVendor, idProduct))
else:
res.append("USB::%d::%d::%s::INSTR" % (idVendor, idProduct, iSerial))

return res


def find_device(idVendor=None, idProduct=None, iSerial=None):
"Find USBTMC instrument"

Expand Down

0 comments on commit 4517092

Please sign in to comment.