【发布时间】: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 函数的返回值。