def __init__(self, debug=False): if os.geteuid() != 0: Logging.error("You need to have root privileges to run this script.") self.started = False exit(1) self.started = True self.devices = {} self.drivers = {} self.debug = debug for i in dir(Drivers.USBTMC): if i[0] != "_" and i != "GenericDriver": driver = getattr(Drivers.USBTMC, i) if hasattr(driver, "DEVICES"): self.drivers.update(driver.DEVICES) if self.debug: Logging.info("Drivers for following devices have been loaded: %s" % self.drivers) devices = usbtmc.list_devices() progress_bar = ProgressBar(len(devices)) progress = 0 device_number = 0 for device in devices: driver_avaliable = False inst = usbtmc.Instrument(device.idVendor, device.idProduct, device.serial_number) device_id = inst.ask("*IDN?") for i in self.drivers: if i in device_id: self.devices[device_number] = self.drivers[i](inst, device_id) driver_avaliable = True if not driver_avaliable: self.devices[device_number] = Drivers.USBTMC.GenericDriver.GenericDriver(inst, device_id) progress += 1 device_number += 1 progress_bar.update(progress) for i in self.devices: Logging.header("%s discovered on virtual port %s" % (self.devices[i].device_id, i)) Logging.success("Discovery finished successfully!")
def connect(self, address=None): """ Méthode pour établir la connection avec l'oscillo. Si la connection est établie, la fonction renvoie l'identité de l'oscilloscope. ---------- address : str Chaîne de caractères contenant l'addresse VISA de l'instrument. ---------- st : bool 'True' ou 'False' selon la résolution de la connection. """ if self.connection == 'usb': print(usbtmc.list_devices()) self.inst = usbtmc.Instrument(address) try: print(self.inst.ask('*IDN?')) except: print('Connection failed.') self.inst = False else: print('Connection succeed.')
def find(self, idProduct): deviceList = usbtmc.list_devices() while 0: device = deviceList.next() if idProduct == device.idProduct: return usbtmc.Instrument(device) if (debug): print "deviceList = ", deviceList deviceCount = len(deviceList) if (deviceCount == 0): print "There are no USBTMC devices attached or there is a driver problem" raise for device in deviceList: if idProduct == device.idProduct: return usbtmc.Instrument(device) continue try: if (debug): print "trying ", device handle = usbtmc.Instrument(device) reply = handle.ask("*IDN?") if (debug): print "Reply = ", reply if (pe.match(reply)): if (debug): print "Found match" return handle if (debug): print reply, " doesn't match ", regexp except OSError: if (debug): print "DEBUG: Unable to open ", device raise
def connect(self, idProduct=None, idVendor=None): """ if either idProduct or idVendor are None, query the user for what to connect to. """ if idProduct is None or idVendor is None: for dev in usbtmc.list_devices(): print("1: {} - {}".format(dev.manufacturer, dev.product)) dev_con = raw_input("Enter the number of the device you want to connect to: ") dev_chosen = usbtmc.list_devices()[int(dev_con) - 1] product_id = dev_chosen.idProduct vendor_id = dev_chosen.idVendor for dev in usbtmc.list_devices(): if dev.idProduct == product_id and dev.idVendor == vendor_id: if dev.is_kernel_driver_active(0): dev.detach_kernel_driver(0) instr = usbtmc.Instrument(vendor_id, product_id) return instr
def connect(self, idProduct=None, idVendor=None): """ if either idProduct or idVendor are None, query the user for what to connect to. """ if idProduct is None or idVendor is None: for dev in usbtmc.list_devices(): print("1: {} - {}".format(dev.manufacturer, dev.product)) dev_con = raw_input( "Enter the number of the device you want to connect to: ") dev_chosen = usbtmc.list_devices()[int(dev_con) - 1] product_id = dev_chosen.idProduct vendor_id = dev_chosen.idVendor for dev in usbtmc.list_devices(): if dev.idProduct == product_id and dev.idVendor == vendor_id: if dev.is_kernel_driver_active(0): dev.detach_kernel_driver(0) instr = usbtmc.Instrument(vendor_id, product_id) return instr
def __init__(self): """Open a connection to the oscilloscope and create interfaces for both channels.""" try: self.handle = usbtmc.Instrument(int(self.VID, 16), int(self.PID, 16)) self.handle.timeout = 5000 except USBError: devlist = usbtmc.list_devices() for dev in devlist: if dev.idProduct == int(self.PID, 16) and dev.idVendor == int(self.VID, 16): dev.reset() self.handle = usbtmc.Instrument(int(self.VID, 16), int(self.PID, 16)) break raise USBError('Unable to establish connection with oscilloscope.') print('Connected to Rigol oscilloscope as ' + repr(self.handle.device)) self.ch1 = self.Channel(1, self) self.ch2 = self.Channel(2, self)
def list_usb_devices(): '''List devices available via USB interface :returns: list of the devices connection-string (NI-VISA format). ''' resource_names = [] try: if _usbtmc_supported: devs = usbtmc.list_devices() for dev in devs: idVendor, idProduct, iSerial = None, None, None try: idVendor = dev.idVendor except: idVendor = None try: idProduct = dev.idProduct except: idProduct = None try: iSerial = dev.serial_number except: iSerial = None if idVendor is None or idProduct is None: continue if iSerial is None: resource_name = 'USB::0x{0:02x}::0x{1:02x}::INSTR'.format(idVendor, idProduct) resource_names.append(resource_name) else: resource_name = 'USB::0x{0:02x}::0x{1:02x}::{2}::INSTR'.format(idVendor, idProduct, iSerial) resource_names.append(resource_name) except: pass return resource_names
def __init__(self, debug=False): if os.geteuid() != 0: Logging.error( "You need to have root privileges to run this script.") self.started = False exit(1) self.started = True self.devices = {} self.drivers = {} self.debug = debug for i in dir(Drivers.USBTMC): if i[0] != "_" and i != "GenericDriver": driver = getattr(Drivers.USBTMC, i) if hasattr(driver, "DEVICES"): self.drivers.update(driver.DEVICES) if self.debug: Logging.info("Drivers for following devices have been loaded: %s" % self.drivers) devices = usbtmc.list_devices() progress_bar = ProgressBar(len(devices)) progress = 0 device_number = 0 for device in devices: driver_avaliable = False inst = usbtmc.Instrument(device.idVendor, device.idProduct, device.serial_number) device_id = inst.ask("*IDN?") for i in self.drivers: if i in device_id: self.devices[device_number] = self.drivers[i](inst, device_id) driver_avaliable = True if not driver_avaliable: self.devices[ device_number] = Drivers.USBTMC.GenericDriver.GenericDriver( inst, device_id) progress += 1 device_number += 1 progress_bar.update(progress) for i in self.devices: Logging.header("%s discovered on virtual port %s" % (self.devices[i].device_id, i)) Logging.success("Discovery finished successfully!")
def __init__(self): """Open a connection to the oscilloscope and create interfaces for both channels.""" try: self.handle = usbtmc.Instrument(int(self.VID, 16), int(self.PID, 16)) self.handle.timeout = 5000 except USBError: devlist = usbtmc.list_devices() for dev in devlist: if dev.idProduct == int(self.PID, 16) and dev.idVendor == int( self.VID, 16): dev.reset() self.handle = usbtmc.Instrument(int(self.VID, 16), int(self.PID, 16)) break raise USBError('Unable to establish connection with oscilloscope.') print('Connected to Rigol oscilloscope as ' + repr(self.handle.device)) self.ch1 = self.Channel(1, self) self.ch2 = self.Channel(2, self)
def main(): import usbtmc from .tektronix import Tektronix devices = usbtmc.list_devices() tek = Tektronix(devices[0]) app = qt.QApplication([]) win = QOscilloscope(tek) win.resize(1600, 600) win.setWindowTitle('Tektronix TDS 2014C') win.show() def update(): gevent.sleep(0.01) timer = qt.QTimer() timer.timeout.connect(update) timer.start(10) app.exec_()
def probe(idVendor=0x1bfa, idProduct=0x0498): """ see https://www.metrolab.com/products/thm1176/ """ log("USBTMC devices: " + str(usbtmc.list_devices())) # log("USBTMC resources: " + str(usbtmc.list_resources())) try: instr = usbtmc.Instrument(idVendor, idProduct) except usbtmc.usbtmc.UsbtmcException: msg = [] for cmd in [ "lsmod | grep usbtmc ", "lsusb | grep 'ID %s'" % (hex(idVendor)[2:]), "ls -l /dev/usbtmc*" ]: msg.append("`%s` returns %s" % (cmd, str(commandOutputFull(cmd)))) msg.append("\nProbe not found.") sys.exit("\n".join(msg)) settings(instr) return instr
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.dirname(CURRENT_DIR)) import time import usbtmc as backend import pyTHM1176.api.thm_usbtmc_api as thm_api import numpy as np params = {"trigger_type": "single", 'range': '0.1T', 'average': 30000, 'format': 'ASCII'} if __name__ == "__main__": thm = thm_api.Thm1176(backend.list_devices()[0], **params) # Get device id string and print output. This can be used to check communications are OK device_id = thm.get_id() for key in thm.id_fields: print('{}: {}'.format(key, device_id[key])) # Open grbl serial port s = serial.Serial('/dev/ttyACM0',115200) # Wake up grbl s.write(b"\r\n\r\n") time.sleep(2) # Wait for grbl to initialize s.flushInput() # Flush startup text in serial input w = 1
from RigolClass import RigolMult import usbtmc import time import numpy as np import serial port="/dev/ttyUSB0" arduino=serial.Serial(port,9600) #deteccion de multimetros dev=usbtmc.list_devices() instr1=RigolMult() instr2=RigolMult() instr1.instr=usbtmc.Instrument(dev[0]) instr2.instr=usbtmc.Instrument(dev[1]) str1=instr1.ID() alfa=str1[38] if(str1[38]=="9"): volt=instr1 res=instr2 else: volt=instr2 res=instr1 def paso(t): #funcion que deja correr el carrito por un tiempo t arduino.write(b"a") time.sleep(t) arduino.write(b"s") path="MedicionAutomatica1.0.csv"
def list_instruments(cls): devices = usbtmc.list_devices() return [USBDevice(dev) for dev in devices]
'block_size': 5, 'period': 1.0 / 20.0, 'range': '0.1T', 'average': 400, 'format': 'INTEGER' } item_name = ['Bx', 'By', 'Bz', 'Temperature'] labels = ['Bx', 'By', 'Bz', 'T'] curve_type = ['F', 'F', 'F', 'T'] to_show = [True, True, True, False] output_file = '~/desktop/test.dat' # You may want to change this to your desired file if BACKEND_CHOICE is 'usbtmc': thm = thm_api.Thm1176( backend.list_devices()[0], **params ) # You may want to ahve a smarter way of fetching the resource name elif BACKEND_CHOICE is 'pyVISA': resource = rm.list_resources()[0] print("Resource name: {}".format(resource)) thm_res = rm.open_resource(resource) thm = thm_api.Thm1176( thm_res, **params ) # You may want to ahve a smarter way of fetching the resource name data_stack = [] # list is thread safe # Get device id string and print output. This can be used to check communications are OK device_id = thm.get_id() for key in thm.id_fields: print('{}: {}'.format(key, device_id[key]))