py_canoe.core.capl.Capl

The CAPL object allows to compile all nodes (CAPL, .NET, XML) in the configuration. Additionally it represents the CAPL functions available in the CAPL programs. Please note that only user-defined CAPL functions can be accessed.

Source code in src\py_canoe\core\capl.py
16
17
18
def __init__(self, app: 'Application'):
    self.com_object = app.com_object.CAPL
    self.capl_function_objects = lambda: app.measurement.measurement_events.CAPL_FUNCTION_OBJECTS

compile_result property

Return the result of the last CAPL compilation as a CompileResult object.

call_capl_function(name, *arguments)

Call a CAPL function by name with the provided arguments. Returns True if the function was called successfully, False otherwise.

Source code in src\py_canoe\core\capl.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def call_capl_function(self, name: str, *arguments) -> bool:
    """Call a CAPL function by name with the provided arguments. Returns True if the function was called successfully, False otherwise."""
    try:
        capl_function = self.get_function(name)
        if capl_function:
            if len(arguments) != capl_function.parameter_count:
                logger.warning(f"Not enough arguments provided for CAPL function '{name}'.")
                return False
            else:
                if len(arguments) > 0:
                    capl_function.call(*arguments)
                else:
                    capl_function.call()
                return True
        else:
            logger.warning(f"CAPL function '{name}' not found.")
            return False
    except Exception as e:
        logger.error(f"Error calling CAPL function '{name}': {e}")
        return False

compile(wait_time=5)

Compile all CAPL nodes in the configuration and return the result as a CompileResult object. Optionally, specify a wait time (in seconds) for the compilation to complete.

Source code in src\py_canoe\core\capl.py
25
26
27
28
29
30
31
32
33
34
35
def compile(self, wait_time: Union[int, float] = 5) -> Union['CompileResult', None]:
    """Compile all CAPL nodes in the configuration and return the result as a CompileResult object. Optionally, specify a wait time (in seconds) for the compilation to complete."""
    try:
        self.com_object.Compile()
        wait(wait_time)
        compile_result = self.compile_result
        logger.info(f'compiled all CAPL nodes. result={compile_result.result}')
        return compile_result
    except Exception as e:
        logger.error(f"Error compiling CAPL nodes: {e}")
        return None

get_function(name)

Get CAPL function object by name. Returns a CaplFunction object if found, or None if not found.

Source code in src\py_canoe\core\capl.py
37
38
39
40
41
42
43
def get_function(self, name: str) -> Union['CaplFunction', None]:
    """Get CAPL function object by name. Returns a CaplFunction object if found, or None if not found."""
    if name in self.capl_function_objects():
        return self.capl_function_objects()[name]
    else:
        logger.warning(f'CAPL function "{name}" not found/registered.')
        return None