从Python调用CAPL函数

ala*_*rci 1 python capl

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

def call(num):
    print 'calling from CAN'
    x=int(num) 
    functions_call.Call()
    return 1
Run Code Online (Sandbox Code Playgroud)

sch*_*zzz 7

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

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

...检出部分“ 2.7调用CAPL函数”。

综上所述,请确保将您的CAPL函数的参数声明为“ long”,例如:以下似乎对我有用:

void function1(long l)
{
   write("function1() called with %d!", l);
}
Run Code Online (Sandbox Code Playgroud)

为了完整起见,这就是我的python代码(对于上面的示例)如下所示:

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)
Run Code Online (Sandbox Code Playgroud)

  • 我感到好奇。使用 python 脚本执行 CANoe CAPL 的目的是什么? (2认同)
  • 取决于用例。我使用一组Python API来自动化整个系统测试的不同部分,包括在CANoe中运行的CAN仿真,连接到目标的调试器,可编程电源和一些其他自定义硬件。在某些情况下,使用Windows COM控制CANoe的各个方面可能既繁琐又缓慢,因此,创建可在外部调用的CAPL“ API”具有很大的灵活性。 (2认同)