簡體   English   中英

從 Python 調用 CAPL 函數

[英]Call CAPL function from Python

我正在研究 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的function1.Call(一些char變量)中將char作為參數傳遞,它將拋出錯誤

文件“ C:\\ Python27 \\ lib \\ site-packages \\ win32com \\ gen_py \\ 4CB02FC0-4F33-11D3-854D-00105A3E017Bx0x1x31.py”,行1668,在Call,p7,p8,p9,p10中)文件“ C:\\ Python27 \\ lib \\ site-packages \\ win32com \\ client__init __。py“,位於ApplyTypes自身中的第467行。 oleobj .InvokeTypes(dispid,0,wFlags,retType,argTypes,* args),pywintypes.com_error:(-2147352567,'發生異常。',(0,None,None,None,0,-2147352571),10)

蟒蛇:

var = 'abc'

count = 0

while count < 10:

    if (is_running):

        function1.Call(var)

        count += 1

CAPL:

void function1(char var1[])

{

    //Code

}

暫無
暫無

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

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