# Module to find all current VISA-compatible USB devices. #import visa as v #import visa_fake as v import find_visa_devices as fv import string as s ## Use PyVisa to find all visa-compatible devices on usb, com, lpt, gpib connections def FindVisaDevices() : # a is list of strings, one per instrument. Each string contains the connection, vendor id, model number and serial number. a = v.get_instruments_list() print('\nVISA devices found:') print('\t' + '\n\t'.join(a)) return a ## Find just the USB-connected devices def FindUSBDevices(write_log=False) : logfile = "log_visa_usb.txt" visa_devs = fv.FindVisaDevices(write_log) # Use FindVisaDevices function defined in find_visa_devices.py usb_devs = [] for dev in visa_devs : if dev.find('USB') > -1 : usb_dev = s.split(dev, '::') # Use the string module imported as s in the find_visa_devices module imported as fv. usb_devs.append(usb_dev[1:]) print('\nVISA USB devices found ( vendor id, product id, serial number):') for thing in usb_devs : print('\n\t' + ' '.join(thing)) if write_log : f = open(logfile, 'w') f.write('\nVISA USB devices found ( vendor id, product id, serial number):') for thing in usb_devs : f.write('\n\t' + ' '.join(thing)) f.close() print('\n' + logfile + ' written.') return usb_devs #------------------------------------------------------------------------------- if __name__ == '__main__' : #FindVisaDevices() usb = FindUSBDevices(write_log=True)