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, sad=0, timeout=13, send_eoi=1, eos_mode=0, debug=False, reset=False, interfaces=[]):
		if os.geteuid() != 0:
			Logging.error("You need to have root privileges to run this script.")
			self.started = False
			exit(1)
		self.debug = debug
		self.reset = reset
		self.devices = {}
		self.started = True
		self.drivers = {}
		# We go through each driver and look at the attribute DEVICES which contains all devices the driver should be loaded for.
		for i in dir(Drivers.GPIB):
			if i[0] != "_" and i != "GenericDriver":
				driver = getattr(Drivers.GPIB, 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)
		self.reset_usb_controller()
		# Interface ids are used to determine which usb connections need to be reset
		# Example:
		"""
		Bus 001 Device 006: ID 3923:709b National Instruments Corp. GPIB-USB-HS
		"""
		self.interfaces = ["3923:709b", "0957:0518"] + interfaces
		self.reset_interfaces()
		progress_bar = ProgressBar(30)
		discovered = {}
		for pad in range(0, 31):
			id = gpib.dev(0, pad, sad, timeout, send_eoi, eos_mode)
			try:
				driver_avaliable = False
				gpib.clear(id)
				gpib.write(id, "*IDN?")
				device_id = gpib.read(id, 1024).rstrip()
				for i in self.drivers:
					if i in device_id:
						self.devices[pad] = self.drivers[i](GPIBCommunicator(id, self.reset_interfaces), device_id)
						driver_avaliable = True
				if not driver_avaliable:
					self.devices[pad] = Drivers.GPIB.GenericDriver.GenericDriver(GPIBCommunicator(id, self.reset_interfaces), device_id)
				discovered[id] = device_id
			except gpib.GpibError:
				pass
			progress_bar.update(pad)
		for i in discovered:
			Logging.header("%s on %s" % (discovered[i], i - 16))
		Logging.success("Discovery finished successfully!")
    def __init__(self, debug=False, baud=19200, timeout=0.1, parity=serial.PARITY_EVEN, rtscts=True, dsrdtr=True):
        self.devices = {}
        self.drivers = {}
        self.debug = debug
        for i in dir(Drivers.Serial):
            if i[0] != "_" and i != "GenericDriver":
                    driver = getattr(Drivers.Serial, 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)
        dev_devices = []
        for dev_device in os.listdir("/dev/"):
            if "USB" in dev_device:   # Should be extended to also search for 'real' serial interfaces
                dev_devices.append(dev_device)
        progress_bar = ProgressBar(len(dev_devices))
        progress = 0
        device_number = 0
        for device in dev_devices:
            driver_avaliable = False
            
            ser = serial.Serial(port='/dev/' + device, baudrate=baud, bytesize=serial.EIGHTBITS, parity=serial.PARITY_EVEN, stopbits=serial.STOPBITS_ONE, timeout=timeout, xonxoff=False, rtscts=True, write_timeout=None, dsrdtr=None, inter_byte_timeout=None)

            ser.reset_input_buffer()
            ser.reset_output_buffer()
            
            inst = io.TextIOWrapper(io.BufferedRWPair(ser, ser, 1), newline=None, line_buffering = True, encoding='ascii') 
            time.sleep(1) # activation of serial interface does usually take some time
            
            # Asking for the device identifier
            inst.write(unicode('*IDN?\n'))
            time.sleep(0.1)
            ret = inst.readline()    
            device_id =ret.rstrip()

            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.Serial.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!")
예제 #4
0
 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,
                 sad=0,
                 timeout=13,
                 send_eoi=1,
                 eos_mode=0,
                 debug=False,
                 reset=False,
                 interfaces=[]):
        if os.geteuid() != 0:
            Logging.error(
                "You need to have root privileges to run this script.")
            self.started = False
            exit(1)
        self.debug = debug
        self.reset = reset
        self.devices = {}
        self.started = True
        self.drivers = {}
        # We go through each driver and look at the attribute DEVICES which contains all devices the driver should be loaded for.
        for i in dir(Drivers.GPIB):
            if i[0] != "_" and i != "GenericDriver":
                driver = getattr(Drivers.GPIB, 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)
        self.reset_usb_controller()
        # Interface ids are used to determine which usb connections need to be reset
        # Example:
        """
		Bus 001 Device 006: ID 3923:709b National Instruments Corp. GPIB-USB-HS
		"""
        self.interfaces = ["3923:709b", "0957:0518"] + interfaces
        self.reset_interfaces()
        progress_bar = ProgressBar(30)
        discovered = {}
        for pad in range(0, 31):
            id = gpib.dev(0, pad, sad, timeout, send_eoi, eos_mode)
            try:
                driver_avaliable = False
                gpib.clear(id)
                gpib.write(id, "*IDN?")
                device_id = gpib.read(id, 1024).rstrip()
                for i in self.drivers:
                    if i in device_id:
                        self.devices[pad] = self.drivers[i](GPIBCommunicator(
                            id, self.reset_interfaces), device_id)
                        driver_avaliable = True
                if not driver_avaliable:
                    self.devices[
                        pad] = Drivers.GPIB.GenericDriver.GenericDriver(
                            GPIBCommunicator(id, self.reset_interfaces),
                            device_id)
                discovered[id] = device_id
            except gpib.GpibError:
                pass
            progress_bar.update(pad)
        for i in discovered:
            Logging.header("%s on %s" % (discovered[i], i - 16))
        Logging.success("Discovery finished successfully!")
    def __init__(self,
                 debug=False,
                 baud=19200,
                 timeout=0.1,
                 parity=serial.PARITY_EVEN,
                 rtscts=True,
                 dsrdtr=True):
        self.devices = {}
        self.drivers = {}
        self.debug = debug
        for i in dir(Drivers.Serial):
            if i[0] != "_" and i != "GenericDriver":
                driver = getattr(Drivers.Serial, 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)
        dev_devices = []
        for dev_device in os.listdir("/dev/"):
            if "USB" in dev_device:  # Should be extended to also search for 'real' serial interfaces
                dev_devices.append(dev_device)
        progress_bar = ProgressBar(len(dev_devices))
        progress = 0
        device_number = 0
        for device in dev_devices:
            driver_avaliable = False

            ser = serial.Serial(port='/dev/' + device,
                                baudrate=baud,
                                bytesize=serial.EIGHTBITS,
                                parity=serial.PARITY_EVEN,
                                stopbits=serial.STOPBITS_ONE,
                                timeout=timeout,
                                xonxoff=False,
                                rtscts=True,
                                write_timeout=None,
                                dsrdtr=None,
                                inter_byte_timeout=None)

            ser.reset_input_buffer()
            ser.reset_output_buffer()

            inst = io.TextIOWrapper(io.BufferedRWPair(ser, ser, 1),
                                    newline=None,
                                    line_buffering=True,
                                    encoding='ascii')
            time.sleep(
                1
            )  # activation of serial interface does usually take some time

            # Asking for the device identifier
            inst.write(unicode('*IDN?\n'))
            time.sleep(0.1)
            ret = inst.readline()
            device_id = ret.rstrip()

            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.Serial.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!")