2016-04-26 86 views
1

私はCANalyzerを開発中で、パラメータを含むCAPL関数を呼び出す方法が見つかりません。 numfunctions_call.Call(num)に入れても機能しません。PythonからCAPL関数を呼び出す

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

答えて

3

私はしばらく前に同様の問題に遭遇したといくつかのグーグルは、Vectorで、次のアプリケーションノートに私を導いた:

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

...精算セクション「2.7呼び出しCAPL関数」。 .eg、「長い」としてあなたCAPL関数のパラメータを宣言することを確認し、それを合計するには

:以下は私のために働くように見えた:

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

完了のために、これはどのように私です(上記の例)、Pythonコードは次のようになります。私はPythonでfunction1.Call(一部文字変数)に引数として文字を渡す場合

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) 
+1

私は好奇心を感じます。 CANoe CAPLを実行するためにPythonスクリプトを使用する目的は何ですか? –

+1

ユースケースによって異なります。 CANoeで実行されるCANシミュレーション、ターゲットに接続されたデバッガ、プログラム可能な電源、およびその他のカスタムハードウェアを含む、フルシステムテストのさまざまな部分を自動化するための一連のPython APIを使用します。いくつかのシナリオでは、Windows COMを使用してCANoeのあらゆる側面を制御することは時間がかかるだけでなく遅くなる可能性があるため、外部から呼び出すことができるCAPL「API」を作成することで多くの柔軟性が得られます。 – schaazzz

+1

さらに、シミュレーション用に特定の機能を実装している既存のCAPLスクリプトが既にある場合は、対応するユースケースがある場合は外部からそれぞれの関数を呼び出すこともできます(前のコメントで述べたシステムレベルのテストなど)。 ところで、それはPythonである必要はありません、それは_any_言語である可能性があります。考えられるのは、CANoeのシミュレーション全体を(VectorのCOM APIを使用して)外部から制御できることです。 – schaazzz

-1

、それは

File "C:\Python27\lib\site-packages\win32com\gen_py\4CB02FC0-4F33-11D3-854D-00105A3E017Bx0x1x31.py", line 1668, in Call , p7, p8, p9, p10) File "C:\Python27\lib\site-packages\win32com\client__init__.py", line 467, in ApplyTypes self.oleobj.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args), pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147352571), 10)

としてエラーをスロー

Python:

var = 'abc' 

count = 0 

while count < 10: 

    if (is_running): 

     function1.Call(var) 

     count += 1 

CAPL: 

void function1(char var1[]) 

{ 

    //Code 

} 
+1

これは質問に対する答えを提供しません。十分な[評判](https://stackoverflow.com/help/whats-reputation)があれば、[投稿にコメントする]ことができます(https://stackoverflow.com/help/privileges/comment)。代わりに、[質問者からの明確化を必要としない回答を提供する](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- i-do-代わりに)。 - [レビューから](/レビュー/低品質の投稿/ 18231430) – larsr

関連する問題