winIDEA SDK
find_free_emulator.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5import isystem.connect as ic
6
7winidea_id = ''
8
9
10connectionMgr = ic.ConnectionMgr()
11
12# Let's connect to the currently running winIDEA. If no winIDEA
13# instance is running, one is started.
14connectionMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
15
16ideCtrl = ic.CIDEController(connectionMgr)
17debugCtrl = ic.CDebugFacade(connectionMgr)
18
19# It is enough to specify emulator's serial number only. winIDEA
20# then finds the right one.
21emulatorSerialNumbers = ['#84379']
22
23# emulators use TCP/IP mode. Other possible values for this option
24# are 'LPT', 'COM', and 'USB'
25ideCtrl.setOption('/IOPEN/Communication.Mode', 'TCP')
26
27isConnected = False
28for serialNumber in emulatorSerialNumbers:
29
30 ideCtrl.setOption('/IOPEN/Communication.IPAddress', serialNumber)
31
32 try:
33 debugCtrl.download()
34 isConnected = True
35 print('Found emulator with serial number: ', serialNumber)
36 break
37 except OSError:
38 print('Emulator with serial number ' + serialNumber + ' is not available.')
39
40
41if isConnected:
42 print('Connected!')
43else:
44 print('No free emulators found!')
45 # restore communication to USB if no free emulators found
46 ideCtrl.setOption('/IOPEN/Communication.Mode', 'USB')