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 write(self, str, calls=0): try: gpib.write(self.id, str) self.last_write = str except gpib.GpibError: if calls == 2: Logging.error("Unrecoverable error. Please reboot") raw_input("Press ENTER when done.") exit(1) self.reset() self.write(str, calls=calls + 1)
def reset_interfaces(self, calls=0): if self.debug: Logging.info("Resetting connected interfaces") self.reset_usb() time.sleep(2) if self.debug: Logging.info("Running gpib_config") try: subprocess.check_call(["sudo", "gpib_config"]) except subprocess.CalledProcessError: if calls == 2: Logging.error("No interface connected") exit(1) self.reset_interfaces(calls=calls + 1) time.sleep(2)
def read(self, len=512, calls=0): try: result = gpib.read(self.id, len).rstrip("\n") except gpib.GpibError, e: Logging.warning(str(e)) if str(e) == "read() failed: A read or write of data bytes has been aborted, possibly due to a timeout or reception of a device clear command.": Logging.info("Last write didn't succeed. Resending...") self.reset() self.write(self.last_write) if calls == 2: Logging.error("Unrecoverable error. Please reboot") raw_input("Press ENTER when done.") exit(1) self.reset() result = self.read(calls=calls + 1)
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 read(self, len=512, calls=0): try: result = gpib.read(self.id, len).rstrip("\n") except gpib.GpibError, e: Logging.warning(str(e)) if str( e ) == "read() failed: A read or write of data bytes has been aborted, possibly due to a timeout or reception of a device clear command.": Logging.info("Last write didn't succeed. Resending...") self.reset() self.write(self.last_write) if calls == 2: Logging.error("Unrecoverable error. Please reboot") raw_input("Press ENTER when done.") exit(1) self.reset() result = self.read(calls=calls + 1)
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!")
import TermOut.Logging as Logging try: import gpib except ImportError: Logging.error("linux_gpib not installed or Python bindings not built") exit(1) from TermOut.ProgressBar import ProgressBar import os import subprocess import time import sys import Drivers.GPIB class GPIB: 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 = {}
#!/usr/bin/python import sys import os from TermOut import Logging import importlib if sys.platform == "win32": Logging.error("Windows is not supported.") exit(1) if len(sys.argv) == 2: if os.path.isfile(sys.argv[1]): import_path = os.path.dirname(sys.argv[1]) if import_path != "": sys.path.append(os.path.abspath(import_path)) os.chdir(import_path) importlib.import_module( os.path.basename(os.path.splitext(sys.argv[1])[0])) else: Logging.error("File does not exist") else: Logging.error("Specify python file as second argument")
""" Created by: Nico Leidenfrost, Philip Trauner Required software: - USBTMC: https://github.com/python-ivi/python-usbtmc - PyUSB: https://github.com/walac/pyusb """ import TermOut.Logging as Logging try: import usbtmc except ImportException: Logging.error("usbtmc not installed") exit(1) from TermOut.ProgressBar import ProgressBar import os import time import subprocess import sys import Drivers.USBTMC class USBTMC: 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 = {}
import TermOut.Logging as Logging try: import gpib except ImportError: Logging.error("linux_gpib not installed or Python bindings not built") exit(1) from TermOut.ProgressBar import ProgressBar import os import subprocess import time import sys import Drivers.GPIB class GPIB: 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)
""" Created by: Nico Leidenfrost, Philip Trauner Required software: - USBTMC: https://github.com/python-ivi/python-usbtmc - PyUSB: https://github.com/walac/pyusb """ import TermOut.Logging as Logging try: import usbtmc except ImportException: Logging.error("usbtmc not installed") exit(1) from TermOut.ProgressBar import ProgressBar import os import time import subprocess import sys import Drivers.USBTMC class USBTMC: 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
# Written for pyserial 3.X (update via pip if needed) import TermOut.Logging as Logging try: import serial except ImportError: Logging.error("pyserial not installed") exit(1) import io # suggested from pyserial developers to use for commands linke readline() from TermOut.ProgressBar import ProgressBar import os import time import sys import Drivers.Serial class Serial: 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):
# Written for pyserial 3.X (update via pip if needed) import TermOut.Logging as Logging try: import serial except ImportError: Logging.error("pyserial not installed") exit(1) import io # suggested from pyserial developers to use for commands linke readline() from TermOut.ProgressBar import ProgressBar import os import time import sys import Drivers.Serial class Serial: 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/"):