<commit_before>"""
.. codeauthor:: <NAME> <<EMAIL>>

"""
from labtronyx.bases import DriverBase
from labtronyx.common.errors import *


class d_B29XX(DriverBase):
    """
    Driver for Agilent B2901A and B2902A Source Measurement Units
    """
    author = 'KKENNEDY'
    version = '1.0'
    deviceType = 'Source Measurement Unit'
    compatibleInterfaces = ['VISA']
    compatibleInstruments = {
        'Agilent': ['B2901A', 'B2902A']
    }

    @classmethod
    def VISA_validResource(cls, identity):
        return identity[0].upper() == 'AGILENT TECHNOLOGIES' and identity[1] in cls.compatibleInstruments['Agilent']

    VALID_SOURCE_OUTPUT_MODES = {
        'Voltage':       'VOLT',
        'Current':       'CURR'
    }

    VALID_MEASURE_MODES = {
        'Voltage':       'VOLT',
        'Current':       'CURR',
        'Resistance':    'RES'
    }

    VALID_SOURCE_MODES = {
        'Sweep': 'SWEEP',
        'Fixed': 'FIXED',
        'List':  'LIST'
    }

    VALID_TRIGGER_SOURCES = {
        'Automatic interval':   'AINT',
        'Remote':               'BUS',
        'Timer':                'TIM',
        'Internal bus 1':       'INT1',
        'Internal bus 2':       'INT2',
        'LXI':                  'LAN',
        'LAN (LXI) 0':          'LAN0',
        'LAN (LXI) 1':          'LAN1',
        'LAN (LXI) 2':          'LAN2',
        'LAN (LXI) 3':          'LAN3',
        'LAN (LXI) 4':          'LAN4',
        'LAN (LXI) 5':          'LAN5',
        'LAN (LXI) 6':          'LAN6',
        'LAN (LXI) 7':          'LAN7',
        'EXT0':                 'EXT0',
        'EXT1':                 'EXT1',
        'EXT2':                 'EXT2',
        'EXT3':                 'EXT3',
        'EXT4':                 'EXT4',
        'EXT5':                 'EXT5',
        'EXT6':                 'EXT6',
        'EXT7':                 'EXT7',
        'EXT8':                 'EXT8',
        'EXT9':                 'EXT9',
        'EXT10':                'EXT10',
        'EXT11':                'EXT11',
        'EXT12':                'EXT12',
        'EXT13':                'EXT13',
        'EXT14':                'EXT14'
    }

    # Instrument Constants
    MIN_APERTURE_TIME = 0.000008
    MAX_APERTURE_TIME = 2.0

    def open(self):
        prop = self.resource.getProperties()

        # Identify the number of channels available
        if prop.get('deviceModel') == 'B2901A':
            self.NUM_CHANNELS = 1
        elif prop.get('deviceModel') == 'B2902A':
            self.NUM_CHANNELS = 2
        else:
            self.NUM_CHANNELS = 1

        # Get the current device mode
        self._mode_source = {}
        self._mode_measure = {}
        for idx in range(1, self.NUM_CHANNELS + 1):
            self.getSourceOutputMode(idx)
            self.getMeasureMode(idx)

    def close(self):
        pass

    def getProperties(self):
        return dict(
            validModes=self.VALID_MODES,
            validTriggerSources=self.VALID_TRIGGER_SOURCES
        )

    def getError(self):
        """
        Get the last recorded error from the instrument

        :return: error code, error message
        """
        err = self.query(':SYST:ERR?')
        return err.split(',')

    def getErrors(self):
        """
        Retrieve any queued errors on the instrument

        :return:                list
        """
        # TODO: Replace with ERR:ALL on the real device, this is just for sim
        errors = [] # self.query(':SYST:ERR:ALL?')

        while True:
            err_num, err_msg = self.getError()
            if float(err_num) == 0:
                break
            else:
                errors.append((err_num, err_msg,))

        return errors

    def checkBusy(self):<commit_msg>Bug fix in SMU driver<commit_after>"""
.. codeauthor:: <NAME> <<EMAIL>>

"""
from labtronyx.bases import DriverBase
from labtronyx.common.errors import *


