コード例 #1
0
ファイル: device.py プロジェクト: dieggo111/DBHandler
 def _open(self):
     if self._backend == 'pyVISA':
         self._port = visa.ResourceManager() \
                         .open_resource(self._connection['port'],
                                        write_termination=
                                        self._write_termination,
                                        read_termination=
                                        self._read_termination)
         # timeout has to be in ms
         self._port.timeout = float(self._connection.get('timeout',
                                                         5)) * 1000
     elif self._backend == 'linux-gpib':
         con = re.findall(r'\d+', self._connection['port'])
         self._port = gpib.dev(int(con[0]), int(con[1]))
     elif self._backend == 'pySerial':
         if not self._port.is_open:
             self._port.open()
     elif self._backend == 'pyDAQmx':
         pass
     elif self._backend in ['usbtmc', 'usbtmcWR']:
         self._port.open()
     elif self._backend == "file":
         file = Path(self._port)
         if not file.is_file():
             self.log.warning("Path ist not a file! Check your port settings in config file!")  #pylint: disable=line-too-long
     elif self._backend == "vxi11":
         self._port = vxi11.Instrument(self._connection["port"].replace(
             "vxi11://", ""))
     elif self._backend == "modbus":
         self._port.open()
コード例 #2
0
ファイル: instruments.py プロジェクト: madengr/usrp_rf_tests
    def __init__(self, address):
        """Initialize the object

        Keyword arguments:
        device -- GPIB address of the instrument
        """
        self.device = gpib.dev(0, address)
コード例 #3
0
ファイル: myGpib.py プロジェクト: umass-wares/wares
 def __init__(self,
              name='gpib0',
              pad=None,
              sad=0,
              timeout=gpib.T10s,
              send_eoi=1,
              eos_mode=0,
              eot=True):
     self._own = False
     self.name = None
     if isinstance(name, basestring):
         self.id = gpib.find(name)
         self.name = name
         self._own = True
     elif pad is None:
         self.id = name
     else:
         self.id = gpib.dev(name, pad, sad, timeout, send_eoi, eos_mode)
         self._own = True
     if eot:
         self.eot = True
     else:
         self.eot = False
     if self._own:
         self.get_status()
コード例 #4
0
 def __init__(self, serial_port=None, gpib_num=None, gpib_dev_num=None):
     assert serial_port or (gpib_num and gpib_dev_num)
     if gpib_num and gpib_dev_num:
         self._dev = gpib.dev(gpib_num, gpib_dev_num)
         self._gpib_used = True
     elif serial_port:
         self._dev = ser.Serial('/dev/'+serial_port, 38400)
         self._gpib_used = False
コード例 #5
0
 def initialize(self):
     self.handle = gpib.dev(0, self.port)
     #gpib.timeout(self.handle, 12)  # timeout T3s = 12; check help(gpib)
     print "GPIB::%d is initialized" % self.port
     print "GPIB handle = %d" % self.handle
     try:
         # Print IDN info if available
         self.query("*IDN?")
     except:
         pass
コード例 #6
0
ファイル: linuxgpib.py プロジェクト: lijunhw/instruments
 def initialize(self):
     self.handle = gpib.dev(0, self.port)
     #gpib.timeout(self.handle, 12)  # timeout T3s = 12; check help(gpib)
     print "GPIB::%d is initialized" % self.port
     print "GPIB handle = %d" % self.handle
     try: 
     # Print IDN info if available
         self.query("*IDN?")
     except:
         pass
コード例 #7
0
ファイル: Gpib.py プロジェクト: 9072997/wikireader
	def __init__(self, name = 'gpib0', pad = None, sad = 0, timeout = 13, send_eoi = 1, eos_mode = 0):
		self._own = False
		if isinstance(name, basestring):
			self.id = gpib.find(name)
			self._own = True
		elif pad is None:
			self.id = name
		else:
			self.id = gpib.dev(name, pad, sad, timeout, send_eoi, eos_mode)
			self._own = True
コード例 #8
0
ファイル: device.py プロジェクト: hewittc/mrgpib
 def __init__(self, name='gpib0', pad=None, sad=0, timeout=13, send_eoi=1, eos_mode=0):
     self._own = False
     try:
         if isinstance(name, basestring):
             self.id = gpib.find(name)
             self._own = True
         elif pad is None:
             self.id = name
         else:
             self.id = gpib.dev(name, pad, sad, timeout, send_eoi, eos_mode)
             self._own = True
     except gpib.GpibError as msg:
         print("error: could not open device ({name})".format(name=name))
         print("libgpib: {msg}".format(msg=msg))
         sys.exit(1)
