<commit_before>from Base_Driver import Base_Driver

import time

class m_DMM(Base_Driver):
    
    info = {
        # Model revision author
        'author':               'KKENNEDY',
        # Model version
        'version':              '1.0',
        # Revision date of Model version
        'date':                 '2015-01-31',
        # Device Manufacturer
        'deviceVendor':         'BK Precision',
        # List of compatible device models
        'deviceModel':          ['2831E', '5491B', '5492BGPIB', '5492B'],
        # Device type    
        'deviceType':           'Multimeter',      
        
        # List of compatible resource types
        'validResourceTypes':   ['VISA'],  
        
        #=======================================================================
        # VISA Attributes        
        #=======================================================================
        # Compatible VISA Manufacturers
        'VISA_compatibleManufacturers': [''],
        # Compatible VISA Models
        'VISA_compatibleModels':        ['2831E  Multimeter', 
                                         '5491B Digital Multimeter',
                                         '5492B Digital Multimeter']
    }
    
    modes = {
        'AC Voltage': 'VOLT:AC',
        'DC Voltage': 'VOLT:DC',
        'Resistance': 'RES',
        'AC Current': 'CURR:AC',
        'DC Current': 'CURR:DC',
        'Frequency': 'FREQ',
        'Period': 'PER',
        'Diode': 'DIOD',
        'Continuity': 'CONT' }
    
    def _onLoad(self):
        self.instr = self.getResource()
        
        self.func = self.getFunction()
    
    def _onUnload(self):
        pass
    
    def query(self, command):
        resp = str(self.instr.ask(command))
        self.logger.debug(resp)
        
        # Check that the SCPI header was not retuned
        ind = resp.find(command)
        if ind != -1:
            ind = ind + len(command)
            resp = resp[ind:]
            
        return resp
    
    def reset(self):
        """
        Reset the instrument
        """
        self.instr.write("*RST")
        
    def getError(self):
        """
        Gets the last error message from the device.
        
        :returns: str
        """
        return self.query(":SYS:ERR?")
        
    def enableFrontPanel(self):
        """
        Enables the front panel display if it was previously disabled.
        """
        self.instr.write(":DISP:ENAB 1")
        
    def disableFrontPanel(self):
        """
        Disables the front panel display. Display can be re-enabled by calling
        `enableFrontPanel` or pressing the `LOCAL` button on the instrument.
        
        .. note:
        
           When the front panel is disabled, the instrument runs faster
        
        """
        self.instr.write(":DISP:ENAB 0")

    def setMode(self, func):
        """
        Set the configuration mode
        
        Valid modes:
         
          * 'AC Voltage'
          * 'DC Voltage'
          * 'Resistance'
          * 'AC Current'
          * 'DC Current'
          * 'Frequency'
          * 'Period'
          * 'Diode'
          * 'Continuity'
          
        :param func: Configuration mode
        :type func: str
        """
        if func in self.modes:
            value = self.modes.get(func)
            self.instr.write(":FUNC %s" % self.value)
            
            self.func = self.getMode()
        else:
            raise RuntimeError("Invalid Function")
        
    def getMode(self):
        return self.query("FUNC?")
    
    def setFunction(self, value):
        """
        Alias for `setMode`
        """
        return self.setMode(value)
    
    def getFunction(self):
        """
        Alias for `getMode`
        """
        return self.getMode()
    def setRange(self, value):
        """
        Set the range for the measurement. The range is selected by specifying
        the expected reading as an absolute value. The instrument will then
        go to the most ideal range that will accomodate the expected reading
        
        Possible values for `value`:
        
           * 'MIN' or '0'
           * Number (see ranges below)
           * 'DEFAULT'
           * 'MAX'
           * 'AUTO'
           
        Expected value ranges:
        
           * DC Voltage: 0 to 1000 Volts
           * AC Voltage: 0 to 750 Volts
           * Current: 0 to 20 Amps
           * Resistance: 0 to 20e6 ohms
           * Frequency or Period: 0 to 1010 Volts
        
        :param value: Measurement Range
        :type value: str
        """
        if self.func in ['freq', 'per']:
            self.instr.write(":%s:THR:VOLT:RANG %s" % (self.func, value))
        else:
            if value in ['auto', 'AUTO']:
                self.instr.write(":%s:RANG:AUTO ON" % self.func)<commit_msg>Changes to BK Multimeter driver<commit_after>from Base_Driver import Base_Driver

import time

