首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Python调用CAPL函数

从Python调用CAPL函数
EN

Stack Overflow用户
提问于 2016-04-26 21:57:56
回答 1查看 12.9K关注 0票数 4

我正在开发CANalyzer,但我找不到如何调用包含参数的CAPL函数。如果我把num放在functions_call.Call(num)中,它不能工作。

代码语言:javascript
复制
def call(num):
    print 'calling from CAN'
    x=int(num) 
    functions_call.Call()
    return 1
EN

回答 1

Stack Overflow用户

发布于 2016-05-06 17:02:31

不久前我遇到了类似的问题,一些谷歌搜索将我带到了Vector的以下应用笔记:

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

...checkout部分"2.7调用CAPL函数“。

总而言之,请确保将CAPL函数的参数声明为"long",.e.g:以下内容似乎适用于我:

代码语言:javascript
复制
void function1(long l)
{
   write("function1() called with %d!", l);
}

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

代码语言:javascript
复制
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)
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36867122

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档