簡體   English   中英

如何從從python調用的CAPL函數中獲取返回值?

[英]How to get return value from a CAPL function called from python?

我想從 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()

您只需要將調用語句分配給一個變量。
var1 = (int)function1.Call(count)
請注意,返回變量類型應僅為int

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM