How to use the pyvisa.ResourceManager function in PyVISA

To help you get started, we’ve selected a few PyVISA examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MDSplus / mdsplus / pydevices / HtsDevices / cryocon18i.py View on Github external
def trend(self):
        '''
        trend method for cryocon18i

        Store one sample for each of the channels that is on using
        putRow.  The timestamp will be time since the unix EPOCH in msec
        '''

        import pyvisa
        import MDSplus
        import time
        # open the instrument
        if self.debugging():
            print("about to open cryocon device %s" % str(self.node.data()))
        event_name = self.trend_event.data()
        rm = pyvisa.ResourceManager('@py')
        instrument = rm.open_resource('TCPIP::%s'% str(self.node.data()))
        chans = []
        t_chans = []
        resists = []
        temps = []
        query_cmd = ''
        for i in range(ord('a'), ord('i')):
            chan = self.__getattr__('input_%c'%(chr(i),))
            if chan.on:
                query_cmd = 'INP %c?;INP %c:SENP?;'%(chr(i), chr(i),)
                ans = instrument.query(query_cmd)[:-1].split(';')
                t_time=time.time()
                try:
                    temp = float(ans[0])
                except:
                    if self.debugging():
github scikit-rf / scikit-rf / skrf / vi / vna / abcvna.py View on Github external
-----------------
        visa_library : str
            allows pyvisa to use different visa_library backends, including the python-based pyvisa-py.
            backend which can handle SOCKET and Serial (though not GPIB) connections.  It should be possible
            to use this library without NI-VISA libraries installed if the analyzer is so configured.
        timeout : int
            milliseconds
        interface : str
            one of "SOCKET", "GPIB"
        card_number : int
            for GPIB, default is usually 0
        """

        rm = kwargs.get("resource_manager", None)
        if not rm:
            rm = pyvisa.ResourceManager(visa_library=kwargs.get("visa_library", ""))

        interface = str(kwargs.get("interface", None)).upper()  # GPIB, SOCKET
        if interface == "GPIB":
            board = str(kwargs.get("card_number", "")).upper()
            resource_string = "GPIB{:}::{:}::INSTR".format(board, address)
        elif interface == "SOCKET":
            port = str(kwargs.get("port", 5025))
            resource_string = "TCPIP0::{:}::{:}::SOCKET".format(address, port)
        else:
            resource_string = address
        self.resource = rm.open_resource(resource_string)  # type: pyvisa.resources.messagebased.MessageBasedResource
        self.resource.timeout = kwargs.get("timeout", 3000)

        self.resource.read_termination = "\n"  # most queries are terminated with a newline
        self.resource.write_termination = "\n"
        if "instr" in resource_string.lower():
github MDSplus / mdsplus / pydevices / HtsDevices / cryocon18i.py View on Github external
def query(self, cmd):
        import pyvisa
        rm = pyvisa.ResourceManager('@py')
        instrument = rm.open_resource('TCPIP::%s'% str(self.node.data()))
        answer = instrument.query(cmd)[:-1]
        print("cmd:%s\nans:%s"%(cmd,answer))
        return 1
    QUERY=query
github lab11 / powerblade / data_collection / multipoint_calibration / generate_calibration_curve.py View on Github external
powers = np.array([10, 50, 100, 500, 1000, 1500])

measurements = np.zeros((len(powers)*len(power_factors), 4))
measurement_list = []

# Parse args and get Chroma device
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--device", help="VISA device string to connect to")
parser.add_argument('addr', metavar='A', type=str, help='Address of the form XX:XX:XX:XX:XX:XX')
args = parser.parse_args()
addr = args.addr.lower()
device = None
if args.device is not None:
    device = args.device
else:
    rm = pyvisa.ResourceManager()
    resources = rm.list_resources()
    print("Select resource:")
    inst = None
    choice = -1
    while not (choice < len(resources) and choice >= 0):
        for i, resource in enumerate(resources):
            print(str(i+1) + '.', resource)
        choice = int(input("Selection: ")) - 1
        if not (choice < len(resources) and choice >= 0): print("Invalid selection")
        else:
            device = resources[choice]
chroma = Chroma63800(device, 20)

# Set up BLE scanning
class ScanDelegate(DefaultDelegate):
    def __init__(self):
github lab11 / powerblade / data_collection / multipoint_calibration / chroma63800.py View on Github external
def __init__(self, device, peak_current=10):
        self.rm = pyvisa.ResourceManager('@py')
        self.inst = self.rm.open_resource(device, write_termination='\n', read_termination='\n', baud_rate=57600)
        idn = self.inst.query('*IDN?')
        if 'Chroma' not in idn and '63802' not in idn:
            raise ValueError('You did not select a Chroma Load Emulator');
        self.set_ipmax(peak_current)
github Terrabits / rohdeschwarz / rohdeschwarz / bus / visa.py View on Github external
def open(self, connection_method = ConnectionMethod.tcpip, address = '127.0.0.1'):
        """
        Open instrument connection.
        Args:
            connection_method (ConnectionMethod(Enum) or str)
            address (str)
        Raises:
            VisaIOError: if instrument not found
        """
        resource_string = "{0}::{1}::INSTR".format(connection_method, address)
        rm = pyvisa.ResourceManager()
        instr = rm.open_resource(resource_string)
        self._instr = instr
        self._session = self._instr.session
        self._visa_lib = rm.visalib
github MDSplus / mdsplus / pydevices / HtsDevices / cryocon18i.py View on Github external
import datetime
        import time
        import numpy as np
        import MDSplus

        try:
            dt = 1./float(self.rate)
        except:
            dt = 1
        print("starting streamer for %s %s %s\nat: %s"%
              (self.tree, self.tree.shot, self.path, datetime.datetime.now()))
        event_name = self.data_event.data()
        seg_length = self.seg_length.data()

        # open the instrument
        rm = pyvisa.ResourceManager('@py')
        instrument = rm.open_resource('TCPIP::%s'% str(self.node.data()))

        # set up arrays of data and nodes to use in the loop
        seg_length = int(self.seg_length.data())
        max_segments = self.max_segments.data()
        r_chans = []
        t_chans = []
        resists = []
        temps = []
        times = np.zeros(seg_length)
        query_cmd = ''
        for i in range(ord('a'), ord('i')):
            chan = self.__getattr__('input_%c'%(chr(i),))
            if chan.on:
                temps.append(np.zeros(seg_length))
                resists.append(np.zeros(seg_length))
github scikit-rf / scikit-rf / skrf / vi / vna / vna.py View on Github external
def __init__(self, address=DEFAULT_VISA_ADDRESS, **kwargs):
        """
        :param address: a visa resource string
        :param kwargs: visa_library, timeout

        general and recommended way of initializing the visa resource.

        visa_library: pyvisa is a frontend that can use different visa_library backends, including the python-based
        pyvisa-py backend which can handle SOCKET (though not GPIB) connections.  It should be possible to use this
        library without NI-VISA libraries installed if the analyzer is so configured.

        FRONT-PANEL LOCKOUT: currently lockout is disabled.  Something to look at for the future
        """

        rm = pyvisa.ResourceManager(visa_library=kwargs.get("visa_library", ""))

        interface = str(kwargs.get("interface", None)).upper()  # GPIB, SOCKET
        if interface == "GPIB":
            board = str(kwargs.get("card_number", "")).upper()
            resource_string = "GPIB{:}::{:}::INSTR".format(board, address)
        elif interface == "SOCKET":
            port = str(kwargs.get("port", 5025))
            resource_string = "TCPIP0::{:}::{:}::SOCKET".format(address, port)
        else:
            resource_string = address
        self.resource = rm.open_resource(resource_string)  # type: pyvisa.resources.messagebased.MessageBasedResource
        self.resource.timeout = kwargs.get("timeout", 3000)

        self.resource.read_termination = "\n"  # most queries are terminated with a newline
        self.resource.write_termination = "\n"
        if "instr" in resource_string.lower():