class m_DMM(Base_Driver):
    
    info = {
        # Model revision author
        'author':               'KKENNEDY',
        # Model version
        'version':              '1.0',
        # Revision date of Model version
        'date':                 '2015-01-31',
        # Device Manufacturer
        'deviceVendor':         'BK Precision',
        # List of compatible device models
        'deviceModel':          ['2831E', '5491B', '5492BGPIB', '5492B'],
        # Device type    
        'deviceType':           'Multimeter',      
        
        # List of compatible resource types
        'validResourceTypes':   ['VISA'],  
        
        #=======================================================================
        # VISA Attributes        
        #=======================================================================
        # Compatible VISA Manufacturers
        'VISA_compatibleManufacturers': [''],
        # Compatible VISA Models
        'VISA_compatibleModels':        ['2831E  Multimeter', 
                                         '5491B Digital Multimeter',
                                         '5492B Digital Multimeter']
    }
    
    modes = {
        'AC Voltage': 'VOLT:AC',
        'DC Voltage': 'VOLT:DC',
        'Resistance': 'RES',
        'AC Current': 'CURR:AC',
        'DC Current': 'CURR:DC',
        'Frequency': 'FREQ',
        'Period': 'PER',
        'Diode': 'DIOD',
        'Continuity': 'CONT' }
    
    def _onLoad(self):
        self.instr = self.getResource()
        self.instr.open()
        
        self.func = self.getFunction()
        
        self.logger.debug("Function: [%s]" % self.func)
    
    def _onUnload(self):
        self.instr.close()
        
    def getProperties(self):
        prop = Base_Driver.getProperties(self)
        
        prop['deviceVendor'] = self.info.get('deviceVendor')
        prop['deviceModel'] = self.instr.getVISA_model().split(' ')[0]
        
        return prop
    
    def query(self, command):
        resp = str(self.instr.query(command))
        resp = resp.strip() # Strip whitespace
        
        # Check that the SCPI header was not retuned
        ind = resp.find(command)
        if ind != -1:
            ind = ind + len(command)
            resp = resp[ind:]
            
        return resp
    
    def reset(self):
        """
        Reset the instrument
        """
        self.instr.write("*RST")
        
    def getError(self):
        """
        Gets the last error message from the device.
        
        :returns: str
        """
        return self.query(":SYS:ERR?")
        
    def enableFrontPanel(self):
        """
        Enables the front panel display if it was previously disabled.
        """
        self.instr.write(":DISP:ENAB 1")
        
    def disableFrontPanel(self):
        """
        Disables the front panel display. Display can be re-enabled by calling
        `enableFrontPanel` or pressing the `LOCAL` button on the instrument.
        
        .. note:
        
           When the front panel is disabled, the instrument runs faster
        
        """
        self.instr.write(":DISP:ENAB 0")

    def setMode(self, func):
        """
        Set the configuration mode
        
        Valid modes:
         
          * 'AC Voltage'
          * 'DC Voltage'
          * 'Resistance'
          * 'AC Current'
          * 'DC Current'
          * 'Frequency'
          * 'Period'
          * 'Diode'
          * 'Continuity'
          
        :param func: Configuration mode
        :type func: str
        """
        if func in self.modes:
            value = self.modes.get(func)
            self.instr.write(":FUNC %s" % self.value)
            
            self.func = self.getMode()
        else:
            raise RuntimeError("Invalid Function")
        
    def getMode(self):
        return self.query("FUNC?")
    
    def setFunction(self, value):
        """
        Alias for `setMode`
        """
        return self.setMode(value)
    
    def getFunction(self):
        """
        Alias for `getMode`
        """
        return self.getMode()
    
    def setRange(self, value):
        """
        Set the range for the measurement. The range is selected by specifying
        the expected reading as an absolute value. The instrument will then
        go to the most ideal range that will accomodate the expected reading
        
        Possible values for `value`:
        
           * 'MIN' or '0'
           * Number (see ranges below)
           * 'DEFAULT'
           * 'MAX'
           * 'AUTO'
           
        Expected value ranges:
        
           * DC Voltage: 0 to 1000 Volts
           * AC Voltage: 0 to 750 Volts
           * Current: 0 to 20 Amps
           * Resistance: 0 to 20e6 ohms
           * Frequency or Period: 0 to 1010 Volts
        
        :param value: Measurement Range
        :type value: str
        """
        if self.func in ['freq', 'per']:
            self.instr.write(":%s:THR:VOLT:RANG %s" % (self.func, value))
        else:
            if value in ['auto', 'AUTO']:
                self.instr.write(":%s:RANG:AUTO ON" % self.func)
{'fraction_non_alphanumeric': 0.1300708940527767, 'fraction_numerical': 0.012504923198109492, 'mean_word_length': 1.4664885866925692, 'pattern_counts': {'":': 12, '<': 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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '820233', 'n_tokens_mistral': 2857, 'n_tokens_neox': 2729, 'n_words': 757}