Ejemplo n.º 1
0
def uart_param_config(name, baud_rate, data_bits, parity, stop_bits,
                      timestamp):
    """ Set uart bus parameter
            
            Args:
                baud_rate(int)   : UART baud rate
                data_bits(int)   : Data width 5/6/7/8
                parity_type(str) : parity type. "ODD"/"EVNE"/"NONE"
                stop_bits(float) : stop bit width. 1/2
                time_insert(str) : PL UART Insert timestamp Control, "TS"/"NONE"
            Returns:
                bool: True | False, True for success, False for adc read failed
    """
    try:
        uart = XObject.get_object(name)
        isok = True
        if utility.mount_on_fpga(uart.name):
            uart.disable()
            uart.enable()
            uart.config(baud_rate, data_bits, parity, stop_bits, timestamp)
        else:
            isok = uart.config(baud_rate, data_bits, parity, stop_bits)

        return isok
    except Exception as e:
        logger.error("the %s uart param config execute error:%s" %
                     (name, repr(e)))
        return False
Ejemplo n.º 2
0
 def __init__(self, uartname, port):
     super(UartServer, self).__init__()
     self._uartname = uartname
     self._port = port
     self._connect_socket = None
     self._uart_device = XObject.get_object(uartname)
     self._inputs = []
     self._total_net_size = 0
     self._total_uart_size = 0
     self._uart_stop = False
Ejemplo n.º 3
0
def uart_close(uart_id):
    try:
        uart = XObject.get_object(uart_id)
        if utility.mount_on_fpga(uart.name):
            uart.disable()
        else:
            uart.close()

        return True
    except Exception as e:
        logger.error("close  the %s uart error:%s" % (uart_id, repr(e)))
        return False
Ejemplo n.º 4
0
    def eval(self, name, method, *args, **kwargs):
        try:
            obj = XObject.get_object(name)
            func = getattr(obj, method)
            if args:
                result = func(*args)
            elif kwargs:
                result = func(**kwargs)
            else:
                result = func()
        except Exception:
            logger.warning("%s" % (traceback.format_exc()))

        return result
Ejemplo n.º 5
0
def write(profile, addr, data):
    """ write  a list data  by the defined profile
        
        Args:
            profile: Dictionary of the hardware profile.
            addr: which  addr will be write data in. 
            data: data type is list.
            
        Returns:
            bool: The return value. True for success, False otherwise.
            
        Raises:
            KeyError: If the key is invalid.
    """
    eeprom = XObject.get_object(profile['partno'], profile)
    return eeprom.write(addr, data)
Ejemplo n.º 6
0
def read(profile, addr, length):
    """ read  data  by the defined profile
        
        Args:
            profile: Dictionary of the hardware profile.
            addr: which  addr will be write data in. 
            length: Want to get the length of the data.
            
        Returns:
            list: success  return datas which beed  saved in a list. False otherwise.
            
        Raises:
            KeyError: If the key is invalid.
    """
    eeprom = XObject.get_object(profile['partno'], profile)
    return eeprom.read(addr, length)
Ejemplo n.º 7
0
def _init_uart():
    ret_value = True
    initconfig = Profile.get_initconfig()

    for name, param in initconfig['uart'].iteritems():
        try:
            obj = XObject.get_object(name)
            if obj is None:
                logger.boot("warning: can not find the %s uart object" %
                            (name))
                continue

            baudrate = int(param['baudrate'])
            databits = int(param['databits'])
            stopbits = int(param['stopbits'])
            parity = param['parity'].upper()
            if utility.mount_on_fpga(obj.name):
                timestamp = param['timestamp'].upper()
                obj.disable()
                obj.enable()
                ret = obj.config(baudrate, databits, parity, stopbits,
                                 timestamp)
            else:
                ret = obj.config(baudrate, databits, parity, stopbits)
            if ret is False:
                logger.boot("error: init the %s uart param:%s fail" %
                            (name, param))
                ret_value = False
            else:
                logger.boot("init the %s uart success, param:%s" %
                            (name, param))
        except Exception as e:
            logger.boot("error: %s _init_uart execute error:\n%s" %
                        (name, traceback.format_exc()))
            ret_value = False

    return ret_value
Ejemplo n.º 8
0
def test_get_class():
    from ee.profile.xobj import XObject
    #assert len(XObject._objects.keys()) == 24

    assert str(type(
        XObject.get_object("cp1"))) == "<class 'ee.chip.cat9555.CAT9555'>"
    assert str(type(
        XObject.get_object("cp2"))) == "<class 'ee.chip.cat9555.CAT9555'>"
    assert str(type(
        XObject.get_object("cp3"))) == "<class 'ee.chip.cat9555.CAT9555'>"
    assert str(type(
        XObject.get_object("cp4"))) == "<class 'ee.chip.cat9555.CAT9555'>"
    assert str(type(
        XObject.get_object("cp5"))) == "<class 'ee.chip.cat9555.CAT9555'>"
    assert str(type(
        XObject.get_object("cp6"))) == "<class 'ee.chip.cat9555.CAT9555'>"
    assert str(type(
        XObject.get_object("cp7"))) == "<class 'ee.chip.cat9555.CAT9555'>"
    assert str(type(
        XObject.get_object("cp8"))) == "<class 'ee.chip.cat9555.CAT9555'>"

    assert str(type(XObject.get_object(
        "dmm"))) == "<class 'ee.board.dmm001.dmm001001.Dmm001001'>"
    assert str(type(XObject.get_object("datalogger"))
               ) == "<class 'ee.board.scope002.scope002001A.Scope002001A'>"
    assert str(type(XObject.get_object(
        "freq"))) == "<class 'ee.board.vfreq001.vfreq001001.Vfreq001001'>"
    assert str(type(XObject.get_object(
        "voltage_output"))) == "<class 'ee.board.ins001.vvo001001.Vvo001001'>"