从Python调用CAPL函数 [英] Call CAPL function from Python

查看:879
本文介绍了从Python调用CAPL函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CANalyzer,但找不到包含参数的CAPL函数的调用方法。如果我将 num 放入 functions_call.Call(num),则无效。

I'm working on CANalyzer and I can't find how to call a CAPL function wich contains a parameter. If I put num in functions_call.Call(num) it doesn't work.

def call(num):
    print 'calling from CAN'
    x=int(num) 
    functions_call.Call()
    return 1


推荐答案

我遇到了不久前出现了类似的问题,有些Google搜索将我引到了Vector的以下应用笔记:

I ran into a similar problem a while back and some Googling led me to the following application note by Vector:

http://vector.com/portal/medien/cmc/application_notes/AN-AND-1-117_CANoe_CANalyzer_as_a_COM_Server.pdf

...结帐部分 2.7调用CAPL函数。

...checkout section "2.7 Calling CAPL Functions".

总而言之,请确保将CAPL函数的参数声明为 long,例如:以下似乎对我有用:

To sum it up, make sure to declare your CAPL function's parameters as "long", .e.g: the following seemed to work for me:

void function1(long l)
{
   write("function1() called with %d!", l);
}

为了完整起见,这就是我的python代码(例如

For the sake of completion, this is how my python code (for the example above) looks like:

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

    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):
        function1.Call(count)
        count += 1

    pythoncom.PumpWaitingMessages()
    time.sleep(1)

这篇关于从Python调用CAPL函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