winIDEA SDK
test_call.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2# (c) TASKING Germany GmbH, 2023
3#
4# This Python example demonstrates how to to connect to a target device, and
5# download a program, execute functions
6# on the target device, and how to call functions with parameters
7# of various data types in a list.
8
9import isystem.connect as ic
10
11
12winidea_id = ''
13
14
15def test_call():
16 connMgr = ic.ConnectionMgr()
17 connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
18
19 execCtrl = ic.CExecutionController(connMgr)
20 sessCtrl = ic.CSessionCtrl(connMgr)
21 sessCtrl.begin_program()
22
23 execCtrl.runUntilFunction('main')
24 execCtrl.waitUntilStopped()
25
26 print("Executing function 'fibonacci' via `call()` method...")
27 retVal = execCtrl.call("fibonacci", "12")
28 print(f"\tReturn value: {retVal}")
29 print(f"\tFunction prototpe: 'int fibonacci(int param)'")
30
31 print("Executing function 'return_smaller' via `call()` method...")
32 retVal = execCtrl.call("return_smaller", "123", "456")
33 print(f"\tReturn value: {retVal}")
34 print(f"\tFunction prototype: 'int return_smaller(int param1, int param2)'")
35
36 print("Executing function 'get_random' via `call()` method...")
37 retVal = execCtrl.call("get_random")
38 print(f"\tReturn value: {retVal}")
39 print(f"\tFunction prototype: 'int get_random(void)'")
40
41 # call with parameters in a list
42 params = ic.StrVector()
43 params.push_back('4')
44 params.push_back('5')
45 params.push_back('6')
46 params.push_back('6000')
47 params.push_back('1.62')
48 params.push_back('2.4')
49
50 print('sum_different_types(4, 5, 6, 6000, 1.62, 2.4) = ',
51 int(execCtrl.call('sum_different_types', params), 0))
52
53
54if __name__ == "__main__":
55 test_call()