<commit_before>#
# ------------------------------------------------------------
# Copyright (c) All rights reserved
# SiLab, Institute of Physics, University of Bonn
# ------------------------------------------------------------
#
# SVN revision information:
#  $Rev:: 261                   $:
#  $Author:: jejan              $:
#  $Date:: 2014-06-06 15:16:45 #$:
#
import logging

from basil.HL.HardwareLayer import HardwareLayer

from iseg_shq import IsegShqCom, status_words


class shq122m(HardwareLayer):
    '''Interface for ISEG SHQ 122M

    Example:
    --------
    hw_drivers:
      - name      : SHQ
        type      : shq122m
        interface : None
        init      :
            port            : \\.\COM5
            trip_current_ma : 0
            trip_current_ua : 0
            ramp_speed      : 2
    registers:
      - name      : HV
        type      : FunctionalRegister
        hw_driver : SHQ
        arg_names : [value]
        arg_add   : {'channel': 1}

    Usage:
    ------
    dut = basil.DUT(config.yaml)
    dut.init()
    dut['HV'].set_voltage(15)
    '''

    def __init__(self, intf, conf):
        super(shq122m, self).__init__(intf, conf)

    def init(self):
        self.iseg = IsegShqCom(port_num=self._init['port'])
        self.iseg.init_iseg()
        for ch in self.iseg.channel_list:
            # default values
            if 'trip_current_ma' in self._conf:
                self.iseg.write_i_trip_ma(channel=ch, current=self._init['trip_current_ma'])
            if 'trip_current_ua' in self._conf:
                self.iseg.write_i_trip_ua(channel=ch, current=self._init['trip_current_ua'])
            if 'ramp_speed' in self._conf:
                self.iseg.write_v_ramp(channel=ch, ramp_speed=self._init['ramp_speed'])
            self.trip_reset(channel=ch)

    def set_voltage(self, channel, value=0, unit='V', ramp_speed=None):
        if unit == 'raw':
            raw = value
        elif unit == 'V':
            raw = value
        elif unit == 'mV':
            raw = value * 0.001
        else:
            raise TypeError("Invalid unit type.")
        if ramp_speed:
            self.write_v_ramp(self, channel=channel, ramp_speed=ramp_speed)
        self.iseg.write_v_set(channel, raw)<commit_msg>ENH: update to latest pyISEG<commit_after>#
# ------------------------------------------------------------
# Copyright (c) All rights reserved
# SiLab, Institute of Physics, University of Bonn
# ------------------------------------------------------------
#
# SVN revision information:
#  $Rev:: 261                   $:
#  $Author:: jejan              $:
#  $Date:: 2014-06-06 15:16:45 #$:
#
import logging

from basil.HL.HardwareLayer import HardwareLayer

from iseg_shq_com import IsegShqCom, status_words


class IsegShq(HardwareLayer):
    '''Interface for ISEG SHQ series

    Example:
    --------
    hw_drivers:
      - name      : SHQ
        type      : iseg_shq
        interface : None
        init      :
            port            : COM1
            trip_current_ma : 0
            trip_current_ua : 0
            ramp_speed      : 2
    registers:
      - name      : HV
        type      : FunctionalRegister
        hw_driver : SHQ
        arg_names : [value]
        arg_add   : {'channel': 1}

    Usage:
    ------
    dut = basil.DUT(config.yaml)
    dut.init()
    dut['HV'].set_voltage(value=10.0)
    '''

    def __init__(self, intf, conf):
        super(IsegShq, self).__init__(intf, conf)

    def init(self):
        self.iseg = IsegShqCom(port_num=self._init['port'])
        self.iseg.init_iseg()
        for ch in self.iseg.channel_list:
            # default values
            if 'trip_current_ma' in self._conf:
                self.iseg.write_i_trip_ma(channel=ch, current=self._init['trip_current_ma'])
            if 'trip_current_ua' in self._conf:
                self.iseg.write_i_trip_ua(channel=ch, current=self._init['trip_current_ua'])
            if 'ramp_speed' in self._conf:
                self.iseg.write_v_ramp(channel=ch, ramp_speed=self._init['ramp_speed'])
            self.trip_reset(channel=ch)

    def set_voltage(self, channel, value=0, unit='V', ramp_speed=None):
        if unit == 'raw':
            raw = value
        elif unit == 'V':
            raw = value
        elif unit == 'mV':
            raw = value * 0.001
        else:
            raise TypeError("Invalid unit type.")
        if ramp_speed:
            self.write_v_ramp(self, channel=channel, ramp_speed=ramp_speed)
        self.iseg.write_v_set(channel, raw)
{'fraction_non_alphanumeric': 0.16044776119402984, 'fraction_numerical': 0.015583845478489903, 'mean_word_length': 1.625, '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': '5597763', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1383, 'n_words': 295}