<commit_before>#
# ------------------------------------------------------------
# Copyright (c) All rights reserved
# SiLab, Institute of Physics, University of Bonn
# ------------------------------------------------------------
#
import visa

from basil.TL.TransferLayer import TransferLayer


class Visa(TransferLayer):

    '''Transfer layer for a Virtual Instrument Software Architecture (VISA) provided by pyVisa.
    Several interfaces are available (GPIB, RS232, USB, Ethernet). To be able to use pyVisa without
    the proprietary NI-VISA driver a pyVisa backend pyVisa-py is used.
    GPIB under linux is not supported via pyVisa-py right now and linux-gpib does not
    compile on modern kernels right now. Thus no GPIB linux support on modern systems.
    '''

    def __init__(self, conf):
        super(TransferLayer, self).__init__(conf)
        self._resource = None

    def init(self):
        '''
        Initialize the device.
        Parameters of visa.ResourceManager().open_resource()
        '''
        backend = self._init.pop('backend', '')
        rm = visa.ResourceManager(backend)
        print rm.list_resources()
        self._resource = rm.open_resource(**self._init)

    def close(self):
        pass
        #self._resource.close()

    def write(self, data):
        self._resource.write(data)

    def read(self):
        self._resource.read()<commit_msg>ENH: show all visa resources and the backend during init MAINT: activate correct device closing<commit_after>#
# ------------------------------------------------------------
# Copyright (c) All rights reserved
# SiLab, Institute of Physics, University of Bonn
# ------------------------------------------------------------
#
import visa
import logging

from basil.TL.TransferLayer import TransferLayer


class Visa(TransferLayer):

    '''Transfer layer for a Virtual Instrument Software Architecture (VISA) provided by pyVisa.
    Several interfaces are available (GPIB, RS232, USB, Ethernet). To be able to use pyVisa without
    the proprietary NI-VISA driver a pyVisa backend pyVisa-py is used.
    GPIB under linux is not supported via pyVisa-py right now and linux-gpib does not
    compile on modern kernels right now. Thus no GPIB linux support on modern systems.
    '''

    def __init__(self, conf):
        super(TransferLayer, self).__init__(conf)
        self._resource = None

    def init(self):
        '''
        Initialize the device.
        Parameters of visa.ResourceManager().open_resource()
        '''
        backend = self._init.pop('backend', '')
        rm = visa.ResourceManager(backend)
        try:
            logging.info('BASIL VISA TL with %s backend found the following devices: %s', backend, rm.list_resources())
        except NotImplementedError:  # some backends do not always implement the list_resources function
            logging.info('BASIL VISA TL instanciated with %s backend', backend)
        self._resource = rm.open_resource(**self._init)

    def close(self):
        self._resource.close()

    def write(self, data):
        self._resource.write(data)

    def read(self):
        self._resource.read()
{'fraction_non_alphanumeric': 0.1564582672167566, 'fraction_numerical': 0.001904157410345922, 'mean_word_length': 2.246138002059732, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3670976', 'n_tokens_mistral': 835, 'n_tokens_neox': 774, 'n_words': 285}