Esempio n. 1
0
    def send_point(self, pdefs, func_def_path, point_name, point_value, step_number):
        """
            Send a point to outstation. Check for validation.

        :param pdefs: point definitions
        :param func_def_path: path to function definition
        :param point_name: name of the point that will be sent
        :param point_value: value of the point that will be sent
        :param step_number: step number of the point that will be sent
        """
        pdef = pdefs.point_named(point_name)
        if not pdef:
            raise MesaMasterTestException("Point definition not found: {}".format(point_name))

        if not pdef.point_type:
            raise MesaMasterTestException("Unrecognized point type: {}".format(pdef.point_type))

        step_def = FunctionDefinitions(pdefs, func_def_path).step_definition_for_point(pdef)
        if step_number != step_def.step_number:
            raise MesaMasterTestException("Step not in order: {}".format(step_number))

        if type(point_value) == list:
            self.send_array(point_value, pdef)
        else:
            fdefs = FunctionDefinitions(pdefs, function_definitions_path=func_def_path)
            step_def = fdefs.step_definition_for_point(pdef)
            send_func = self.SEND_FUNCTIONS.get(step_def.fcodes[0] if step_def.fcodes else DIRECT_OPERATE, None)
            if not send_func:
                raise MesaMasterTestException("Unrecognized function code")

            if pdef.point_type in POINT_TYPE_TO_PYTHON_TYPE and \
                    type(point_value) not in POINT_TYPE_TO_PYTHON_TYPE[pdef.point_type]:
                raise MesaMasterTestException("Invalid point value: {}".format(pdef.name))

            self.send_command(send_func, pdef, point_value)
def test_function_definitions():
    point_definitions = PointDefinitions(point_definitions_path=POINT_DEFINITIONS_PATH)
    fdefs = FunctionDefinitions(point_definitions, function_definitions_path=FUNCTION_DEFINITIONS_PATH)

    fd = fdefs.function_for_id("curve")
    print(fd)

    pdef = point_definitions.get_point_named("DCHD.WinTms (out)")
    print(pdef)
    print(fdefs.step_definition_for_point(pdef))
def test_function_definitions():
    point_definitions = PointDefinitions(
        point_definitions_path=POINT_DEFINITIONS_PATH)
    fdefs = FunctionDefinitions(
        point_definitions, function_definitions_path=FUNCTION_DEFINITIONS_PATH)

    fd = fdefs.function_for_id("curve")
    print(fd)

    pdef = point_definitions.get_point_named("DCHD.WinTms (out)")
    print(pdef)
    print(fdefs.step_definition_for_point(pdef))
Esempio n. 4
0
    def send_point(self, pdefs, func_def_path, point_name, point_value,
                   step_number):
        """
            Send a point to outstation. Check for validation.

        :param pdefs: point definitions
        :param func_def_path: path to function definition
        :param point_name: name of the point that will be sent
        :param point_value: value of the point that will be sent
        :param step_number: step number of the point that will be sent
        """
        pdef = pdefs.point_named(point_name)
        if not pdef:
            raise MesaMasterTestException(
                "Point definition not found: {}".format(point_name))

        if not pdef.point_type:
            raise MesaMasterTestException("Unrecognized point type: {}".format(
                pdef.point_type))

        step_def = FunctionDefinitions(
            pdefs, func_def_path).step_definition_for_point(pdef)
        if step_number != step_def.step_number:
            raise MesaMasterTestException(
                "Step not in order: {}".format(step_number))

        if type(point_value) == list:
            self.send_array(point_value, pdef)
        else:
            fdefs = FunctionDefinitions(
                pdefs, function_definitions_path=func_def_path)
            step_def = fdefs.step_definition_for_point(pdef)
            send_func = self.SEND_FUNCTIONS.get(
                step_def.fcodes[0] if step_def.fcodes else DIRECT_OPERATE,
                None)
            if not send_func:
                raise MesaMasterTestException("Unrecognized function code")

            if pdef.point_type in POINT_TYPE_TO_PYTHON_TYPE and \
                    type(point_value) not in POINT_TYPE_TO_PYTHON_TYPE[pdef.point_type]:
                raise MesaMasterTestException("Invalid point value: {}".format(
                    pdef.name))

            self.send_command(send_func, pdef, point_value)