python - 从 Python 调用 CAPL 函数

标签 python capl

我正在研究 CANalyzer,但找不到如何调用包含参数的 CAPL 函数。如果我将 num 放在 functions_call.Call(num) 中,它不起作用。

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

最佳答案

不久前我遇到了类似的问题,一些谷歌搜索让我找到了 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);
}

为了完成,这是我的 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)

关于python - 从 Python 调用 CAPL 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36867122/

相关文章:

python - scrapy获取当前url页面ref

type-conversion - 如何在 CAPL 中将十六进制字符串转换为字节数组?

python - 如何从 Python 3.x 调用 CAPL 通用函数?

CAPL 访问超过 52 位的整数信号

python - 使用 numpy 将 M*N 矩阵的每个 3x3 窗口求和为 M/3*N/3 矩阵

python - 捕获异常并显示自定义错误页面

python - 如何使用 Python 连接来自不同元组但位于同一索引中的两个字符串?

CAPL #include 相对路径

capl - 设置 Capl 函数 sysExecCmd 的相对路径

python - matplotlib 茎图中的彩色标签文本