【问题标题】:How to get return value from a CAPL function called from python?如何从 python 调用的 CAPL 函数中获取返回值?
【发布时间】:2018-08-29 10:42:35
【问题描述】:

我想从 python 调用的 CAPL 函数中获取返回数据。 请帮我解决这个问题。

目前我只能调用示例中带参数的函数。

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()

【问题讨论】:

  • 您可能会做的一件事是将您想从 CAPL 传输的任何结果转储到文本文件中,然后让 python 从该文本文件中读取。
  • 请向我们展示您的 CAPL 函数并告诉我们您在哪里使用它。某些情况下可以直接使用CAPLFunction.Call方法的返回值。
  • 你上面引用的例子是从stackoverflow.com/questions/36867122/…复制而来的。您是否尝试过阅读 Vector 帮助或尝试过任何您自己的事情?因为如果你这样做了,你就会意识到“CAPLFunction”对象的“Call”方法会返回被调用的 CAPL 函数的返回值。

标签: python capl canoe


【解决方案1】:

您只需将调用语句分配给一个变量。
var1 = (int)function1.Call(count)
注意返回变量类型只能是int

【讨论】:

    猜你喜欢
    • 2018-03-31
    • 2013-10-24
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    • 2017-11-05
    • 2015-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多