Unable to call CAPL Function

38 views Asked by At
Failed to select or prepare CAPL function: 'Check_msg': (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147418113), None)
Error details: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147418113), None)
CAPL function not selected or does not exist.

I tried this code to call the CAPL but I am getting the above error, Is there anything wrong I am doing ?

    def select_and_prepare_capl_function(self, functionName):
        """
        Selects and prepares a CAPL function for execution.
        """
        if self.application:
            try:
                # Clear existing CAPLFunction attribute
                self.CAPLFunction = None

                self.CAPLFunction = self.application.CAPL.GetFunction(functionName)
                self.CAPLFunction = win32.Dispatch(self.CAPLFunction)
            except pythoncom.com_error as e:
                print(f"Failed to select or prepare CAPL function '{functionName}': {e}")
                self.CAPLFunction = None
                print(f"Error details: {e.args}")  # Print detailed error information
        else:
            print("CANoe application not initialized.")

    def execute_capl_function(self, *args):
        if self.CAPLFunction:
            try:
                return self.CAPLFunction.Call(*args)
            except pythoncom.com_error as e:
                print(f"Failed to execute CAPL function: {e}")
                return None
        else:
            print("CAPL function not selected or does not exist.")
            return None
def main():
    app = CANoe()
    try:
        pythoncom.CoInitialize()
        app.application = win32.DispatchEx("CANoe.Application")
        ver = app.application.Version
        print('Loaded CANoe version ', ver.major, '.', ver.minor, '.', ver.Build)

        app.start_measurement()
        time.sleep(5)

        # Select and prepare CAPL function
        functionName = 'Check_msg'  # Replace with your actual CAPL function name
        app.select_and_prepare_capl_function(functionName)

        if app.CAPLFunction:
            # Example: Execute CAPL function with arguments
            # arg1 = 5
            # arg2 = 5
            result = app.execute_capl_function()
            print(f"CAPL function execution result: {result}")
        else:
            print("CAPL function not selected or does not exist.")

        time.sleep(5)
    except pythoncom.com_error as e:
        print(f"Error: {e}")
    finally:
        app.stop_measurement()

The CAPL code looks like this:

/*@!Encoding:1252*/
includes { }

variables { }

on start { 
  write("check it is working"); 
}

void Check_msg() {
  write("CAPL function check_msg called using Python");
  write("CCVS_IECU::Wheelbasedvehiclespeed=%f",$CCVS_IECU::Wheelbasedvehiclespeed); 
}

int multi(int x , int y, int z) { 
  z= x*y; 
  write("inside the multi"); 
  write("c value = %d", z); 
  return z; 
}
0

There are 0 answers