コード例 #9
0
 def __init__(self,
              name='gpib0',
              pad=None,
              sad=0,
              timeout=13,
              send_eoi=1,
              eos_mode=0):
     self._own = False
     if isinstance(name, basestring):
         self.id = gpib.find(name)
         self._own = True
     elif pad is None:
         self.id = name
     else:
         self.id = gpib.dev(name, pad, sad, timeout, send_eoi, eos_mode)
         self._own = True
コード例 #10
0
	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!")
コード例 #11
0
ファイル: transport.py プロジェクト: openlabequipment/aqua
    def __init__(self, board=0, paddr=0, saddr=None, timeout='10s', send_eoi=True,
            eos_char=None, eos_mode=EOS_NONE):

        if not 0 <= paddr <= 30:
            raise ValueError("Primary address must be in [0, 30].")

        if saddr is not None and not 0 <= saddr <= 30:
            raise ValueError("Secondary address must be in [0, 30].")

        # linux-gpib uses the unfortunate NI convention of
        # adding 0x60 to the secondary address
        saddr = 0 if saddr is None else saddr + 0x60

        timeout = self.TIMEOUTS.index(timeout)

        eos = (eos_char or 0) | eos_mode

        self._handle = gpib.dev(board, paddr, saddr, timeout, send_eoi, eos)
コード例 #12
0
ファイル: gpib.py プロジェクト: lcarde/pymanip
def scanGpib(board):
    if not has_gpib:
        warnings.warn(
            "Linux-GPIB is not available. ScanGpib with VISA not implemented at the moment.",
            RuntimeWarning,
            stacklevel=2,
        )
    else:
        for pad in range(1, 31):
            listen = gpib.listener(board, pad)
            # print(board, pad, listen)
            if listen:
                print("GPIB" + str(board) + "::" + str(pad))
                try:
                    ud = gpib.dev(board, pad, 0, 10, 1, 0)
                    if ud > 0:
                        gpib.write(ud, "*CLS;*IDN?")
                        description = gpib.read(ud, 256)
                        print(description.strip().decode("ascii"))
                except Exception:
                    pass
コード例 #13
0
    def __init__(self, resource=14, timeDelay=10, numReadings=20, initDelay=1):
        try:
            self.resource = int(resource)
        except ValueError:
            print "Invalid resource (numerical values only)"
            return
        try:
            self.timeDelay = int(timeDelay)
            if self.timeDelay < 0:
                raise ValueError("Negative time delay setting is invalid!")
        except ValueError:
            # timeDelay negative or non-integer
            print "Invalid time delay. Setting default value of 10"
            self.timeDelay = 10

        try:
            self.numReadings = int(numReadings)
            if self.numReadings < 0:
                raise ValueError("Negative number of readings is invalid!")
        except ValueError:
            print "Invalid number of readings. Setting default value of 20"
            self.numReadings = 20

        try:
            self.initDelay = int(initDelay)
            if self.initDelay < 0:
                raise ValueError("Negative init delay setting is invalid!")
        except ValueError:
            # initDelay negative or non-integer
            print "Invalid init delay. Setting default value of 1"
            self.initDelay = 1

        self.con = gpib.dev(0, self.resource)
        self.mean = 0.
        self.std = 0.
        self.min = 0.
        self.max = 0.
コード例 #14
0
    return response


def initialise_device(handle):  # set up device to assert SRQ/RQS
    gpib.write(handle, "*CLS")  # Clear status registers
    gpib.write(handle, "*SRE 32")  # Assert SRQ on Event
    return


def show_devid(handle):  # Show device ID
    print query(handle, "*IDN?")
    return


print gpib.version()  # Show package version
ud = gpib.dev(board, device)  # Open the device
gpib.config(board, gpib.IbcAUTOPOLL, 1)  # Enable automatic serial polling
gpib.config(ud, gpib.IbcTMO, gpib.T30s)  # Set timeout to 30 seconds
show_devid(ud)
initialise_device(ud)
gpib.write(handle, "*TST;*OPC")  # Selftest and request OPC event
# Wait for Timeout or Request Service on device
sta = gpib.wait(ud, gpib.TIMO | gpib.RQS)
if (sta & gpib.TIMO) != 0:
    print "Timed out"
else:
    print "Device asserted RQS"
    stb = gpib.serial_poll(ud)  # Read status byte
    print "stb = %#x" % (stb)
    if (stb & gpib.IbStbESB) != 0:  # Check for Event Status bit
        esr = int(query(ud, "ESR?"))  # Read Event Status Register
コード例 #15
0
ファイル: gpib.py プロジェクト: DavidFabijan/pyvisa-py
 def after_parsing(self):
     minor = self.parsed.board
     pad = self.parsed.primary_address
     self.handle = gpib.dev(int(minor), int(pad))
     self.interface = Gpib(self.handle)
