0

I would like to get the return data from a CAPL function called from python. Please help me with this.

Currently I can only call the function with parameter in the example .

from win32com import client
import pythoncom
import time

function1 = None
canoe_app = None
is_running = False

class EventHandler:

    def OnInit(self):
        global canoe_app
        global function1

        function1 = canoe_app.CAPL.GetFunction('Test1')

    def OnStart(self):
        global is_running
        is_running = True

canoe_app = client.Dispatch('CANoe.Application')
measurement = canoe_app.Measurement
measurement_events = client.WithEvents(measurement, EventHandler)
measurement.Start()


# The following loop takes care of any pending events and, once, the Measurement
# starts, it will call the CAPL function "function1" 10 times and then exit!
count = 0
while count < 10:
    if (is_running):
        ret = []
        function1.Call(count)
        function1.Call(count+1)
        print(ret)
        count += 1

    pythoncom.PumpWaitingMessages()
    time.sleep(1)

measurement.Stop()
  • One thing that you might do is to dump whatever result you'd like to transfer from the CAPL into a text file and have python read from that text file. – Daemon Painter Aug 31 '18 at 09:53
  • Please show us your CAPL function and tell us where do you use it. You can directly use the return value of the `CAPLFunction.Call` method for some cases. – dymanoid Sep 24 '18 at 08:28
  • The example you've quoted above is copied as is from https://stackoverflow.com/questions/36867122/call-capl-function-from-python/37068335. Have you tried to read through Vector help or tried anything your self at all? Because if you did, you would've realized that the "Call" method of the "CAPLFunction" object, returns the return value of the CAPL function being called. – schaazzz Sep 24 '18 at 16:11

1 Answers1

0

You just have to assign the calling statement to a variable.
var1 = (int)function1.Call(count)
Note that the return variable type should only be int.

Shyam
  • 649
  • 1
  • 5
  • 20