class d_B29XX(DriverBase):
    """
    Driver for Agilent B2901A and B2902A Source Measurement Units
    """
    author = 'KKENNEDY'
    version = '1.0'
    deviceType = 'Source Measurement Unit'
    compatibleInterfaces = ['VISA']
    compatibleInstruments = {
        'Agilent': ['B2901A', 'B2902A']
    }

    @classmethod
    def VISA_validResource(cls, identity):
        return identity[0].upper() == 'AGILENT TECHNOLOGIES' and identity[1] in cls.compatibleInstruments['Agilent']

    VALID_SOURCE_OUTPUT_MODES = {
        'Voltage':       'VOLT',
        'Current':       'CURR'
    }

    VALID_MEASURE_MODES = {
        'Voltage':       'VOLT',
        'Current':       'CURR',
        'Resistance':    'RES'
    }

    VALID_SOURCE_MODES = {
        'Sweep': 'SWEEP',
        'Fixed': 'FIXED',
        'List':  'LIST'
    }

    VALID_TRIGGER_SOURCES = {
        'Automatic interval':   'AINT',
        'Remote':               'BUS',
        'Timer':                'TIM',
        'Internal bus 1':       'INT1',
        'Internal bus 2':       'INT2',
        'LXI':                  'LAN',
        'LAN (LXI) 0':          'LAN0',
        'LAN (LXI) 1':          'LAN1',
        'LAN (LXI) 2':          'LAN2',
        'LAN (LXI) 3':          'LAN3',
        'LAN (LXI) 4':          'LAN4',
        'LAN (LXI) 5':          'LAN5',
        'LAN (LXI) 6':          'LAN6',
        'LAN (LXI) 7':          'LAN7',
        'EXT0':                 'EXT0',
        'EXT1':                 'EXT1',
        'EXT2':                 'EXT2',
        'EXT3':                 'EXT3',
        'EXT4':                 'EXT4',
        'EXT5':                 'EXT5',
        'EXT6':                 'EXT6',
        'EXT7':                 'EXT7',
        'EXT8':                 'EXT8',
        'EXT9':                 'EXT9',
        'EXT10':                'EXT10',
        'EXT11':                'EXT11',
        'EXT12':                'EXT12',
        'EXT13':                'EXT13',
        'EXT14':                'EXT14'
    }

    # Instrument Constants
    MIN_APERTURE_TIME = 0.000008
    MAX_APERTURE_TIME = 2.0

    def open(self):
        prop = self.resource.getProperties()

        # Identify the number of channels available
        if prop.get('deviceModel') == 'B2901A':
            self.NUM_CHANNELS = 1
        elif prop.get('deviceModel') == 'B2902A':
            self.NUM_CHANNELS = 2
        else:
            self.NUM_CHANNELS = 1

        # Get the current device mode
        self._mode_source = {}
        self._mode_measure = {}
        for idx in range(1, self.NUM_CHANNELS + 1):
            self.getSourceOutputMode(idx)
            self.getMeasureMode(idx)

    def close(self):
        pass

    def getProperties(self):
        return dict(
            validSourceModes=self.VALID_SOURCE_MODES,
            validMeasureModes=self.VALID_MEASURE_MODES,
            validTriggerSources=self.VALID_TRIGGER_SOURCES
        )

    def getError(self):
        """
        Get the last recorded error from the instrument

        :return: error code, error message
        """
        err = self.query(':SYST:ERR?')
        return err.split(',')

    def getErrors(self):
        """
        Retrieve any queued errors on the instrument

        :return:                list
        """
        # TODO: Replace with ERR:ALL on the real device, this is just for sim
        errors = [] # self.query(':SYST:ERR:ALL?')

        while True:
            err_num, err_msg = self.getError()
            if float(err_num) == 0:
                break
            else:
                errors.append((err_num, err_msg,))

        return errors

    def checkBusy(self):
{'fraction_non_alphanumeric': 0.12643073279831601, 'fraction_numerical': 0.027627943691619524, 'mean_word_length': 1.4264283434407916, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '224155', 'n_tokens_mistral': 2516, 'n_tokens_neox': 2340, 'n_words': 526}