コード例 #16
0
def get_gpib_device(port: int, timeout=0.5):
    device = gpib.dev(0, port)
    gpib.timeout(device, get_gpib_timeout(timeout))
    return GpibInstrument(device)
コード例 #17
0
 def __init__(self, gpib_id_high, gpib_id_low):
     """Initialize the connection to oscilloscope using GPIB."""
     self.scope = gpib.dev(gpib_id_high, gpib_id_low)
     if DEBUG:
         print "DL1540 initialized"
         print(self.query("*IDN?"))
コード例 #18
0
 def __init__(self, gpib_num, gpib_dev_num, units='mW'):
     self._dev = gpib.dev(gpib_num, gpib_dev_num)
     self.set_power_units(units)
     self._sleep = 0.1
コード例 #19
0
	def __init__(self,gpib_address,card=0):

		self.device = gpib.dev(card,gpib_address)
コード例 #20
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 28 20:57:10 2018

@author: jonathan
"""

import gpib
import numpy as np

# GPIB interface 0, address 15
con = gpib.dev(0,15)

status = gpib.write(con, "COMM_FORMAT OFF")
#status = gpib.write(con, "COMM_FORMAT OFF,WORD,BIN")
status = gpib.write(con, "COMM_HEADER OFF")

status = gpib.write(con, "*IDN?")
deviceID = gpib.read(con, 1000).decode()
print("found device: " + deviceID)


# get template
print("fetching template")
status = gpib.write(con, "TEMPLATE?")
template = ""

chunk_size = 1024
keepFetching = True
while keepFetching:
コード例 #21
0
ファイル: model340.py プロジェクト: chgad/scientificdevices
 def __init__(self, address, board=0):
     self._dev = gpib.dev(board, address)
コード例 #22
0
ファイル: server.py プロジェクト: leszektarkowski/PAR273
 def __init__(self, addres):
     self.dev = gpib.dev(*addres)
     self.write('DD 13')
     self.write('TYPE Succesfull init"')
コード例 #23
0
    def __init__(self, address: int = 25):
        assert (1 <= address <= 32), 'address out of range'

        self._device_handler = gpib.dev(0, address)
        gpib.config(self._device_handler, gpib.IbaEOSrd, 1)
        gpib.config(self._device_handler, gpib.IbaEOSchar, 13)
コード例 #24
0
        iteration_duration = stop_iteration - start_iteration
        mah += c * iteration_duration.total_seconds() / -3.6
        wh += c * v * iteration_duration.total_seconds() / -3600
        if (stop_iteration -
                start_reporting).total_seconds() > reporting_period_sec:
            print('%.3f V %.3f A %d mAh %.3f Wh' % (v, c, mah, wh))
            start_reporting = stop_iteration
    send(ps, 'output off')
    stop = datetime.now()
    duration = stop - start
    print('Discharging done: %s' % (duration))
    print('Battery capacity: %d mAh %.3f Wh' % (mah, wh))


# init power supply
ps = gpib.dev(0, addr)
ps_id = query(ps, '*idn?')
print('Using power supply: ', ps_id)

parser = argparse.ArgumentParser()
parser.add_argument('-c', '--charge', nargs='?', const=True, default=False)
parser.add_argument('-d', '--discharge', nargs='?', const=True, default=False)

args = parser.parse_args()

if args.charge:
    charge()

if args.discharge:
    discharge(ps)
コード例 #25
0
 def __init__(self, addres):
     self.equipo = gpib.dev(0, addres)
     self.addres = addres
コード例 #26
0
    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!")
コード例 #27
0
 def __setConnection( self ):
   self.__interface = gpib.dev( self.__device, self.__address ) 
コード例 #28
0
ファイル: gpib.py プロジェクト: herm/pyvisa-py
 def after_parsing(self):
     minor = self.parsed.board
     pad = self.parsed.primary_address
     self.handle = gpib.dev(int(minor), int(pad))
     self.interface = Gpib(self.handle)
コード例 #29
0
#!/usr/bin/env python

import datetime
import signal
import sys
import time
import gpib

dc1 = gpib.dev(0, 1)  # Agilent 66332A on GPIB bus 0, address 1


# thanks to http://stackoverflow.com/questions/8600161/executing-periodic-actions-in-python
def do_every(period, count, f, *args):
    def g_tick():
        t = time.time()
        count = 0
        while True:
            count += 1
            yield max(t + count * period - time.time(), 0)

    g = g_tick()
    for i in range(count):
        time.sleep(next(g))
        f(*args)


t0 = None


def meas():
    gpib.write(dc1, 'MEAS:CURR?')
コード例 #30
0
 def __init__(self, gpib_num, gpib_dev_num):
     self._dev = gpib.dev(gpib_num, gpib_dev_num)