py_canoe 3.0.2__py3-none-any.whl → 3.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
py_canoe/__init__.py CHANGED
@@ -1,2503 +1 @@
1
- # import external modules here
2
- import os
3
- import time
4
- import logging
5
- import pythoncom
6
- import win32com.client
7
- from typing import Union
8
- from datetime import datetime
9
-
10
- # import internal modules here
11
- from .py_canoe_logger import PyCanoeLogger
12
-
13
-
14
- class PyCanoeException(Exception):
15
- def __init__(self, message):
16
- self.message = message
17
-
18
- def __str__(self):
19
- return self.message
20
-
21
- class CANoe:
22
- """
23
- Represents a CANoe instance.
24
- Args:
25
- py_canoe_log_dir (str): The path for the CANoe log file. Defaults to an empty string.
26
- user_capl_functions (tuple): A tuple of user-defined CAPL function names. Defaults to an empty tuple.
27
- """
28
- CANOE_APPLICATION_OPENED = False
29
- CANOE_APPLICATION_CLOSED = False
30
- CANOE_MEASUREMENT_STARTED = False
31
- CANOE_MEASUREMENT_STOPPED = False
32
-
33
- def __init__(self, py_canoe_log_dir='', user_capl_functions=tuple()):
34
- self.__log = PyCanoeLogger(py_canoe_log_dir).log
35
- self.application_events_enabled = True
36
- self.application_open_close_timeout = 60
37
- self.simulation_events_enabled = False
38
- self.measurement_events_enabled = True
39
- self.measurement_start_stop_timeout = 60 # default value set to 60 seconds (1 minute)
40
- self.configuration_events_enabled = False
41
- self.__user_capl_functions = user_capl_functions
42
-
43
- def __init_canoe_application(self):
44
- self.__log.debug('➖'*50)
45
- pythoncom.CoInitialize()
46
- wait(0.5)
47
- self.application_com_obj = win32com.client.Dispatch('CANoe.Application')
48
- self.wait_for_canoe_app_to_open = lambda: DoMeasurementEventsUntil(lambda: CANoe.CANOE_APPLICATION_OPENED, lambda: self.application_open_close_timeout)
49
- self.wait_for_canoe_app_to_close = lambda: DoMeasurementEventsUntil(lambda: CANoe.CANOE_APPLICATION_CLOSED, lambda: self.application_open_close_timeout)
50
- if self.application_events_enabled:
51
- win32com.client.WithEvents(self.application_com_obj, CanoeApplicationEvents)
52
- wait(0.5)
53
-
54
- def __init_canoe_application_bus(self):
55
- self.bus_com_obj = win32com.client.Dispatch(self.application_com_obj.Bus)
56
- self.bus_databases = win32com.client.Dispatch(self.bus_com_obj.Databases)
57
- self.bus_nodes = win32com.client.Dispatch(self.bus_com_obj.Nodes)
58
-
59
- def __init_canoe_application_capl(self):
60
- self.capl_obj = lambda: CanoeCapl(self.application_com_obj)
61
-
62
- def __init_canoe_application_configuration(self):
63
- self.configuration_com_obj = win32com.client.Dispatch(self.application_com_obj.Configuration)
64
- if self.configuration_events_enabled:
65
- win32com.client.WithEvents(self.configuration_com_obj, CanoeConfigurationEvents)
66
- self.configuration_offline_setup = win32com.client.Dispatch(self.configuration_com_obj.OfflineSetup)
67
- self.configuration_offline_setup_source = win32com.client.Dispatch(self.configuration_offline_setup.Source)
68
- self.configuration_offline_setup_source_sources = win32com.client.Dispatch(self.configuration_offline_setup_source.Sources)
69
- sources = self.configuration_offline_setup_source_sources
70
- sources_count = sources.Count + 1
71
- self.configuration_offline_setup_source_sources_paths = lambda: [sources.Item(index) for index in range(1, sources_count)]
72
- self.configuration_online_setup = win32com.client.Dispatch(self.configuration_com_obj.OnlineSetup)
73
- self.configuration_online_setup_bus_statistics = win32com.client.Dispatch(self.configuration_online_setup.BusStatistics)
74
- self.configuration_online_setup_bus_statistics_bus_statistic = lambda bus_type, channel: win32com.client.Dispatch(self.configuration_online_setup_bus_statistics.BusStatistic(bus_type, channel))
75
- self.configuration_general_setup = CanoeConfigurationGeneralSetup(self.configuration_com_obj)
76
- self.configuration_simulation_setup = lambda: CanoeConfigurationSimulationSetup(self.configuration_com_obj)
77
- self.__replay_blocks = self.configuration_simulation_setup().replay_collection.fetch_replay_blocks()
78
- self.configuration_test_setup = lambda: CanoeConfigurationTestSetup(self.configuration_com_obj)
79
- self.__test_setup_environments = self.configuration_test_setup().test_environments.fetch_all_test_environments()
80
- self.__test_modules = list()
81
- for te_name, te_inst in self.__test_setup_environments.items():
82
- for tm_name, tm_inst in te_inst.get_all_test_modules().items():
83
- self.__test_modules.append({'name': tm_name, 'object': tm_inst, 'environment': te_name})
84
-
85
- def __init_canoe_application_environment(self):
86
- self.environment_obj_inst = CanoeEnvironment(self.application_com_obj)
87
-
88
- def __init_canoe_application_measurement(self):
89
- CanoeMeasurementEvents.application_com_obj = self.application_com_obj
90
- CanoeMeasurementEvents.user_capl_function_names = self.__user_capl_functions
91
- self.measurement_com_obj = win32com.client.Dispatch(self.application_com_obj.Measurement)
92
- self.wait_for_canoe_meas_to_start = lambda: DoMeasurementEventsUntil(lambda: CANoe.CANOE_MEASUREMENT_STARTED, lambda: self.measurement_start_stop_timeout)
93
- self.wait_for_canoe_meas_to_stop = lambda: DoMeasurementEventsUntil(lambda: CANoe.CANOE_MEASUREMENT_STOPPED, lambda: self.measurement_start_stop_timeout)
94
- if self.measurement_events_enabled:
95
- win32com.client.WithEvents(self.measurement_com_obj, CanoeMeasurementEvents)
96
-
97
- def __init_canoe_application_networks(self):
98
- self.networks_com_obj = win32com.client.Dispatch(self.application_com_obj.Networks)
99
- self.networks_obj = lambda: CanoeNetworks(self.networks_com_obj)
100
- self.__diag_devices = self.networks_obj().fetch_all_diag_devices()
101
-
102
- def __init_canoe_application_simulation(self):
103
- pass
104
-
105
- def __init_canoe_application_system(self):
106
- self.system_com_obj = win32com.client.Dispatch(self.application_com_obj.System)
107
- self.system_obj = lambda: CanoeSystem(self.system_com_obj)
108
-
109
- def __init_canoe_application_ui(self):
110
- self.ui_com_obj = win32com.client.Dispatch(self.application_com_obj.UI)
111
- self.ui_write_window_com_obj = win32com.client.Dispatch(self.ui_com_obj.Write)
112
-
113
- def __init_canoe_application_version(self):
114
- self.version_com_obj = win32com.client.Dispatch(self.application_com_obj.Version)
115
-
116
- def new(self, auto_save=False, prompt_user=False) -> None:
117
- try:
118
- self.__init_canoe_application()
119
- self.application_com_obj.New(auto_save, prompt_user)
120
- self.__log.debug(f'📢 New CANoe configuration successfully created 🎉')
121
- except Exception as e:
122
- error_message = f'😡 Error creating new CANoe configuration: {str(e)}'
123
- self.__log.error(error_message)
124
- raise PyCanoeException(error_message)
125
-
126
- def open(self, canoe_cfg: str, visible=True, auto_save=True, prompt_user=False, auto_stop=True) -> None:
127
- """Loads CANoe configuration.
128
-
129
- Args:
130
- canoe_cfg (str): The complete path for the CANoe configuration.
131
- visible (bool): True if you want to see CANoe UI. Defaults to True.
132
- auto_save (bool, optional): A boolean value that indicates whether the active configuration should be saved if it has been changed. Defaults to True.
133
- prompt_user (bool, optional): A boolean value that indicates whether the user should intervene in error situations. Defaults to False.
134
- auto_stop (bool, optional): A boolean value that indicates whether to stop the measurement before opening the configuration. Defaults to True.
135
- """
136
- try:
137
- self.__init_canoe_application()
138
- self.__init_canoe_application_measurement()
139
- self.__init_canoe_application_simulation()
140
- self.__init_canoe_application_version()
141
- self.application_com_obj.Visible = visible
142
- if self.measurement_com_obj.Running and not auto_stop:
143
- raise PyCanoeException('Measurement is running. Stop the measurement or set argument auto_stop=True')
144
- elif self.measurement_com_obj.Running and auto_stop:
145
- self.__log.warning('😇 Active Measurement is running. Stopping measurement before opening your configuration')
146
- self.stop_ex_measurement()
147
- if os.path.isfile(canoe_cfg):
148
- self.__log.debug('⏳ waiting for application to open')
149
- self.application_com_obj.Open(canoe_cfg, auto_save, prompt_user)
150
- self.wait_for_canoe_app_to_open()
151
- self.__init_canoe_application_bus()
152
- self.__init_canoe_application_capl()
153
- self.__init_canoe_application_configuration()
154
- self.__init_canoe_application_environment()
155
- self.__init_canoe_application_networks()
156
- self.__init_canoe_application_system()
157
- self.__init_canoe_application_ui()
158
- self.__log.debug(f'📢 CANoe configuration successfully opened 🎉')
159
- else:
160
- raise PyCanoeException(f'CANoe configuration "{canoe_cfg}" not found')
161
- except Exception as e:
162
- error_message = f'😡 Error opening CANoe configuration: {str(e)}'
163
- self.__log.error(error_message)
164
- raise PyCanoeException(error_message)
165
-
166
- def quit(self):
167
- """Quits CANoe without saving changes in the configuration."""
168
- try:
169
- wait(0.5)
170
- self.__log.debug('⏳ waiting for application to quit')
171
- self.application_com_obj.Quit()
172
- self.wait_for_canoe_app_to_close()
173
- wait(0.5)
174
- pythoncom.CoUninitialize()
175
- self.application_com_obj = None
176
- self.__log.debug('📢 CANoe Application Closed')
177
- except Exception as e:
178
- error_message = f'😡 Error quitting CANoe application: {str(e)}'
179
- self.__log.error(error_message)
180
- raise PyCanoeException(error_message)
181
-
182
- def start_measurement(self, timeout=60) -> bool:
183
- """Starts the measurement.
184
-
185
- Args:
186
- timeout (int, optional): measurement start/stop event timeout in seconds. Defaults to 60.
187
-
188
- Returns:
189
- True if measurement started. else False.
190
- """
191
- try:
192
- meas_run_sts = {True: "Started 🏃‍♂️", False: "Not Started 🧍‍♂️"}
193
- self.measurement_start_stop_timeout = timeout
194
- if self.measurement_com_obj.Running:
195
- self.__log.warning(f'⚠️ CANoe Measurement already running 🏃‍♂️')
196
- else:
197
- self.measurement_com_obj.Start()
198
- if not self.measurement_com_obj.Running:
199
- self.__log.debug(f'⏳ waiting for measurement to start')
200
- self.wait_for_canoe_meas_to_start()
201
- self.__log.debug(f'👉 CANoe Measurement {meas_run_sts[self.measurement_com_obj.Running]}')
202
- return self.measurement_com_obj.Running
203
- except Exception as e:
204
- error_message = f'😡 Error starting measurement: {str(e)}'
205
- self.__log.error(error_message)
206
- raise PyCanoeException(error_message)
207
-
208
- def stop_measurement(self, timeout=60) -> bool:
209
- """Stops the measurement.
210
-
211
- Args:
212
- timeout (int, optional): measurement start/stop event timeout in seconds. Defaults to 60.
213
-
214
- Returns:
215
- True if measurement stopped. else False.
216
- """
217
- return self.stop_ex_measurement(timeout)
218
-
219
- def stop_ex_measurement(self, timeout=60) -> bool:
220
- """StopEx repairs differences in the behavior of the Stop method on deferred stops concerning simulated and real mode in CANoe.
221
-
222
- Args:
223
- timeout (int, optional): measurement start/stop event timeout in seconds. Defaults to 60.
224
-
225
- Returns:
226
- True if measurement stopped. else False.
227
- """
228
- try:
229
- meas_run_sts = {True: "Not Stopped 🏃‍♂️ ", False: "Stopped 🧍‍♂️"}
230
- self.measurement_start_stop_timeout = timeout
231
- if self.measurement_com_obj.Running:
232
- self.measurement_com_obj.Stop()
233
- if self.measurement_com_obj.Running:
234
- self.__log.debug(f'⏳ waiting for measurement to stop 🧍‍♂️')
235
- self.wait_for_canoe_meas_to_stop()
236
- self.__log.debug(f'👉 CANoe Measurement {meas_run_sts[self.measurement_com_obj.Running]}')
237
- else:
238
- self.__log.warning(f'⚠️ CANoe Measurement already stopped 🧍‍♂️')
239
- return not self.measurement_com_obj.Running
240
- except Exception as e:
241
- error_message = f'😡 Error stopping measurement: {str(e)}'
242
- self.__log.error(error_message)
243
- raise PyCanoeException(error_message)
244
-
245
- def reset_measurement(self) -> bool:
246
- """reset(stop and start) the measurement.
247
-
248
- Returns:
249
- Measurement running status(True/False).
250
- """
251
- try:
252
- self.stop_measurement()
253
- self.start_measurement()
254
- self.__log.debug(f'👉 active measurement resetted 🔁')
255
- return self.measurement_com_obj.Running
256
- except Exception as e:
257
- error_message = f'😡 Error resetting measurement: {str(e)}'
258
- self.__log.error(error_message)
259
- raise PyCanoeException(error_message)
260
-
261
- def get_measurement_running_status(self) -> bool:
262
- """Returns the running state of the measurement.
263
-
264
- Returns:
265
- True if The measurement is running.
266
- False if The measurement is not running.
267
- """
268
- return self.measurement_com_obj.Running
269
-
270
- def add_offline_source_log_file(self, absolute_log_file_path: str) -> bool:
271
- """this method adds offline source log file.
272
-
273
- Args:
274
- absolute_log_file_path (str): absolute path of offline source log file.
275
-
276
- Returns:
277
- bool: returns True if log file added or already available. False if log file not available.
278
- """
279
- try:
280
- if os.path.isfile(absolute_log_file_path):
281
- offline_sources_paths = self.configuration_offline_setup_source_sources_paths()
282
- file_already_added = any([file == absolute_log_file_path for file in offline_sources_paths])
283
- if file_already_added:
284
- self.__log.warning(f'⚠️ File "{absolute_log_file_path}" already added as offline source')
285
- else:
286
- self.configuration_offline_setup_source_sources.Add(absolute_log_file_path)
287
- self.__log.debug(f'📢 File "{absolute_log_file_path}" added as offline source')
288
- return True
289
- else:
290
- self.__log.error(f'😡 invalid logging file ({absolute_log_file_path})')
291
- return False
292
- except Exception as e:
293
- self.__log.error(f'😡 Error adding offline source log file: {str(e)}')
294
- return False
295
-
296
- def start_measurement_in_animation_mode(self, animation_delay=100) -> None:
297
- """Starts the measurement in Animation mode.
298
-
299
- Args:
300
- animation_delay (int): The animation delay during the measurement in Offline Mode.
301
- """
302
- try:
303
- self.measurement_com_obj.AnimationDelay = animation_delay
304
- self.measurement_com_obj.Animate()
305
- self.__log.debug(f'⏳ waiting for measurement to start 🏃‍♂️')
306
- self.wait_for_canoe_meas_to_start()
307
- self.__log.debug(f"👉 started 🏃‍♂️ measurement in Animation mode with animation delay ⏲️ {animation_delay}")
308
- except Exception as e:
309
- self.__log.error(f'😡 Error starting measurement in animation mode: {str(e)}')
310
-
311
- def break_measurement_in_offline_mode(self) -> None:
312
- """Interrupts the playback in Offline mode."""
313
- try:
314
- if self.measurement_com_obj.Running:
315
- self.measurement_com_obj.Break()
316
- self.__log.debug('👉 measurement interrupted 🫷 in Offline mode')
317
- else:
318
- self.__log.warning('⚠️ Measurement is not running')
319
- except Exception as e:
320
- self.__log.error(f'😡 Error interrupting measurement in Offline mode: {str(e)}')
321
-
322
- def reset_measurement_in_offline_mode(self) -> None:
323
- """Resets the measurement in Offline mode."""
324
- try:
325
- self.measurement_com_obj.Reset()
326
- self.__log.debug('👉 measurement resetted 🔁 in Offline mode')
327
- except Exception as e:
328
- self.__log.error(f'😡 Error resetting measurement in Offline mode: {str(e)}')
329
-
330
- def step_measurement_event_in_single_step(self) -> None:
331
- """Processes a measurement event in single step."""
332
- try:
333
- self.measurement_com_obj.Step()
334
- self.__log.debug('👉 Processed a measurement event in single step 👣')
335
- except Exception as e:
336
- self.__log.error(f'😡 Error stepping measurement in Single Step mode: {str(e)}')
337
-
338
- def get_measurement_index(self) -> int:
339
- """gets the measurement index for the next measurement.
340
-
341
- Returns:
342
- Measurement Index.
343
- """
344
- try:
345
- meas_index = self.measurement_com_obj.MeasurementIndex
346
- self.__log.debug(f'👉 measurement_index value = {meas_index}')
347
- return meas_index
348
- except Exception as e:
349
- self.__log.error(f'😡 Error getting measurement index: {str(e)}')
350
- return -1
351
-
352
- def set_measurement_index(self, index: int) -> int:
353
- """sets the measurement index for the next measurement.
354
-
355
- Args:
356
- index (int): index value to set.
357
-
358
- Returns:
359
- Measurement Index value.
360
- """
361
- try:
362
- self.measurement_com_obj.MeasurementIndex = index
363
- self.__log.debug(f'👉 measurement_index value set to {index}')
364
- return index
365
- except Exception as e:
366
- self.__log.error(f'😡 Error setting measurement index: {str(e)}')
367
- return -1
368
-
369
- def save_configuration(self) -> bool:
370
- """Saves the configuration.
371
-
372
- Returns:
373
- True if configuration saved. else False.
374
- """
375
- try:
376
- if not self.configuration_com_obj.Saved:
377
- self.configuration_com_obj.Save()
378
- self.__log.debug('💾 configuration saved successfully')
379
- else:
380
- self.__log.debug('😇 configuration already saved')
381
- return self.configuration_com_obj.Saved
382
- except Exception as e:
383
- self.__log.error(f'😡 Error saving configuration: {str(e)}')
384
- return False
385
-
386
- def save_configuration_as(self, path: str, major: int, minor: int, prompt_user=False, create_dir=True) -> bool:
387
- """Saves the configuration as a different CANoe version.
388
-
389
- Args:
390
- path (str): The complete file name.
391
- major (int): The major version number of the target version.
392
- minor (int): The minor version number of the target version.
393
- create_dir (bool): create directory if not available. default value True.
394
-
395
- Returns:
396
- True if configuration saved. else False.
397
- """
398
- try:
399
- config_path = '\\'.join(path.split('\\')[:-1])
400
- if not os.path.exists(config_path) and create_dir:
401
- os.makedirs(config_path, exist_ok=True)
402
- if os.path.exists(config_path):
403
- self.configuration_com_obj.SaveAs(path, major, minor, prompt_user)
404
- if self.configuration_com_obj.Saved:
405
- self.__log.debug(f'💾 configuration saved as {path} successfully')
406
- return True
407
- else:
408
- self.__log.error(f'😡 Error saving configuration as {path}')
409
- return False
410
- else:
411
- self.__log.error(f'😡 file path {config_path} not found')
412
- return False
413
- except Exception as e:
414
- self.__log.error(f'😡 Error saving configuration as: {str(e)}')
415
- return False
416
-
417
- def get_can_bus_statistics(self, channel: int) -> dict:
418
- """Returns CAN Bus Statistics.
419
-
420
- Args:
421
- channel (int): The channel of the statistic that is to be returned.
422
-
423
- Returns:
424
- CAN bus statistics.
425
- """
426
- try:
427
- bus_types = {'CAN': 1, 'J1939': 2, 'TTP': 4, 'LIN': 5, 'MOST': 6, 'Kline': 14}
428
- can_bus_statistic_obj = self.configuration_online_setup_bus_statistics_bus_statistic(bus_types['CAN'], channel)
429
- statistics_info = {
430
- 'bus_load': can_bus_statistic_obj.BusLoad,
431
- 'chip_state': can_bus_statistic_obj.ChipState,
432
- 'error': can_bus_statistic_obj.Error,
433
- 'error_total': can_bus_statistic_obj.ErrorTotal,
434
- 'extended': can_bus_statistic_obj.Extended,
435
- 'extended_total': can_bus_statistic_obj.ExtendedTotal,
436
- 'extended_remote': can_bus_statistic_obj.ExtendedRemote,
437
- 'extended_remote_total': can_bus_statistic_obj.ExtendedRemoteTotal,
438
- 'overload': can_bus_statistic_obj.Overload,
439
- 'overload_total': can_bus_statistic_obj.OverloadTotal,
440
- 'peak_load': can_bus_statistic_obj.PeakLoad,
441
- 'rx_error_count': can_bus_statistic_obj.RxErrorCount,
442
- 'standard': can_bus_statistic_obj.Standard,
443
- 'standard_total': can_bus_statistic_obj.StandardTotal,
444
- 'standard_remote': can_bus_statistic_obj.StandardRemote,
445
- 'standard_remote_total': can_bus_statistic_obj.StandardRemoteTotal,
446
- 'tx_error_count': can_bus_statistic_obj.TxErrorCount,
447
- }
448
- self.__log.debug(f'👉 CAN Bus Statistics info = {statistics_info}')
449
- return statistics_info
450
- except Exception as e:
451
- self.__log.error(f'😡 Error getting CAN Bus Statistics: {str(e)}')
452
- return {}
453
-
454
- def get_canoe_version_info(self) -> dict:
455
- """The Version class represents the version of the CANoe application.
456
-
457
- Returns:
458
- "full_name" - The complete CANoe version.
459
- "name" - The CANoe version.
460
- "build" - The build number of the CANoe application.
461
- "major" - The major version number of the CANoe application.
462
- "minor" - The minor version number of the CANoe application.
463
- "patch" - The patch number of the CANoe application.
464
- """
465
- try:
466
- version_info = {'full_name': self.version_com_obj.FullName,
467
- 'name': self.version_com_obj.Name,
468
- 'build': self.version_com_obj.Build,
469
- 'major': self.version_com_obj.major,
470
- 'minor': self.version_com_obj.minor,
471
- 'patch': self.version_com_obj.Patch}
472
- self.__log.debug('> CANoe Application.Version info<'.center(50, '➖'))
473
- for k, v in version_info.items():
474
- self.__log.debug(f'{k:<10}: {v}')
475
- self.__log.debug(''.center(50, '➖'))
476
- return version_info
477
- except Exception as e:
478
- self.__log.error(f'😡 Error getting CANoe version info: {str(e)}')
479
- return {}
480
-
481
- def get_bus_databases_info(self, bus: str) -> dict:
482
- """returns bus database info(path, channel, full_name).
483
-
484
- Args:
485
- bus (str): bus (str): The Bus(CAN, LIN, FlexRay, MOST, AFDX, Ethernet) on which the signal is sent.
486
-
487
- Returns:
488
- bus database info {'path': 'value', 'channel': 'value', 'full_name': 'value'}
489
- """
490
- try:
491
- dbcs_info = dict()
492
- app_bus_databases_obj = win32com.client.Dispatch(self.application_com_obj.GetBus(bus).Databases)
493
- for item in app_bus_databases_obj:
494
- database_obj = win32com.client.Dispatch(item)
495
- dbcs_info[database_obj.Name] = {
496
- 'path': database_obj.Path,
497
- 'channel': database_obj.Channel,
498
- 'full_name': database_obj.FullName
499
- }
500
- self.__log.debug(f'👉 {bus} bus databases info = {dbcs_info}')
501
- return dbcs_info
502
- except Exception as e:
503
- self.__log.error(f'😡 Error getting {bus} bus databases info: {str(e)}')
504
- return {}
505
-
506
- def get_bus_nodes_info(self, bus: str) -> dict:
507
- """returns bus nodes info(path, full_name, active).
508
-
509
- Args:
510
- bus (str): bus (str): The Bus(CAN, LIN, FlexRay, MOST, AFDX, Ethernet) on which the signal is sent.
511
-
512
- Returns:
513
- bus nodes info {'path': 'value', 'full_name': 'value', 'active': 'value'}
514
- """
515
- try:
516
- nodes_info = dict()
517
- app_bus_nodes_obj = win32com.client.Dispatch(self.application_com_obj.GetBus(bus).Nodes)
518
- for item in app_bus_nodes_obj:
519
- node_obj = win32com.client.Dispatch(item)
520
- nodes_info[node_obj.Name] = {
521
- 'path': node_obj.Path,
522
- 'full_name': node_obj.FullName,
523
- 'active': node_obj.Active
524
- }
525
- self.__log.debug(f'👉 {bus} bus nodes info = {nodes_info}')
526
- return nodes_info
527
- except Exception as e:
528
- self.__log.error(f'😡 Error getting {bus} bus nodes info: {str(e)}')
529
- return {}
530
-
531
- def get_signal_value(self, bus: str, channel: int, message: str, signal: str, raw_value=False) -> Union[int, float, None]:
532
- """get_signal_value Returns a Signal value.
533
-
534
- Args:
535
- bus (str): The Bus(CAN, LIN, FlexRay, MOST, AFDX, Ethernet) on which the signal is sent.
536
- channel (int): The channel on which the signal is sent.
537
- message (str): The name of the message to which the signal belongs.
538
- signal (str): The name of the signal.
539
- raw_value (bool): return raw value of the signal if true. Default(False) is physical value.
540
-
541
- Returns:
542
- signal value.
543
- """
544
- try:
545
- signal_obj = self.application_com_obj.GetBus(bus).GetSignal(channel, message, signal)
546
- signal_value = signal_obj.RawValue if raw_value else signal_obj.Value
547
- self.__log.debug(f'👉 value of signal({bus}{channel}.{message}.{signal}) = {signal_value}')
548
- return signal_value
549
- except Exception as e:
550
- self.__log.error(f'😡 Error getting signal value: {str(e)}')
551
- return None
552
-
553
- def set_signal_value(self, bus: str, channel: int, message: str, signal: str, value: Union[int, float], raw_value=False) -> None:
554
- """set_signal_value sets a value to Signal. Works only when messages are sent using CANoe IL.
555
-
556
- Args:
557
- bus (str): The Bus(CAN, LIN, FlexRay, MOST, AFDX, Ethernet) on which the signal is sent.
558
- channel (int): The channel on which the signal is sent.
559
- message (str): The name of the message to which the signal belongs.
560
- signal (str): The name of the signal.
561
- value (Union[float, int]): signal value.
562
- raw_value (bool): return raw value of the signal if true. Default(False) is physical value.
563
- """
564
- try:
565
- signal_obj = self.application_com_obj.GetBus(bus).GetSignal(channel, message, signal)
566
- if raw_value:
567
- signal_obj.RawValue = value
568
- else:
569
- signal_obj.Value = value
570
- self.__log.debug(f'👉 signal({bus}{channel}.{message}.{signal}) value set to {value}')
571
- except Exception as e:
572
- self.__log.error(f'😡 Error setting signal value: {str(e)}')
573
-
574
- def get_signal_full_name(self, bus: str, channel: int, message: str, signal: str) -> str:
575
- """Determines the fully qualified name of a signal.
576
-
577
- Args:
578
- bus (str): The Bus(CAN, LIN, FlexRay, MOST, AFDX, Ethernet) on which the signal is sent.
579
- channel (int): The channel on which the signal is sent.
580
- message (str): The name of the message to which the signal belongs.
581
- signal (str): The name of the signal.
582
-
583
- Returns:
584
- str: The fully qualified name of a signal. The following format will be used for signals: <DatabaseName>::<MessageName>::<SignalName>
585
- """
586
- try:
587
- signal_obj = self.application_com_obj.GetBus(bus).GetSignal(channel, message, signal)
588
- signal_fullname = signal_obj.FullName
589
- self.__log.debug(f'👉 signal({bus}{channel}.{message}.{signal}) full name = {signal_fullname}')
590
- return signal_fullname
591
- except Exception as e:
592
- self.__log.error(f'😡 Error getting signal full name: {str(e)}')
593
- return ''
594
-
595
- def check_signal_online(self, bus: str, channel: int, message: str, signal: str) -> bool:
596
- """Checks whether the measurement is running and the signal has been received.
597
-
598
- Args:
599
- bus (str): The Bus(CAN, LIN, FlexRay, MOST, AFDX, Ethernet) on which the signal is sent.
600
- channel (int): The channel on which the signal is sent.
601
- message (str): The name of the message to which the signal belongs.
602
- signal (str): The name of the signal.
603
-
604
- Returns:
605
- TRUE if the measurement is running and the signal has been received. FALSE if not.
606
- """
607
- try:
608
- signal_obj = self.application_com_obj.GetBus(bus).GetSignal(channel, message, signal)
609
- sig_online_status = signal_obj.IsOnline
610
- self.__log.debug(f'👉 signal({bus}{channel}.{message}.{signal}) online status = {sig_online_status}')
611
- return sig_online_status
612
- except Exception as e:
613
- self.__log.error(f'😡 Error checking signal online status: {str(e)}')
614
- return False
615
-
616
- def check_signal_state(self, bus: str, channel: int, message: str, signal: str) -> int:
617
- """Checks whether the measurement is running and the signal has been received.
618
-
619
- Args:
620
- bus (str): The Bus(CAN, LIN, FlexRay, MOST, AFDX, Ethernet) on which the signal is sent.
621
- channel (int): The channel on which the signal is sent.
622
- message (str): The name of the message to which the signal belongs.
623
- signal (str): The name of the signal.
624
-
625
- Returns:
626
- State of the signal.
627
- 0- The default value of the signal is returned.
628
- 1- The measurement is not running; the value set by the application is returned.
629
- 2- The measurement is not running; the value of the last measurement is returned.
630
- 3- The signal has been received in the current measurement; the current value is returned.
631
- """
632
- try:
633
- signal_obj = self.application_com_obj.GetBus(bus).GetSignal(channel, message, signal)
634
- sig_state = signal_obj.State
635
- self.__log.debug(f'👉 signal({bus}{channel}.{message}.{signal}) state = {sig_state}')
636
- return sig_state
637
- except Exception as e:
638
- self.__log.error(f'😡 Error checking signal state: {str(e)}')
639
-
640
- def get_j1939_signal_value(self, bus: str, channel: int, message: str, signal: str, source_addr: int, dest_addr: int, raw_value=False) -> Union[float, int]:
641
- """get_j1939_signal Returns a Signal object.
642
-
643
- Args:
644
- bus (str): The Bus(CAN, LIN, FlexRay, MOST, AFDX, Ethernet) on which the signal is sent.
645
- channel (int): The channel on which the signal is sent.
646
- message (str): The name of the message to which the signal belongs.
647
- signal (str): The name of the signal.
648
- source_addr (int): The source address of the ECU that sends the message.
649
- dest_addr (int): The destination address of the ECU that receives the message.
650
- raw_value (bool): return raw value of the signal if true. Default(False) is physical value.
651
-
652
- Returns:
653
- signal value.
654
- """
655
- try:
656
- signal_obj = self.application_com_obj.GetBus(bus).GetJ1939Signal(channel, message, signal, source_addr, dest_addr)
657
- signal_value = signal_obj.RawValue if raw_value else signal_obj.Value
658
- self.__log.debug(f'👉 value of signal({bus}{channel}.{message}.{signal}) = {signal_value}')
659
- return signal_value
660
- except Exception as e:
661
- self.__log.error(f'😡 Error getting signal value: {str(e)}')
662
-
663
- def set_j1939_signal_value(self, bus: str, channel: int, message: str, signal: str, source_addr: int, dest_addr: int, value: Union[float, int], raw_value=False) -> None:
664
- """get_j1939_signal Returns a Signal object.
665
-
666
- Args:
667
- bus (str): The Bus(CAN, LIN, FlexRay, MOST, AFDX, Ethernet) on which the signal is sent.
668
- channel (int): The channel on which the signal is sent.
669
- message (str): The name of the message to which the signal belongs.
670
- signal (str): The name of the signal.
671
- source_addr (int): The source address of the ECU that sends the message.
672
- dest_addr (int): The destination address of the ECU that receives the message.
673
- value (Union[float, int]): signal value.
674
- raw_value (bool): return raw value of the signal if true. Default(False) is physical value.
675
-
676
- Returns:
677
- signal value.
678
- """
679
- try:
680
- signal_obj = self.application_com_obj.GetBus(bus).GetJ1939Signal(channel, message, signal, source_addr, dest_addr)
681
- if raw_value:
682
- signal_obj.RawValue = value
683
- else:
684
- signal_obj.Value = value
685
- self.__log.debug(f'👉 signal({bus}{channel}.{message}.{signal}) value set to {value}')
686
- except Exception as e:
687
- self.__log.error(f'😡 Error setting signal value: {str(e)}')
688
-
689
- def get_j1939_signal_full_name(self, bus: str, channel: int, message: str, signal: str, source_addr: int, dest_addr: int) -> str:
690
- """Determines the fully qualified name of a signal.
691
-
692
- Args:
693
- bus (str): The Bus(CAN, LIN, FlexRay, MOST, AFDX, Ethernet) on which the signal is sent.
694
- channel (int): The channel on which the signal is sent.
695
- message (str): The name of the message to which the signal belongs.
696
- signal (str): The name of the signal.
697
- source_addr (int): The source address of the ECU that sends the message.
698
- dest_addr (int): The destination address of the ECU that receives the message.
699
-
700
- Returns:
701
- str: The fully qualified name of a signal. The following format will be used for signals: <DatabaseName>::<MessageName>::<SignalName>
702
- """
703
- try:
704
- signal_obj = self.application_com_obj.GetBus(bus).GetJ1939Signal(channel, message, signal, source_addr, dest_addr)
705
- signal_fullname = signal_obj.FullName
706
- self.__log.debug(f'👉 signal({bus}{channel}.{message}.{signal}) full name = {signal_fullname}')
707
- return signal_fullname
708
- except Exception as e:
709
- self.__log.error(f'😡 Error getting signal full name: {str(e)}')
710
- return ''
711
-
712
- def check_j1939_signal_online(self, bus: str, channel: int, message: str, signal: str, source_addr: int, dest_addr: int) -> bool:
713
- """Checks whether the measurement is running and the signal has been received.
714
-
715
- Args:
716
- bus (str): The Bus(CAN, LIN, FlexRay, MOST, AFDX, Ethernet) on which the signal is sent.
717
- channel (int): The channel on which the signal is sent.
718
- message (str): The name of the message to which the signal belongs.
719
- signal (str): The name of the signal.
720
- source_addr (int): The source address of the ECU that sends the message.
721
- dest_addr (int): The destination address of the ECU that receives the message.
722
-
723
- Returns:
724
- bool: TRUE: if the measurement is running and the signal has been received. FALSE: if not.
725
- """
726
- try:
727
- signal_obj = self.application_com_obj.GetBus(bus).GetJ1939Signal(channel, message, signal, source_addr, dest_addr)
728
- sig_online_status = signal_obj.IsOnline
729
- self.__log.debug(f'👉 signal({bus}{channel}.{message}.{signal}) online status = {sig_online_status}')
730
- return sig_online_status
731
- except Exception as e:
732
- self.__log.error(f'😡 Error checking signal online status: {str(e)}')
733
- return False
734
-
735
- def check_j1939_signal_state(self, bus: str, channel: int, message: str, signal: str, source_addr: int, dest_addr: int) -> int:
736
- """Returns the state of the signal.
737
-
738
- Returns:
739
- int: State of the signal.
740
- possible values are:
741
- 0: The default value of the signal is returned.
742
- 1: The measurement is not running; the value set by the application is returned.
743
- 3: The signal has been received in the current measurement; the current value is returned.
744
- """
745
- try:
746
- signal_obj = self.application_com_obj.GetBus(bus).GetJ1939Signal(channel, message, signal, source_addr, dest_addr)
747
- sig_state = signal_obj.State
748
- self.__log.debug(f'👉 signal({bus}{channel}.{message}.{signal}) state = {sig_state}')
749
- return sig_state
750
- except Exception as e:
751
- self.__log.error(f'😡 Error checking signal state: {str(e)}')
752
-
753
- def ui_activate_desktop(self, name: str) -> None:
754
- """Activates the desktop with the given name.
755
-
756
- Args:
757
- name (str): The name of the desktop to be activated.
758
- """
759
- try:
760
- self.ui_com_obj.ActivateDesktop(name)
761
- self.__log.debug(f'👉 Activated the desktop({name})')
762
- except Exception as e:
763
- self.__log.error(f'😡 Error activating the desktop: {str(e)}')
764
-
765
- def ui_open_baudrate_dialog(self) -> None:
766
- """opens the dialog for configuring the bus parameters. Make sure Measurement stopped when using this method."""
767
- try:
768
- self.ui_com_obj.OpenBaudrateDialog()
769
- self.__log.debug('👉 baudrate dialog opened. Configure the bus parameters')
770
- except Exception as e:
771
- self.__log.error(f'😡 Error opening baudrate dialog: {str(e)}')
772
-
773
- def write_text_in_write_window(self, text: str) -> None:
774
- """Outputs a line of text in the Write Window.
775
- Args:
776
- text (str): The text.
777
- """
778
- try:
779
- self.ui_write_window_com_obj.Output(text)
780
- self.__log.debug(f'✍️ text "{text}" written in the Write Window')
781
- except Exception as e:
782
- self.__log.error(f'😡 Error writing text in the Write Window: {str(e)}')
783
-
784
- def read_text_from_write_window(self) -> str:
785
- """read the text contents from Write Window.
786
-
787
- Returns:
788
- The text content.
789
- """
790
- try:
791
- text_content = self.ui_write_window_com_obj.Text
792
- self.__log.debug(f'📖 text read from Write Window: {text_content}')
793
- return text_content
794
- except Exception as e:
795
- self.__log.error(f'😡 Error reading text from Write Window: {str(e)}')
796
- return ''
797
-
798
- def clear_write_window_content(self) -> None:
799
- """Clears the contents of the Write Window."""
800
- try:
801
- self.ui_write_window_com_obj.Clear()
802
- self.__log.debug('🧹 Write Window content cleared')
803
- except Exception as e:
804
- self.__log.error(f'😡 Error clearing Write Window content: {str(e)}')
805
-
806
- def copy_write_window_content(self) -> None:
807
- """Copies the contents of the Write Window to the clipboard."""
808
- try:
809
- self.ui_write_window_com_obj.Copy()
810
- self.__log.debug('©️ Write Window content copied to clipboard')
811
- except Exception as e:
812
- self.__log.error(f'😡 Error copying Write Window content: {str(e)}')
813
-
814
- def enable_write_window_output_file(self, output_file: str, tab_index=None) -> None:
815
- """Enables logging of all outputs of the Write Window in the output file.
816
-
817
- Args:
818
- output_file (str): The complete path of the output file.
819
- tab_index (int, optional): The index of the page, for which logging of the output is to be activated. Defaults to None.
820
- """
821
- try:
822
- if tab_index:
823
- self.ui_write_window_com_obj.EnableOutputFile(output_file, tab_index)
824
- self.__log.debug(f'✔️ Enabled logging of outputs of the Write Window. output_file={output_file} and tab_index={tab_index}')
825
- else:
826
- self.ui_write_window_com_obj.EnableOutputFile(output_file)
827
- self.__log.debug(f'✔️ Enabled logging of outputs of the Write Window. output_file={output_file}')
828
- except Exception as e:
829
- self.__log.error(f'😡 Error enabling Write Window output file: {str(e)}')
830
-
831
- def disable_write_window_output_file(self, tab_index=None) -> None:
832
- """Disables logging of all outputs of the Write Window.
833
-
834
- Args:
835
- tab_index (int, optional): The index of the page, for which logging of the output is to be activated. Defaults to None.
836
- """
837
- try:
838
- if tab_index:
839
- self.ui_write_window_com_obj.DisableOutputFile(tab_index)
840
- self.__log.debug(f'⏹️ Disabled logging of outputs of the Write Window. tab_index={tab_index}')
841
- else:
842
- self.ui_write_window_com_obj.DisableOutputFile()
843
- self.__log.debug(f'⏹️ Disabled logging of outputs of the Write Window')
844
- except Exception as e:
845
- self.__log.error(f'😡 Error disabling Write Window output file: {str(e)}')
846
-
847
- def define_system_variable(self, sys_var_name: str, value: Union[int, float, str]) -> object:
848
- """define_system_variable Create a system variable with an initial value
849
- Args:
850
- sys_var_name (str): The name of the system variable. Ex- "sys_var_demo::speed"
851
- value (Union[int, float, str]): variable value.
852
-
853
- Returns:
854
- object: The new Variable object.
855
- """
856
- new_var_com_obj = None
857
- try:
858
- namespace_name = '::'.join(sys_var_name.split('::')[:-1])
859
- variable_name = sys_var_name.split('::')[-1]
860
- system_obj = self.system_obj()
861
- system_obj.add_system_variable(namespace_name, variable_name, value)
862
- self.__log.debug(f'👉 system variable({sys_var_name}) created and value set to {value}')
863
- except Exception as e:
864
- self.__log.error(f'😡 failed to create system variable({sys_var_name}). {e}')
865
- return new_var_com_obj
866
-
867
- def get_system_variable_value(self, sys_var_name: str, return_symbolic_name=False) -> Union[int, float, str, tuple, dict, None]:
868
- """get_system_variable_value Returns a system variable value.
869
-
870
- Args:
871
- sys_var_name (str): The name of the system variable. Ex- "sys_var_demo::speed"
872
- return_symbolic_name (bool): True if user want to return symbolic name. Default is False.
873
-
874
- Returns:
875
- System Variable value.
876
- """
877
- return_value = None
878
- try:
879
- namespace = '::'.join(sys_var_name.split('::')[:-1])
880
- variable_name = sys_var_name.split('::')[-1]
881
- namespace_com_object = self.system_com_obj.Namespaces(namespace)
882
- variable_com_object = win32com.client.Dispatch(namespace_com_object.Variables(variable_name))
883
- var_value = variable_com_object.Value
884
- if return_symbolic_name and (variable_com_object.Type == 0):
885
- var_value_name = variable_com_object.GetSymbolicValueName(var_value)
886
- return_value = var_value_name
887
- else:
888
- return_value = var_value
889
- self.__log.debug(f'👉 system variable({sys_var_name}) value = {return_value}')
890
- except Exception as e:
891
- self.__log.debug(f'😡 failed to get system variable({sys_var_name}) value. {e}')
892
- return return_value
893
-
894
- def set_system_variable_value(self, sys_var_name: str, value: Union[int, float, str]) -> None:
895
- """set_system_variable_value sets a value to system variable.
896
-
897
- Args:
898
- sys_var_name (str): The name of the system variable. Ex- "sys_var_demo::speed".
899
- value (Union[int, float, str]): variable value. supported CAPL system variable data types integer, double, string and data.
900
- """
901
- try:
902
- namespace = '::'.join(sys_var_name.split('::')[:-1])
903
- variable_name = sys_var_name.split('::')[-1]
904
- namespace_com_object = self.system_com_obj.Namespaces(namespace)
905
- variable_com_object = namespace_com_object.Variables(variable_name)
906
- if isinstance(variable_com_object.Value, int):
907
- variable_com_object.Value = int(value)
908
- elif isinstance(variable_com_object.Value, float):
909
- variable_com_object.Value = float(value)
910
- else:
911
- variable_com_object.Value = value
912
- self.__log.debug(f'👉 system variable({sys_var_name}) value set to {value}')
913
- except Exception as e:
914
- self.__log.debug(f'😡 failed to set system variable({sys_var_name}) value. {e}')
915
-
916
- def set_system_variable_array_values(self, sys_var_name: str, value: tuple, index=0) -> None:
917
- """set_system_variable_array_values sets array of values to system variable.
918
-
919
- Args:
920
- sys_var_name (str): The name of the system variable. Ex- "sys_var_demo::speed"
921
- value (tuple): variable values. supported integer array or double array. please always give only one type.
922
- index (int): value of index where values will start updating. Defaults to 0.
923
- """
924
- try:
925
- namespace = '::'.join(sys_var_name.split('::')[:-1])
926
- variable_name = sys_var_name.split('::')[-1]
927
- namespace_com_object = self.system_com_obj.Namespaces(namespace)
928
- variable_com_object = namespace_com_object.Variables(variable_name)
929
- existing_variable_value = list(variable_com_object.Value)
930
- if (index + len(value)) <= len(existing_variable_value):
931
- final_value = existing_variable_value
932
- if isinstance(existing_variable_value[0], float):
933
- final_value[index: index + len(value)] = (float(v) for v in value)
934
- else:
935
- final_value[index: index + len(value)] = value
936
- variable_com_object.Value = tuple(final_value)
937
- wait(0.1)
938
- self.__log.debug(f'👉 system variable({sys_var_name}) value set to {variable_com_object.Value}')
939
- else:
940
- self.__log.warning(f'⚠️ failed to set system variable({sys_var_name}) value. check variable length and index value')
941
- except Exception as e:
942
- self.__log.error(f'😡 failed to set system variable({sys_var_name}) value. {e}')
943
-
944
- def send_diag_request(self, diag_ecu_qualifier_name: str, request: str, request_in_bytes=True, return_sender_name=False) -> Union[str, dict]:
945
- """The send_diag_request method represents the query of a diagnostic tester (client) to an ECU (server) in CANoe.
946
-
947
- Args:
948
- diag_ecu_qualifier_name (str): Diagnostic Node ECU Qualifier Name configured in "Diagnostic/ISO TP Configuration".
949
- request (str): Diagnostic request in bytes or diagnostic request qualifier name.
950
- request_in_bytes (bool): True if Diagnostic request is bytes. False if you are using Qualifier name. Default is True.
951
- return_sender_name (bool): True if you user want response along with response sender name in dictionary. Default is False.
952
-
953
- Returns:
954
- diagnostic response stream. Ex- "50 01 00 00 00 00" or {'Door': "50 01 00 00 00 00"}
955
- """
956
- diag_response_data = ""
957
- diag_response_including_sender_name = {}
958
- try:
959
- if diag_ecu_qualifier_name in self.__diag_devices.keys():
960
- self.__log.debug(f'💉 {diag_ecu_qualifier_name}: Diagnostic Request = {request}')
961
- if request_in_bytes:
962
- diag_req = self.__diag_devices[diag_ecu_qualifier_name].create_request_from_stream(request)
963
- else:
964
- diag_req = self.__diag_devices[diag_ecu_qualifier_name].create_request(request)
965
- diag_req.send()
966
- while diag_req.pending:
967
- wait(0.1)
968
- diag_req_responses = diag_req.responses
969
- if len(diag_req_responses) == 0:
970
- self.__log.warning("🙅 Diagnostic Response Not Received 🔴")
971
- else:
972
- for diag_res in diag_req_responses:
973
- diag_response_data = diag_res.stream
974
- diag_response_including_sender_name[diag_res.sender] = diag_response_data
975
- if diag_res.positive:
976
- self.__log.debug(f"🟢 {diag_res.sender}: ➕ Diagnostic Response = {diag_response_data}")
977
- else:
978
- self.__log.debug(f"🔴 {diag_res.Sender}: ➖ Diagnostic Response = {diag_response_data}")
979
- else:
980
- self.__log.warning(f'⚠️ Diagnostic ECU qualifier({diag_ecu_qualifier_name}) not available in loaded CANoe config')
981
- except Exception as e:
982
- self.__log.error(f'😡 failed to send diagnostic request({request}). {e}')
983
- return diag_response_including_sender_name if return_sender_name else diag_response_data
984
-
985
- def control_tester_present(self, diag_ecu_qualifier_name: str, value: bool) -> None:
986
- """Starts/Stops sending autonomous/cyclical Tester Present requests to the ECU.
987
-
988
- Args:
989
- diag_ecu_qualifier_name (str): Diagnostic Node ECU Qualifier Name configured in "Diagnostic/ISO TP Configuration".
990
- value (bool): True - activate tester present. False - deactivate tester present.
991
- """
992
- try:
993
- if diag_ecu_qualifier_name in self.__diag_devices.keys():
994
- diag_device = self.__diag_devices[diag_ecu_qualifier_name]
995
- if diag_device.tester_present_status != value:
996
- if value:
997
- diag_device.start_tester_present()
998
- self.__log.debug(f'⏱️🏃‍♂️‍ {diag_ecu_qualifier_name}: started tester present')
999
- else:
1000
- diag_device.stop_tester_present()
1001
- self.__log.debug(f'⏱️🧍‍♂️ {diag_ecu_qualifier_name}: stopped tester present')
1002
- wait(0.1)
1003
- else:
1004
- self.__log.warning(f'⚠️ {diag_ecu_qualifier_name}: tester present already set to {value}')
1005
- else:
1006
- self.__log.error(f'😇 diag ECU qualifier "{diag_ecu_qualifier_name}" not available in configuration')
1007
- except Exception as e:
1008
- self.__log.error(f'😡 failed to control tester present. {e}')
1009
-
1010
- def set_replay_block_file(self, block_name: str, recording_file_path: str) -> None:
1011
- """Method for setting CANoe replay block file.
1012
-
1013
- Args:
1014
- block_name: CANoe replay block name
1015
- recording_file_path: CANoe replay recording file including path.
1016
- """
1017
- try:
1018
- replay_blocks = self.__replay_blocks
1019
- if block_name in replay_blocks.keys():
1020
- replay_block = replay_blocks[block_name]
1021
- replay_block.path = recording_file_path
1022
- self.__log.debug(f'👉 Replay block "{block_name}" updated with "{recording_file_path}" path')
1023
- else:
1024
- self.__log.warning(f'⚠️ Replay block "{block_name}" not available')
1025
- except Exception as e:
1026
- self.__log.error(f'😡 failed to set replay block file. {e}')
1027
-
1028
- def control_replay_block(self, block_name: str, start_stop: bool) -> None:
1029
- """Method for controlling CANoe replay block.
1030
-
1031
- Args:
1032
- block_name (str): CANoe replay block name
1033
- start_stop (bool): True to start replay block. False to Stop.
1034
- """
1035
- try:
1036
- replay_blocks = self.__replay_blocks
1037
- if block_name in replay_blocks.keys():
1038
- replay_block = replay_blocks[block_name]
1039
- if start_stop:
1040
- replay_block.start()
1041
- else:
1042
- replay_block.stop()
1043
- self.__log.debug(f'👉 Replay block "{block_name}" {"Started" if start_stop else "Stopped"}')
1044
- else:
1045
- self.__log.warning(f'⚠️ Replay block "{block_name}" not available')
1046
- except Exception as e:
1047
- self.__log.error(f'😡 failed to control replay block. {e}')
1048
-
1049
- def compile_all_capl_nodes(self) -> dict:
1050
- """compiles all CAPL, XML and .NET nodes."""
1051
- try:
1052
- capl_obj = self.capl_obj()
1053
- capl_obj.compile()
1054
- wait(1)
1055
- compile_result = capl_obj.compile_result()
1056
- self.__log.debug(f'🧑‍💻 compiled all CAPL nodes successfully. result={compile_result["result"]}')
1057
- return compile_result
1058
- except Exception as e:
1059
- self.__log.error(f'😡 failed to compile all CAPL nodes. {e}')
1060
- return {}
1061
-
1062
- def call_capl_function(self, name: str, *arguments) -> bool:
1063
- """Calls a CAPL function.
1064
- Please note that the number of parameters must agree with that of the CAPL function.
1065
- not possible to read return value of CAPL function at the moment. only execution status is returned.
1066
-
1067
- Args:
1068
- name (str): The name of the CAPL function. Please make sure this name is already passed as argument during CANoe instance creation. see example for more info.
1069
- arguments (tuple): Function parameters p1…p10 (optional).
1070
-
1071
- Returns:
1072
- bool: CAPL function execution status. True-success, False-failed.
1073
- """
1074
- try:
1075
- capl_obj = self.capl_obj()
1076
- exec_sts = capl_obj.call_capl_function(CanoeMeasurementEvents.user_capl_function_obj_dict[name], *arguments)
1077
- self.__log.debug(f'🛫 triggered capl function({name}). execution status = {exec_sts}')
1078
- return exec_sts
1079
- except Exception as e:
1080
- self.__log.error(f'😡 failed to call capl function({name}). {e}')
1081
- return False
1082
-
1083
- def get_test_environments(self) -> dict:
1084
- """returns dictionary of test environment names and class."""
1085
- try:
1086
- return self.__test_setup_environments
1087
- except Exception as e:
1088
- self.__log.debug(f'😡 failed to get test environments. {e}')
1089
- return {}
1090
-
1091
- def get_test_modules(self, env_name: str) -> dict:
1092
- """returns dictionary of test environment test module names and its class object.
1093
-
1094
- Args:
1095
- env_name (str): test environment name. avoid duplicate test environment names in CANoe configuration.
1096
- """
1097
- try:
1098
- test_environments = self.get_test_environments()
1099
- if len(test_environments) > 0:
1100
- if env_name in test_environments.keys():
1101
- return test_environments[env_name].get_all_test_modules()
1102
- else:
1103
- self.__log.warning(f'⚠️ "{env_name}" not found in configuration')
1104
- return {}
1105
- else:
1106
- self.__log.warning(f'⚠️ Zero test environments found in configuration. Not possible to fetch test modules')
1107
- return {}
1108
- except Exception as e:
1109
- self.__log.error(f'😡 failed to get test modules. {e}')
1110
- return {}
1111
-
1112
- def execute_test_module(self, test_module_name: str) -> int:
1113
- """use this method to execute test module.
1114
-
1115
- Args:
1116
- test_module_name (str): test module name. avoid duplicate test module names in CANoe configuration.
1117
-
1118
- Returns:
1119
- int: test module execution verdict. 0 ='VerdictNotAvailable', 1 = 'VerdictPassed', 2 = 'VerdictFailed',
1120
- """
1121
- try:
1122
- test_verdict = {0: 'NotAvailable',
1123
- 1: 'Passed',
1124
- 2: 'Failed',
1125
- 3: 'None (not available for test modules)',
1126
- 4: 'Inconclusive (not available for test modules)',
1127
- 5: 'ErrorInTestSystem (not available for test modules)', }
1128
- execution_result = 0
1129
- test_module_found = False
1130
- test_env_name = ''
1131
- for tm in self.__test_modules:
1132
- if tm['name'] == test_module_name:
1133
- test_module_found = True
1134
- tm_obj = tm['object']
1135
- test_env_name = tm['environment']
1136
- self.__log.debug(f'🔎 test module "{test_module_name}" found in "{test_env_name}"')
1137
- tm_obj.start()
1138
- tm_obj.wait_for_completion()
1139
- execution_result = tm_obj.verdict
1140
- break
1141
- else:
1142
- continue
1143
- if test_module_found and (execution_result == 1):
1144
- self.__log.debug(f'✔️ test module "{test_env_name}.{test_module_name}" executed and verdict = {test_verdict[execution_result]}')
1145
- elif test_module_found and (execution_result != 1):
1146
- self.__log.debug(f'😵‍💫 test module "{test_env_name}.{test_module_name}" executed and verdict = {test_verdict[execution_result]}')
1147
- else:
1148
- self.__log.warning(f'⚠️ test module "{test_module_name}" not found. not possible to execute')
1149
- return execution_result
1150
- except Exception as e:
1151
- self.__log.error(f'😡 failed to execute test module. {e}')
1152
- return 0
1153
-
1154
- def stop_test_module(self, test_module_name: str):
1155
- """stops execution of test module.
1156
-
1157
- Args:
1158
- test_module_name (str): test module name. avoid duplicate test module names in CANoe configuration.
1159
- """
1160
- try:
1161
- for tm in self.__test_modules:
1162
- if tm['name'] == test_module_name:
1163
- tm['object'].stop()
1164
- test_env_name = tm['environment']
1165
- self.__log.debug(f'👉 test module "{test_module_name}" in test environment "{test_env_name}" stopped 🧍‍♂️')
1166
- else:
1167
- self.__log.warning(f'⚠️ test module "{test_module_name}" not found. not possible to execute')
1168
- except Exception as e:
1169
- self.__log.error(f'😡 failed to stop test module. {e}')
1170
-
1171
- def execute_all_test_modules_in_test_env(self, env_name: str):
1172
- """executes all test modules available in test environment.
1173
-
1174
- Args:
1175
- env_name (str): test environment name. avoid duplicate test environment names in CANoe configuration.
1176
- """
1177
- try:
1178
- test_modules = self.get_test_modules(env_name=env_name)
1179
- if test_modules:
1180
- for tm_name in test_modules.keys():
1181
- self.execute_test_module(tm_name)
1182
- else:
1183
- self.__log.warning(f'⚠️ test modules not available in "{env_name}" test environment')
1184
- except Exception as e:
1185
- self.__log.error(f'😡 failed to execute all test modules in "{env_name}" test environment. {e}')
1186
-
1187
- def stop_all_test_modules_in_test_env(self, env_name: str):
1188
- """stops execution of all test modules available in test environment.
1189
-
1190
- Args:
1191
- env_name (str): test environment name. avoid duplicate test environment names in CANoe configuration.
1192
- """
1193
- try:
1194
- test_modules = self.get_test_modules(env_name=env_name)
1195
- if test_modules:
1196
- for tm_name in test_modules.keys():
1197
- self.stop_test_module(env_name, tm_name)
1198
- else:
1199
- self.__log.warning(f'⚠️ test modules not available in "{env_name}" test environment')
1200
- except Exception as e:
1201
- self.__log.error(f'😡 failed to stop all test modules in "{env_name}" test environment. {e}')
1202
-
1203
- def execute_all_test_environments(self):
1204
- """executes all test environments available in test setup."""
1205
- try:
1206
- test_environments = self.get_test_environments()
1207
- if len(test_environments) > 0:
1208
- for test_env_name in test_environments.keys():
1209
- self.__log.debug(f'🏃‍♂️ started executing test environment "{test_env_name}"')
1210
- self.execute_all_test_modules_in_test_env(test_env_name)
1211
- self.__log.debug(f'✔️ completed executing test environment "{test_env_name}"')
1212
- else:
1213
- self.__log.warning(f'⚠️ Zero test environments found in configuration')
1214
- except Exception as e:
1215
- self.__log.error(f'😡 failed to execute all test environments. {e}')
1216
-
1217
- def stop_all_test_environments(self):
1218
- """stops execution of all test environments available in test setup."""
1219
- try:
1220
- test_environments = self.get_test_environments()
1221
- if len(test_environments) > 0:
1222
- for test_env_name in test_environments.keys():
1223
- self.__log.debug(f'⏹️ stopping test environment "{test_env_name}" execution')
1224
- self.stop_all_test_modules_in_test_env(test_env_name)
1225
- self.__log.debug(f'✔️ completed stopping test environment "{test_env_name}"')
1226
- else:
1227
- self.__log.warning(f'⚠️ Zero test environments found in configuration')
1228
- except Exception as e:
1229
- self.__log.error(f'😡 failed to stop all test environments. {e}')
1230
-
1231
- def get_environment_variable_value(self, env_var_name: str) -> Union[int, float, str, tuple, None]:
1232
- """returns a environment variable value.
1233
-
1234
- Args:
1235
- env_var_name (str): The name of the environment variable. Ex- "float_var"
1236
-
1237
- Returns:
1238
- Environment Variable value.
1239
- """
1240
- var_value = None
1241
- try:
1242
- variable = self.environment_obj_inst.get_variable(env_var_name)
1243
- var_value = variable.value if variable.type != 3 else tuple(variable.value)
1244
- self.__log.debug(f'👉 environment variable({env_var_name}) value = {var_value}')
1245
- except Exception as e:
1246
- self.__log.error(f'😡 failed to get environment variable({env_var_name}) value. {e}')
1247
- return var_value
1248
-
1249
- def set_environment_variable_value(self, env_var_name: str, value: Union[int, float, str, tuple]) -> None:
1250
- """sets a value to environment variable.
1251
-
1252
- Args:
1253
- env_var_name (str): The name of the environment variable. Ex- "speed".
1254
- value (Union[int, float, str, tuple]): variable value. supported CAPL environment variable data types integer, double, string and data.
1255
- """
1256
- try:
1257
- variable = self.environment_obj_inst.get_variable(env_var_name)
1258
- if variable.type == 0:
1259
- converted_value = int(value)
1260
- elif variable.type == 1:
1261
- converted_value = float(value)
1262
- elif variable.type == 2:
1263
- converted_value = str(value)
1264
- else:
1265
- converted_value = tuple(value)
1266
- variable.value = converted_value
1267
- self.__log.debug(f'👉 environment variable({env_var_name}) value = {converted_value}')
1268
- except Exception as e:
1269
- self.__log.error(f'😡 failed to set system variable({env_var_name}) value. {e}')
1270
-
1271
- def add_database(self, database_file: str, database_network: str, database_channel: int) -> bool:
1272
- """adds database file to a network channel
1273
-
1274
- Args:
1275
- database_file (str): database file to attach. give full file path.
1276
- database_network (str): network name on which you want to add this database.
1277
- database_channel (int): channel name on which you want to add this database.
1278
- """
1279
- try:
1280
- if self.get_measurement_running_status():
1281
- self.__log.warning('⚠️ measurement is running. not possible to add database')
1282
- return False
1283
- else:
1284
- databases = self.configuration_general_setup.database_setup.databases.fetch_databases()
1285
- if database_file in [database.full_name for database in databases.values()]:
1286
- self.__log.warning(f'⚠️ database "{database_file}" already added')
1287
- return False
1288
- else:
1289
- self.configuration_general_setup.database_setup.databases.add_network(database_file, database_network)
1290
- wait(1)
1291
- databases = self.configuration_general_setup.database_setup.databases.fetch_databases()
1292
- for database in databases.values():
1293
- if database.full_name == database_file:
1294
- database.channel = database_channel
1295
- wait(1)
1296
- self.__log.debug(f'👉 database "{database_file}" added to network "{database_network}" and channel {database_channel}')
1297
- return True
1298
- except Exception as e:
1299
- self.__log.error(f'😡 failed to add database "{database_file}". {e}')
1300
- return False
1301
-
1302
- def remove_database(self, database_file: str, database_channel: int) -> bool:
1303
- """remove database file from a channel
1304
-
1305
- Args:
1306
- database_file (str): database file to remove. give full file path.
1307
- database_channel (int): channel name on which you want to remove database.
1308
- """
1309
- try:
1310
- if self.get_measurement_running_status():
1311
- self.__log.warning('⚠️ measurement is running. not possible to remove database')
1312
- return False
1313
- else:
1314
- databases = self.configuration_general_setup.database_setup.databases
1315
- if database_file not in [database.full_name for database in databases.fetch_databases().values()]:
1316
- self.__log.warning(f'⚠️ database "{database_file}" not available to remove')
1317
- return False
1318
- else:
1319
- for i in range(1, databases.count + 1):
1320
- database_com_obj = databases.com_obj.Item(i)
1321
- if database_com_obj.FullName == database_file and database_com_obj.Channel == database_channel:
1322
- self.configuration_general_setup.database_setup.databases.remove(i)
1323
- wait(1)
1324
- self.__log.debug(f'👉 database "{database_file}" removed from channel {database_channel}')
1325
- return True
1326
- except Exception as e:
1327
- self.__log.error(f'😡 failed to remove database "{database_file}". {e}')
1328
- return False
1329
-
1330
-
1331
- def wait(timeout_seconds=0.1):
1332
- """Waits for a specified timeout, pumping Windows messages.
1333
-
1334
- Args:
1335
- timeout_seconds: The time to wait in seconds.
1336
-
1337
- Returns:
1338
- None
1339
- """
1340
- pythoncom.PumpWaitingMessages()
1341
- time.sleep(timeout_seconds)
1342
-
1343
- def DoApplicationEvents() -> None:
1344
- wait(0.1)
1345
-
1346
- def DoApplicationEventsUntil(cond, timeout) -> None:
1347
- base_time = datetime.now()
1348
- while not cond():
1349
- DoMeasurementEvents()
1350
- now = datetime.now()
1351
- difference = now - base_time
1352
- seconds = difference.seconds
1353
- if seconds > timeout():
1354
- logging.getLogger('CANOE_LOG').debug(f'⌛ application event timeout({timeout()} s)')
1355
- break
1356
-
1357
- def DoMeasurementEvents() -> None:
1358
- wait(0.1)
1359
-
1360
- def DoMeasurementEventsUntil(cond, timeout) -> None:
1361
- base_time = datetime.now()
1362
- while not cond():
1363
- DoMeasurementEvents()
1364
- now = datetime.now()
1365
- difference = now - base_time
1366
- seconds = difference.seconds
1367
- if seconds > timeout():
1368
- logging.getLogger('CANOE_LOG').debug(f'⌛ measurement event timeout({timeout()} s)')
1369
- break
1370
-
1371
- def DoTestModuleEvents():
1372
- wait(0.1)
1373
-
1374
- def DoTestModuleEventsUntil(condition):
1375
- while not condition():
1376
- DoTestModuleEvents()
1377
-
1378
- def DoEnvVarEvents():
1379
- wait(0.1)
1380
-
1381
- def DoEnvVarEventsUntil(condition):
1382
- while not condition():
1383
- DoEnvVarEvents()
1384
-
1385
-
1386
- class CanoeApplicationEvents:
1387
- """Handler for CANoe Application events"""
1388
- @staticmethod
1389
- def OnOpen(fullname):
1390
- CANoe.CANOE_APPLICATION_OPENED = True
1391
- CANoe.CANOE_APPLICATION_CLOSED = False
1392
-
1393
- @staticmethod
1394
- def OnQuit():
1395
- CANoe.CANOE_APPLICATION_OPENED = False
1396
- CANoe.CANOE_APPLICATION_CLOSED = True
1397
-
1398
-
1399
- class CanoeCapl:
1400
- """The CAPL object allows to compile all nodes (CAPL, .NET, XML) in the configuration.
1401
- Additionally, it represents the CAPL functions available in the CAPL programs.
1402
- Please note that only user-defined CAPL functions can be accessed
1403
- """
1404
- def __init__(self, application_com_obj):
1405
- try:
1406
- self.__log = logging.getLogger('CANOE_LOG')
1407
- self.com_obj = win32com.client.Dispatch(application_com_obj.CAPL)
1408
- except Exception as e:
1409
- self.__log.error(f'😡 Error initializing CAPL object: {str(e)}')
1410
-
1411
- def compile(self) -> None:
1412
- self.com_obj.Compile()
1413
-
1414
- def get_function(self, name: str) -> object:
1415
- return self.com_obj.GetFunction(name)
1416
-
1417
- @staticmethod
1418
- def parameter_count(capl_function_object: get_function) -> int:
1419
- return capl_function_object.ParameterCount
1420
-
1421
- @staticmethod
1422
- def parameter_types(capl_function_object: get_function) -> tuple:
1423
- return capl_function_object.ParameterTypes
1424
-
1425
- def call_capl_function(self, capl_function_obj: get_function, *arguments) -> bool:
1426
- return_value = False
1427
- if len(arguments) == self.parameter_count(capl_function_obj):
1428
- if len(arguments) > 0:
1429
- capl_function_obj.Call(*arguments)
1430
- else:
1431
- capl_function_obj.Call()
1432
- return_value = True
1433
- else:
1434
- self.__log.warning(fr'😇 function arguments not matching with CAPL user function args')
1435
- return return_value
1436
-
1437
- def compile_result(self) -> dict:
1438
- return_values = dict()
1439
- compile_result_obj = self.com_obj.CompileResult
1440
- return_values['error_message'] = compile_result_obj.ErrorMessage
1441
- return_values['node_name'] = compile_result_obj.NodeName
1442
- return_values['result'] = compile_result_obj.result
1443
- return_values['source_file'] = compile_result_obj.SourceFile
1444
- return return_values
1445
-
1446
-
1447
- class CanoeConfigurationEvents:
1448
- """Handler for CANoe Configuration events"""
1449
- @staticmethod
1450
- def OnClose():
1451
- logging.getLogger('CANOE_LOG').debug('👉 configuration OnClose event triggered')
1452
-
1453
- @staticmethod
1454
- def OnSystemVariablesDefinitionChanged():
1455
- logging.getLogger('CANOE_LOG').debug('👉 configuration OnSystemVariablesDefinitionChanged event triggered')
1456
-
1457
-
1458
- class CanoeConfigurationGeneralSetup:
1459
- """The GeneralSetup object represents the general settings of a CANoe configuration."""
1460
- def __init__(self, configuration_com_obj) -> None:
1461
- try:
1462
- self.__log = logging.getLogger('CANOE_LOG')
1463
- self.com_obj = win32com.client.Dispatch(configuration_com_obj.GeneralSetup)
1464
- except Exception as e:
1465
- self.__log.error(f'😡 Error initializing CANoe general setup: {str(e)}')
1466
-
1467
- @property
1468
- def database_setup(self):
1469
- return CanoeConfigurationGeneralSetupDatabaseSetup(self.com_obj)
1470
-
1471
-
1472
- class CanoeConfigurationGeneralSetupDatabaseSetupEvents:
1473
- @staticmethod
1474
- def OnChange():
1475
- logging.getLogger('CANOE_LOG').debug('👉 database setup OnChange event triggered')
1476
-
1477
-
1478
- class CanoeConfigurationGeneralSetupDatabaseSetup:
1479
- """The DatabaseSetup object represents the assigned databases of the current configuration."""
1480
- def __init__(self, general_setup_com_obj):
1481
- try:
1482
- self.__log = logging.getLogger('CANOE_LOG')
1483
- self.com_obj = win32com.client.Dispatch(general_setup_com_obj.DatabaseSetup)
1484
- except Exception as e:
1485
- self.__log.error(f'😡 Error initializing CANoe database setup: {str(e)}')
1486
-
1487
- @property
1488
- def databases(self):
1489
- return CanoeConfigurationGeneralSetupDatabaseSetupDatabases(self.com_obj)
1490
-
1491
-
1492
- class CanoeConfigurationGeneralSetupDatabaseSetupDatabases:
1493
- """The Databases object represents the assigned databases of CANoe."""
1494
- def __init__(self, database_setup_com_obj):
1495
- try:
1496
- self.__log = logging.getLogger('CANOE_LOG')
1497
- self.com_obj = win32com.client.Dispatch(database_setup_com_obj.Databases)
1498
- except Exception as e:
1499
- self.__log.error(f'😡 Error initializing CANoe databases: {str(e)}')
1500
-
1501
- @property
1502
- def count(self) -> int:
1503
- return self.com_obj.Count
1504
-
1505
- def fetch_databases(self) -> dict:
1506
- databases = dict()
1507
- for index in range(1, self.count + 1):
1508
- db_com_obj = self.com_obj.Item(index)
1509
- db_inst = CanoeConfigurationGeneralSetupDatabaseSetupDatabasesDatabase(db_com_obj)
1510
- databases[db_inst.name] = db_inst
1511
- return databases
1512
-
1513
- def add(self, full_name: str) -> object:
1514
- return self.com_obj.Add(full_name)
1515
-
1516
- def add_network(self, database_name: str, network_name: str) -> object:
1517
- return self.com_obj.AddNetwork(database_name, network_name)
1518
-
1519
- def remove(self, index: int) -> None:
1520
- self.com_obj.Remove(index)
1521
-
1522
-
1523
- class CanoeConfigurationGeneralSetupDatabaseSetupDatabasesDatabase:
1524
- """The Database object represents the assigned database of the CANoe application."""
1525
- def __init__(self, database_com_obj):
1526
- try:
1527
- self.__log = logging.getLogger('CANOE_LOG')
1528
- self.com_obj = win32com.client.Dispatch(database_com_obj)
1529
- except Exception as e:
1530
- self.__log.error(f'😡 Error initializing CANoe database: {str(e)}')
1531
-
1532
- @property
1533
- def channel(self) -> int:
1534
- return self.com_obj.Channel
1535
-
1536
- @channel.setter
1537
- def channel(self, channel: int) -> None:
1538
- self.com_obj.Channel = channel
1539
-
1540
- @property
1541
- def full_name(self) -> str:
1542
- return self.com_obj.FullName
1543
-
1544
- @full_name.setter
1545
- def full_name(self, full_name: str) -> None:
1546
- self.com_obj.FullName = full_name
1547
-
1548
- @property
1549
- def name(self) -> str:
1550
- return self.com_obj.Name
1551
-
1552
- @property
1553
- def path(self) -> str:
1554
- return self.com_obj.Path
1555
-
1556
-
1557
- class CanoeConfigurationSimulationSetup:
1558
- """The SimulationSetup object represents the Simulation Setup of CANoe."""
1559
- def __init__(self, configuration_com_obj):
1560
- try:
1561
- self.__log = logging.getLogger('CANOE_LOG')
1562
- self.com_obj = win32com.client.Dispatch(configuration_com_obj.SimulationSetup)
1563
- except Exception as e:
1564
- self.__log.error(f'😡 Error initializing CANoe simulation setup: {str(e)}')
1565
-
1566
- @property
1567
- def replay_collection(self):
1568
- return CanoeConfigurationSimulationSetupReplayCollection(self.com_obj)
1569
-
1570
- @property
1571
- def buses(self):
1572
- return CanoeConfigurationSimulationSetupBuses(self.com_obj)
1573
-
1574
- @property
1575
- def nodes(self):
1576
- return CanoeConfigurationSimulationSetupNodes(self.com_obj)
1577
-
1578
-
1579
- class CanoeConfigurationSimulationSetupReplayCollection:
1580
- """The ReplayCollection object represents the Replay Blocks of the CANoe application."""
1581
- def __init__(self, sim_setup_com_obj):
1582
- try:
1583
- self.__log = logging.getLogger('CANOE_LOG')
1584
- self.com_obj = win32com.client.Dispatch(sim_setup_com_obj.ReplayCollection)
1585
- except Exception as e:
1586
- self.__log.error(f'😡 Error initializing CANoe replay collection: {str(e)}')
1587
-
1588
- @property
1589
- def count(self) -> int:
1590
- return self.com_obj.Count
1591
-
1592
- def add(self, name: str) -> object:
1593
- return self.com_obj.Add(name)
1594
-
1595
- def remove(self, index: int) -> None:
1596
- self.com_obj.Remove(index)
1597
-
1598
- def fetch_replay_blocks(self) -> dict:
1599
- replay_blocks = dict()
1600
- for index in range(1, self.count + 1):
1601
- rb_com_obj = self.com_obj.Item(index)
1602
- rb_inst = CanoeConfigurationSimulationSetupReplayCollectionReplayBlock(rb_com_obj)
1603
- replay_blocks[rb_inst.name] = rb_inst
1604
- return replay_blocks
1605
-
1606
-
1607
- class CanoeConfigurationSimulationSetupReplayCollectionReplayBlock:
1608
- def __init__(self, replay_block_com_obj):
1609
- try:
1610
- self.__log = logging.getLogger('CANOE_LOG')
1611
- self.com_obj = win32com.client.Dispatch(replay_block_com_obj)
1612
- except Exception as e:
1613
- self.__log.error(f'😡 Error initializing CANoe replay block: {str(e)}')
1614
-
1615
- @property
1616
- def name(self) -> str:
1617
- return self.com_obj.Name
1618
-
1619
- @property
1620
- def path(self) -> str:
1621
- return self.com_obj.Path
1622
-
1623
- @path.setter
1624
- def path(self, path: str):
1625
- self.com_obj.Path = path
1626
-
1627
- def start(self):
1628
- self.com_obj.Start()
1629
-
1630
- def stop(self):
1631
- self.com_obj.Stop()
1632
-
1633
-
1634
- class CanoeConfigurationSimulationSetupBuses:
1635
- """The Buses object represents the buses of the Simulation Setup of the CANoe application.
1636
- The Buses object is only available in CANoe.
1637
- """
1638
- def __init__(self, sim_setup_com_obj):
1639
- try:
1640
- self.__log = logging.getLogger('CANOE_LOG')
1641
- self.com_obj = win32com.client.Dispatch(sim_setup_com_obj.Buses)
1642
- except Exception as e:
1643
- self.__log.error(f'😡 Error initializing CANoe buses: {str(e)}')
1644
-
1645
- @property
1646
- def count(self) -> int:
1647
- return self.com_obj.Count
1648
-
1649
-
1650
- class CanoeConfigurationSimulationSetupNodes:
1651
- """The Nodes object represents the CAPL node of the Simulation Setup of the CANoe application.
1652
- The Nodes object is only available in CANoe.
1653
- """
1654
- def __init__(self, sim_setup_com_obj):
1655
- try:
1656
- self.__log = logging.getLogger('CANOE_LOG')
1657
- self.com_obj = win32com.client.Dispatch(sim_setup_com_obj.Nodes)
1658
- except Exception as e:
1659
- self.__log.error(f'😡 Error initializing CANoe nodes: {str(e)}')
1660
-
1661
- @property
1662
- def count(self) -> int:
1663
- return self.com_obj.Count
1664
-
1665
-
1666
- class CanoeConfigurationTestSetup:
1667
- """The TestSetup object represents CANoe's test setup."""
1668
- def __init__(self, conf_com_obj):
1669
- try:
1670
- self.__log = logging.getLogger('CANOE_LOG')
1671
- self.com_obj = win32com.client.Dispatch(conf_com_obj.TestSetup)
1672
- except Exception as e:
1673
- self.__log.error(f'😡 Error initializing CANoe test setup: {str(e)}')
1674
-
1675
- def save_all(self, prompt_user=False) -> None:
1676
- self.com_obj.SaveAll(prompt_user)
1677
-
1678
- @property
1679
- def test_environments(self):
1680
- return CanoeConfigurationTestSetupTestEnvironments(self.com_obj)
1681
-
1682
-
1683
- class CanoeConfigurationTestSetupTestEnvironments:
1684
- """The TestEnvironments object represents the test environments within CANoe's test setup."""
1685
- def __init__(self, test_setup_com_obj):
1686
- try:
1687
- self.__log = logging.getLogger('CANOE_LOG')
1688
- self.com_obj = win32com.client.Dispatch(test_setup_com_obj.TestEnvironments)
1689
- except Exception as e:
1690
- self.__log.error(f'😡 Error initializing CANoe test environments: {str(e)}')
1691
-
1692
- @property
1693
- def count(self) -> int:
1694
- return self.com_obj.Count
1695
-
1696
- def add(self, name: str) -> object:
1697
- return self.com_obj.Add(name)
1698
-
1699
- def remove(self, index: int, prompt_user=False) -> None:
1700
- self.com_obj.Remove(index, prompt_user)
1701
-
1702
- def fetch_all_test_environments(self) -> dict:
1703
- test_environments = dict()
1704
- for index in range(1, self.count + 1):
1705
- te_com_obj = win32com.client.Dispatch(self.com_obj.Item(index))
1706
- te_inst = CanoeConfigurationTestSetupTestEnvironmentsTestEnvironment(te_com_obj)
1707
- test_environments[te_inst.name] = te_inst
1708
- return test_environments
1709
-
1710
-
1711
- class CanoeConfigurationTestSetupTestEnvironmentsTestEnvironment:
1712
- """The TestEnvironment object represents a test environment within CANoe's test setup."""
1713
- def __init__(self, test_environment_com_obj):
1714
- self.com_obj = test_environment_com_obj
1715
- self.__test_modules = CanoeConfigurationTestSetupTestEnvironmentsTestEnvironmentTestModules(self.com_obj)
1716
- self.__test_setup_folders = CanoeConfigurationTestSetupTestEnvironmentsTestEnvironmentTestSetupFolders(self.com_obj)
1717
- self.__all_test_modules = {}
1718
- self.__all_test_setup_folders = {}
1719
-
1720
- @property
1721
- def enabled(self) -> bool:
1722
- return self.com_obj.Enabled
1723
-
1724
- @enabled.setter
1725
- def enabled(self, value: bool) -> None:
1726
- self.com_obj.Enabled = value
1727
-
1728
- @property
1729
- def full_name(self) -> str:
1730
- return self.com_obj.FullName
1731
-
1732
- @property
1733
- def name(self) -> str:
1734
- return self.com_obj.Name
1735
-
1736
- @property
1737
- def path(self) -> str:
1738
- return self.com_obj.Path
1739
-
1740
- def execute_all(self) -> None:
1741
- self.com_obj.ExecuteAll()
1742
-
1743
- def save(self, name: str, prompt_user=False) -> None:
1744
- self.com_obj.Save(name, prompt_user)
1745
-
1746
- def save_as(self, name: str, major: int, minor: int, prompt_user=False) -> None:
1747
- self.com_obj.SaveAs(name, major, minor, prompt_user)
1748
-
1749
- def stop_sequence(self) -> None:
1750
- self.com_obj.StopSequence()
1751
-
1752
- def update_all_test_setup_folders(self, tsfs_instance=None):
1753
- if tsfs_instance is None:
1754
- tsfs_instance = self.__test_setup_folders
1755
- if tsfs_instance.count > 0:
1756
- test_setup_folders = tsfs_instance.fetch_test_setup_folders()
1757
- for tsf_name, tsf_inst in test_setup_folders.items():
1758
- self.__all_test_setup_folders[tsf_name] = tsf_inst
1759
- if tsf_inst.test_modules.count > 0:
1760
- self.__all_test_modules.update(tsf_inst.test_modules.fetch_test_modules())
1761
- if tsf_inst.folders.count > 0:
1762
- tsfs_instance = tsf_inst.folders
1763
- self.update_all_test_setup_folders(tsfs_instance)
1764
-
1765
- def get_all_test_modules(self):
1766
- self.update_all_test_setup_folders()
1767
- self.__all_test_modules.update(self.__test_modules.fetch_test_modules())
1768
- return self.__all_test_modules
1769
-
1770
-
1771
- class CanoeConfigurationTestSetupTestEnvironmentsTestEnvironmentTestSetupFolders:
1772
- """The TestSetupFolders object represents the folders in a test environment or in a test setup folder."""
1773
- def __init__(self, test_env_com_obj) -> None:
1774
- self.com_obj = test_env_com_obj.Folders
1775
-
1776
- @property
1777
- def count(self) -> int:
1778
- return self.com_obj.Count
1779
-
1780
- def add(self, full_name: str) -> object:
1781
- return self.com_obj.Add(full_name)
1782
-
1783
- def remove(self, index: int, prompt_user=False) -> None:
1784
- self.com_obj.Remove(index, prompt_user)
1785
-
1786
- def fetch_test_setup_folders(self) -> dict:
1787
- test_setup_folders = dict()
1788
- for index in range(1, self.count + 1):
1789
- tsf_com_obj = win32com.client.Dispatch(self.com_obj.Item(index))
1790
- tsf_inst = CanoeConfigurationTestSetupTestEnvironmentsTestEnvironmentTestSetupFoldersTestSetupFolderExt(tsf_com_obj)
1791
- test_setup_folders[tsf_inst.name] = tsf_inst
1792
- return test_setup_folders
1793
-
1794
-
1795
- class CanoeConfigurationTestSetupTestEnvironmentsTestEnvironmentTestSetupFoldersTestSetupFolderExt:
1796
- """The TestSetupFolderExt object represents a directory in CANoe's test setup."""
1797
- def __init__(self, test_setup_folder_ext_com_obj) -> None:
1798
- self.com_obj = test_setup_folder_ext_com_obj
1799
-
1800
- @property
1801
- def enabled(self) -> bool:
1802
- return self.com_obj.Enabled
1803
-
1804
- @enabled.setter
1805
- def enabled(self, enabled: bool) -> None:
1806
- self.com_obj.Enabled = enabled
1807
-
1808
- @property
1809
- def name(self):
1810
- return self.com_obj.Name
1811
-
1812
- @property
1813
- def folders(self):
1814
- return CanoeConfigurationTestSetupTestEnvironmentsTestEnvironmentTestSetupFolders(self.com_obj)
1815
-
1816
- @property
1817
- def test_modules(self):
1818
- return CanoeConfigurationTestSetupTestEnvironmentsTestEnvironmentTestModules(self.com_obj)
1819
-
1820
- def execute_all(self):
1821
- self.com_obj.ExecuteAll()
1822
-
1823
- def stop_sequence(self):
1824
- self.com_obj.StopSequence()
1825
-
1826
-
1827
- class CanoeConfigurationTestSetupTestEnvironmentsTestEnvironmentTestModules:
1828
- """The TestModules object represents the test modules in a test environment or in a test setup folder.
1829
- This object should be preferred to the TestSetupItems object.
1830
- """
1831
-
1832
- def __init__(self, test_env_com_obj) -> None:
1833
- self.com_obj = test_env_com_obj.TestModules
1834
-
1835
- @property
1836
- def count(self) -> int:
1837
- return self.com_obj.Count
1838
-
1839
- def add(self, full_name: str) -> object:
1840
- return self.com_obj.Add(full_name)
1841
-
1842
- def remove(self, index: int, prompt_user=False) -> None:
1843
- self.com_obj.Remove(index, prompt_user)
1844
-
1845
- def fetch_test_modules(self) -> dict:
1846
- test_modules = dict()
1847
- for index in range(1, self.count + 1):
1848
- tm_com_obj = self.com_obj.Item(index)
1849
- tm_inst = CanoeConfigurationTestSetupTestEnvironmentsTestEnvironmentTestModulesTestModule(tm_com_obj)
1850
- test_modules[tm_inst.name] = tm_inst
1851
- return test_modules
1852
-
1853
-
1854
- class CanoeConfigurationTestSetupTestEnvironmentsTestEnvironmentTestModulesTestModuleEvents:
1855
- """test module events object."""
1856
- def __init__(self):
1857
- self.tm_html_report_path = ''
1858
- self.tm_report_generated = False
1859
- self.tm_running = False
1860
-
1861
- def OnStart(self):
1862
- self.tm_html_report_path = ''
1863
- self.tm_report_generated = False
1864
- self.tm_running = True
1865
- # logging.getLogger('CANOE_LOG').debug(f'👉test module OnStart event')
1866
-
1867
- @staticmethod
1868
- def OnPause():
1869
- logging.getLogger('CANOE_LOG').debug(f'👉test module OnPause event')
1870
-
1871
- def OnStop(self, reason):
1872
- self.tm_running = False
1873
- # logging.getLogger('CANOE_LOG').debug(f'👉test module OnStop event. reason -> {reason}')
1874
-
1875
- def OnReportGenerated(self, success, source_full_name, generated_full_name):
1876
- self.tm_html_report_path = generated_full_name
1877
- self.tm_report_generated = success
1878
- self.tm_running = False
1879
- logging.getLogger('CANOE_LOG').debug(f'👉test module OnReportGenerated event. {success} # {source_full_name} # {generated_full_name}')
1880
-
1881
- def OnVerdictFail(self):
1882
- # logging.getLogger('CANOE_LOG').debug(f'👉test module OnVerdictFail event')
1883
- pass
1884
-
1885
-
1886
- class CanoeConfigurationTestSetupTestEnvironmentsTestEnvironmentTestModulesTestModule:
1887
- """The TestModule object represents a test module in CANoe's test setup."""
1888
-
1889
- def __init__(self, test_module_com_obj):
1890
- try:
1891
- self.__log = logging.getLogger('CANOE_LOG')
1892
- self.com_obj = win32com.client.DispatchWithEvents(test_module_com_obj, CanoeConfigurationTestSetupTestEnvironmentsTestEnvironmentTestModulesTestModuleEvents)
1893
- self.wait_for_tm_to_start = lambda: DoTestModuleEventsUntil(lambda: self.com_obj.tm_running)
1894
- self.wait_for_tm_to_stop = lambda: DoTestModuleEventsUntil(lambda: not self.com_obj.tm_running)
1895
- self.wait_for_tm_report_gen = lambda: DoTestModuleEventsUntil(lambda: self.com_obj.tm_report_generated)
1896
- except Exception as e:
1897
- self.__log.error(f'😡 Error initializing CANoe test module: {str(e)}')
1898
-
1899
- @property
1900
- def name(self) -> str:
1901
- return self.com_obj.Name
1902
-
1903
- @property
1904
- def full_name(self) -> str:
1905
- return self.com_obj.FullName
1906
-
1907
- @property
1908
- def path(self) -> str:
1909
- return self.com_obj.Path
1910
-
1911
- @property
1912
- def verdict(self) -> int:
1913
- return self.com_obj.Verdict
1914
-
1915
- def start(self):
1916
- self.com_obj.Start()
1917
- self.wait_for_tm_to_start()
1918
- logging.getLogger('CANOE_LOG').debug(f'👉 started executing test module. waiting for completion')
1919
-
1920
- def wait_for_completion(self):
1921
- self.wait_for_tm_to_stop()
1922
- wait(1)
1923
- logging.getLogger('CANOE_LOG').debug(f'👉 completed executing test module. verdict = {self.verdict}')
1924
-
1925
- def pause(self) -> None:
1926
- self.com_obj.Pause()
1927
-
1928
- def resume(self) -> None:
1929
- self.com_obj.Resume()
1930
-
1931
- def stop(self) -> None:
1932
- self.com_obj.Stop()
1933
- logging.getLogger('CANOE_LOG').debug(f'👉stopping test module. waiting for completion')
1934
- self.wait_for_tm_to_stop()
1935
- logging.getLogger('CANOE_LOG').debug(f'👉completed stopping test module')
1936
-
1937
- def reload(self) -> None:
1938
- self.com_obj.Reload()
1939
-
1940
- def set_execution_time(self, days: int, hours: int, minutes: int):
1941
- self.com_obj.SetExecutionTime(days, hours, minutes)
1942
-
1943
-
1944
- class CanoeEnvironment:
1945
- """The Environment class represents the environment variables.
1946
- The Environment class is only available in CANoe
1947
- """
1948
- def __init__(self, application_com_obj):
1949
- try:
1950
- self.__log = logging.getLogger('CANOE_LOG')
1951
- self.com_obj = win32com.client.Dispatch(application_com_obj.Environment)
1952
- except Exception as e:
1953
- self.__log.error(f'😡 Error initializing Environment object: {str(e)}')
1954
-
1955
- def create_group(self):
1956
- return CanoeEnvironmentGroup(self.com_obj.CreateGroup())
1957
-
1958
- def create_info(self):
1959
- return CanoeEnvironmentInfo(self.com_obj.CreateInfo())
1960
-
1961
- def get_variable(self, name: str):
1962
- return CanoeEnvironmentVariable(self.com_obj.GetVariable(name))
1963
-
1964
- def get_variables(self, list_of_variable_names: tuple):
1965
- return self.com_obj.GetVariables(list_of_variable_names)
1966
-
1967
- def set_variables(self, list_of_variables_with_name_value: tuple):
1968
- self.com_obj.SetVariables(list_of_variables_with_name_value)
1969
-
1970
-
1971
- class CanoeEnvironmentGroup:
1972
- """The EnvironmentGroup class represents a group of environment variables.
1973
- With the help of environment variable groups you can set or query multiple environment variables simultaneously with just one call.
1974
- """
1975
- def __init__(self, env_group_com_obj):
1976
- self.com_obj = env_group_com_obj
1977
-
1978
- @property
1979
- def array(self):
1980
- return CanoeEnvironmentArray(self.com_obj.Array)
1981
-
1982
- def add(self, variable):
1983
- self.com_obj.Add(variable)
1984
-
1985
- def get_values(self):
1986
- return self.com_obj.GetValues()
1987
-
1988
- def remove(self, variable):
1989
- self.com_obj.Variable(variable)
1990
-
1991
- def set_values(self, values):
1992
- self.com_obj.SetValues(values)
1993
-
1994
-
1995
- class CanoeEnvironmentArray:
1996
- """The EnvironmentArray class represents an array of environment variables."""
1997
- def __init__(self, env_array_com_obj):
1998
- self.com_obj = env_array_com_obj
1999
-
2000
- @property
2001
- def count(self) -> int:
2002
- return self.com_obj.Count
2003
-
2004
-
2005
- class CanoeEnvironmentVariableEvents:
2006
- def __init__(self):
2007
- self.var_event_occurred = False
2008
-
2009
- def OnChange(self, value):
2010
- self.var_event_occurred = True
2011
-
2012
-
2013
- class CanoeEnvironmentVariable:
2014
- def __init__(self, env_var_com_obj):
2015
- try:
2016
- self.__log = logging.getLogger('CANOE_LOG')
2017
- self.com_obj = win32com.client.DispatchWithEvents(env_var_com_obj, CanoeEnvironmentVariableEvents)
2018
- self.wait_for_var_event = lambda: DoEnvVarEventsUntil(lambda: self.com_obj.var_event_occurred)
2019
- except Exception as e:
2020
- self.__log.error(f'😡 Error initializing EnvironmentVariable object: {str(e)}')
2021
-
2022
- @property
2023
- def handle(self):
2024
- return self.com_obj.Handle
2025
-
2026
- @handle.setter
2027
- def handle(self, value):
2028
- self.com_obj.Handle = value
2029
-
2030
- @property
2031
- def notification_type(self):
2032
- return self.com_obj.NotificationType
2033
-
2034
- @notification_type.setter
2035
- def notification_type(self, value: int):
2036
- self.com_obj.NotificationType = value
2037
-
2038
- @property
2039
- def type(self):
2040
- return self.com_obj.Type
2041
-
2042
- @property
2043
- def value(self):
2044
- return self.com_obj.Value
2045
-
2046
- @value.setter
2047
- def value(self, value):
2048
- self.com_obj.Value = value
2049
- wait(0.1)
2050
-
2051
-
2052
- class CanoeEnvironmentInfo:
2053
- def __init__(self, env_info_com_obj):
2054
- self.com_obj = env_info_com_obj
2055
-
2056
- @property
2057
- def read(self):
2058
- return self.com_obj.Read
2059
-
2060
- @property
2061
- def write(self):
2062
- return self.com_obj.Write
2063
-
2064
- def get_info(self):
2065
- return self.com_obj.GetInfo()
2066
-
2067
-
2068
- class CanoeMeasurementEvents:
2069
- application_com_obj = object
2070
- user_capl_function_names = tuple()
2071
- user_capl_function_obj_dict = dict()
2072
-
2073
- @staticmethod
2074
- def OnInit():
2075
- application_com_obj_loc = CanoeMeasurementEvents.application_com_obj
2076
- for fun in CanoeMeasurementEvents.user_capl_function_names:
2077
- CanoeMeasurementEvents.user_capl_function_obj_dict[fun] = application_com_obj_loc.CAPL.GetFunction(fun)
2078
- CANoe.CANOE_MEASUREMENT_STARTED = False
2079
- CANoe.CANOE_MEASUREMENT_STOPPED = False
2080
-
2081
-
2082
- @staticmethod
2083
- def OnStart():
2084
- CANoe.CANOE_MEASUREMENT_STARTED = True
2085
- CANoe.CANOE_MEASUREMENT_STOPPED = False
2086
-
2087
-
2088
- @staticmethod
2089
- def OnStop():
2090
- CANoe.CANOE_MEASUREMENT_STARTED = False
2091
- CANoe.CANOE_MEASUREMENT_STOPPED = True
2092
-
2093
- @staticmethod
2094
- def OnExit():
2095
- CANoe.CANOE_MEASUREMENT_STARTED = False
2096
- CANoe.CANOE_MEASUREMENT_STOPPED = False
2097
-
2098
-
2099
- class CanoeNetworks:
2100
- """The Networks class represents the networks of CANoe."""
2101
- def __init__(self, networks_com_obj):
2102
- try:
2103
- self.log = logging.getLogger('CANOE_LOG')
2104
- self.com_obj = networks_com_obj
2105
- except Exception as e:
2106
- self.log.error(f'😡 Error initializing Networks object: {str(e)}')
2107
-
2108
- @property
2109
- def count(self) -> int:
2110
- return self.com_obj.Count
2111
-
2112
- def fetch_all_networks(self) -> dict:
2113
- networks = dict()
2114
- for index in range(1, self.count + 1):
2115
- network_com_obj = win32com.client.Dispatch(self.com_obj.Item(index))
2116
- network = CanoeNetworksNetwork(network_com_obj)
2117
- networks[network_com_obj.Name] = network
2118
- return networks
2119
-
2120
- def fetch_all_diag_devices(self) -> dict:
2121
- diag_devices = dict()
2122
- networks = self.fetch_all_networks()
2123
- if len(networks) > 0:
2124
- for _, n_value in networks.items():
2125
- devices = n_value.devices
2126
- n_devices = devices.get_all_devices()
2127
- if len(n_devices) > 0:
2128
- for d_name, d_value in n_devices.items():
2129
- if d_value.diagnostic is not None:
2130
- diag_devices[d_name] = d_value.diagnostic
2131
- return diag_devices
2132
-
2133
-
2134
- class CanoeNetworksNetwork:
2135
- """The Network class represents one single network of CANoe."""
2136
- def __init__(self, network_com_obj):
2137
- self.com_obj = network_com_obj
2138
-
2139
- @property
2140
- def bus_type(self) -> int:
2141
- return self.com_obj.BusType
2142
-
2143
- @property
2144
- def devices(self) -> object:
2145
- return CanoeNetworksNetworkDevices(self.com_obj)
2146
-
2147
- @property
2148
- def name(self) -> str:
2149
- return self.com_obj.Name
2150
-
2151
-
2152
- class CanoeNetworksNetworkDevices:
2153
- """The Devices class represents all devices of CANoe."""
2154
- def __init__(self, network_com_obj):
2155
- self.com_obj = network_com_obj.Devices
2156
-
2157
- @property
2158
- def count(self) -> int:
2159
- return self.com_obj.Count
2160
-
2161
- def get_all_devices(self) -> dict:
2162
- devices = dict()
2163
- for index in range(1, self.count + 1):
2164
- device_com_obj = self.com_obj.Item(index)
2165
- device = CanoeNetworksNetworkDevicesDevice(device_com_obj)
2166
- devices[device.name] = device
2167
- return devices
2168
-
2169
-
2170
- class CanoeNetworksNetworkDevicesDevice:
2171
- """The Device class represents one single device of CANoe."""
2172
- def __init__(self, device_com_obj):
2173
- self.com_obj = device_com_obj
2174
-
2175
- @property
2176
- def name(self) -> str:
2177
- return self.com_obj.Name
2178
-
2179
- @property
2180
- def diagnostic(self):
2181
- try:
2182
- diag_com_obj = self.com_obj.Diagnostic
2183
- return CanoeNetworksNetworkDevicesDeviceDiagnostic(diag_com_obj)
2184
- except pythoncom.com_error:
2185
- return None
2186
-
2187
-
2188
- class CanoeNetworksNetworkDevicesDeviceDiagnostic:
2189
- """The Diagnostic class represents the diagnostic properties of an ECU on the bus or the basic diagnostic functionality of a CANoe network.
2190
- It is identified by the ECU qualifier that has been specified for the loaded diagnostic description (CDD/ODX).
2191
- """
2192
- def __init__(self, diagnostic_com_obj):
2193
- self.com_obj = diagnostic_com_obj
2194
-
2195
- @property
2196
- def tester_present_status(self) -> bool:
2197
- return self.com_obj.TesterPresentStatus
2198
-
2199
- def create_request(self, primitive_path: str):
2200
- return CanoeNetworksNetworkDevicesDeviceDiagnosticRequest(self.com_obj.CreateRequest(primitive_path))
2201
-
2202
- def create_request_from_stream(self, byte_stream: str):
2203
- diag_req_in_bytes = bytearray()
2204
- byte_stream = ''.join(byte_stream.split(' '))
2205
- for i in range(0, len(byte_stream), 2):
2206
- diag_req_in_bytes.append(int(byte_stream[i:i + 2], 16))
2207
- return CanoeNetworksNetworkDevicesDeviceDiagnosticRequest(self.com_obj.CreateRequestFromStream(diag_req_in_bytes))
2208
-
2209
- def start_tester_present(self) -> None:
2210
- self.com_obj.DiagStartTesterPresent()
2211
-
2212
- def stop_tester_present(self) -> None:
2213
- self.com_obj.DiagStopTesterPresent()
2214
-
2215
-
2216
- class CanoeNetworksNetworkDevicesDeviceDiagnosticRequest:
2217
- """The DiagnosticRequest class represents the query of a diagnostic tester (client) to an ECU (server) in CANoe.
2218
- It can be replied by a DiagnosticResponse object.
2219
- """
2220
- def __init__(self, diag_req_com_obj):
2221
- self.com_obj = diag_req_com_obj
2222
-
2223
- @property
2224
- def pending(self) -> bool:
2225
- return self.com_obj.Pending
2226
-
2227
- @property
2228
- def responses(self) -> list:
2229
- diag_responses_com_obj = self.com_obj.Responses
2230
- diag_responses = [CanoeNetworksNetworkDevicesDeviceDiagnosticResponse(diag_responses_com_obj.item(i)) for i in range(1, diag_responses_com_obj.Count + 1)]
2231
- return diag_responses
2232
-
2233
- @property
2234
- def suppress_positive_response(self):
2235
- return self.com_obj.SuppressPositiveResponse
2236
-
2237
- def send(self):
2238
- self.com_obj.Send()
2239
-
2240
- def set_complex_parameter(self, qualifier, iteration, sub_parameter, value):
2241
- self.com_obj.SetComplexParameter(qualifier, iteration, sub_parameter, value)
2242
-
2243
- def set_parameter(self, qualifier, value):
2244
- self.com_obj.SetParameter(qualifier, value)
2245
-
2246
-
2247
- class CanoeNetworksNetworkDevicesDeviceDiagnosticResponse:
2248
- """The DiagnosticResponse class represents the ECU's reply to a diagnostic request in CANoe.
2249
- The received parameters can be read out and processed.
2250
- """
2251
- def __init__(self, diag_res_com_obj):
2252
- self.com_obj = diag_res_com_obj
2253
-
2254
- @property
2255
- def positive(self) -> bool:
2256
- return self.com_obj.Positive
2257
-
2258
- @property
2259
- def response_code(self) -> int:
2260
- return self.com_obj.ResponseCode
2261
-
2262
- @property
2263
- def stream(self) -> str:
2264
- diag_response_data = " ".join(f"{d:02X}" for d in self.com_obj.Stream).upper()
2265
- return diag_response_data
2266
-
2267
- @property
2268
- def sender(self) -> str:
2269
- return self.com_obj.Sender
2270
-
2271
- def get_complex_iteration_count(self, qualifier):
2272
- return self.com_obj.GetComplexIterationCount(qualifier)
2273
-
2274
- def get_complex_parameter(self, qualifier, iteration, sub_parameter, mode):
2275
- return self.com_obj.GetComplexParameter(qualifier, iteration, sub_parameter, mode)
2276
-
2277
- def get_parameter(self, qualifier, mode):
2278
- return self.com_obj.GetParameter(qualifier, mode)
2279
-
2280
- def is_complex_parameter(self, qualifier):
2281
- return self.com_obj.IsComplexParameter(qualifier)
2282
-
2283
-
2284
- class CanoeSystem:
2285
- """The System object represents the system of the CANoe application.
2286
- The System object offers access to the namespaces for data exchange with external applications.
2287
- """
2288
- def __init__(self, system_com_obj):
2289
- try:
2290
- self.__log = logging.getLogger('CANOE_LOG')
2291
- self.com_obj = system_com_obj
2292
- self.namespaces_com_obj = win32com.client.Dispatch(self.com_obj.Namespaces)
2293
- self.variables_files_com_obj = win32com.client.Dispatch(self.com_obj.VariablesFiles)
2294
- self.namespaces_dict = {}
2295
- self.variables_files_dict = {}
2296
- self.variables_dict = {}
2297
- except Exception as e:
2298
- self.__log.error(f'😡 Error initializing CANoe System: {str(e)}')
2299
-
2300
- @property
2301
- def namespaces_count(self) -> int:
2302
- return self.namespaces_com_obj.Count
2303
-
2304
- def fetch_namespaces(self) -> dict:
2305
- if self.namespaces_count > 0:
2306
- for index in range(1, self.namespaces_count + 1):
2307
- namespace_com_obj = win32com.client.Dispatch(self.namespaces_com_obj.Item(index))
2308
- namespace_name = namespace_com_obj.Name
2309
- self.namespaces_dict[namespace_name] = namespace_com_obj
2310
- if 'Namespaces' in dir(namespace_com_obj):
2311
- self.fetch_namespace_namespaces(namespace_com_obj, namespace_name)
2312
- if 'Variables' in dir(namespace_com_obj):
2313
- self.fetch_namespace_variables(namespace_com_obj)
2314
- return self.namespaces_dict
2315
-
2316
- def add_namespace(self, name: str):
2317
- self.fetch_namespaces()
2318
- if name not in self.namespaces_dict.keys():
2319
- namespace_com_obj = self.namespaces_com_obj.Add(name)
2320
- self.namespaces_dict[name] = namespace_com_obj
2321
- self.__log.debug(f'➕ Added the new namespace ({name})')
2322
- return namespace_com_obj
2323
- else:
2324
- self.__log.warning(f'⚠️ The given namespace ({name}) already exists')
2325
- return None
2326
-
2327
- def remove_namespace(self, name: str) -> None:
2328
- self.fetch_namespaces()
2329
- if name in self.namespaces_list:
2330
- self.namespaces_com_obj.Remove(name)
2331
- self.fetch_namespaces()
2332
- self.__log.debug(f'➖ Removed the namespace ({name}) from the collection')
2333
- else:
2334
- self.__log.warning(f'⚠️ The given namespace ({name}) does not exist')
2335
-
2336
- @property
2337
- def variables_files_count(self) -> int:
2338
- return self.variables_files_com_obj.Count
2339
-
2340
- def fetch_variables_files(self):
2341
- if self.variables_files_count > 0:
2342
- for index in range(1, self.variables_files_count + 1):
2343
- variable_file_com_obj = self.variables_files_com_obj.Item(index)
2344
- self.variables_files_dict[variable_file_com_obj.Name] = {'full_name': variable_file_com_obj.FullName,
2345
- 'path': variable_file_com_obj.Path,
2346
- 'index': index}
2347
- return self.variables_files_dict
2348
-
2349
- def add_variables_file(self, variables_file: str):
2350
- self.fetch_variables_files()
2351
- if os.path.isfile(variables_file):
2352
- self.variables_files_com_obj.Add(variables_file)
2353
- self.fetch_variables_files()
2354
- self.__log.debug(f'➕ Added the Variables file ({variables_file}) to the collection')
2355
- else:
2356
- self.__log.warning(f'⚠️ The given file ({variables_file}) does not exist')
2357
-
2358
- def remove_variables_file(self, variables_file_name: str):
2359
- self.fetch_variables_files()
2360
- if variables_file_name in self.variables_files_dict:
2361
- self.variables_files_com_obj.Remove(variables_file_name)
2362
- self.fetch_variables_files()
2363
- self.__log.debug(f'➖ Removed the Variables file ({variables_file_name}) from the collection')
2364
- else:
2365
- self.__log.warning(f'⚠️ The given file ({variables_file_name}) does not exist')
2366
-
2367
- def fetch_namespace_namespaces(self, parent_namespace_com_obj, parent_namespace_name):
2368
- namespaces_count = parent_namespace_com_obj.Namespaces.Count
2369
- if namespaces_count > 0:
2370
- for index in range(1, namespaces_count + 1):
2371
- namespace_com_obj = win32com.client.Dispatch(parent_namespace_com_obj.Namespaces.Item(index))
2372
- namespace_name = f'{parent_namespace_name}::{namespace_com_obj.Name}'
2373
- self.namespaces_dict[namespace_name] = namespace_com_obj
2374
- if 'Namespaces' in dir(namespace_com_obj):
2375
- self.fetch_namespace_namespaces(namespace_com_obj, namespace_name)
2376
- if 'Variables' in dir(namespace_com_obj):
2377
- self.fetch_namespace_variables(namespace_com_obj)
2378
-
2379
- def fetch_namespace_variables(self, parent_namespace_com_obj):
2380
- variables_count = parent_namespace_com_obj.Variables.Count
2381
- if variables_count > 0:
2382
- for index in range(1, variables_count + 1):
2383
- variable_obj = CanoeSystemVariable(parent_namespace_com_obj.Variables.Item(index))
2384
- self.variables_dict[variable_obj.full_name] = variable_obj
2385
-
2386
- def add_system_variable(self, namespace, variable, value):
2387
- self.fetch_namespaces()
2388
- if f'{namespace}::{variable}' in self.variables_dict.keys():
2389
- self.__log.warning(f'⚠️ The given variable ({variable}) already exists in the namespace ({namespace})')
2390
- return None
2391
- else:
2392
- self.add_namespace(namespace)
2393
- return self.namespaces_dict[namespace].Variables.Add(variable, value)
2394
-
2395
- def remove_system_variable(self, namespace, variable):
2396
- self.fetch_namespaces()
2397
- if f'{namespace}::{variable}' not in self.variables_dict.keys():
2398
- self.__log.warning(f'⚠️ The given variable ({variable}) already removed in the namespace ({namespace})')
2399
- return None
2400
- else:
2401
- self.namespaces_dict[namespace].Variables.Remove(variable)
2402
-
2403
-
2404
- class CanoeSystemVariable:
2405
- def __init__(self, variable_com_obj):
2406
- try:
2407
- self.com_obj = win32com.client.Dispatch(variable_com_obj)
2408
- except Exception as e:
2409
- self.__log.error(f'😡 Error initializing CANoe Variable: {str(e)}')
2410
-
2411
- @property
2412
- def analysis_only(self) -> bool:
2413
- return self.com_obj.AnalysisOnly
2414
-
2415
- @analysis_only.setter
2416
- def analysis_only(self, value: bool) -> None:
2417
- self.com_obj.AnalysisOnly = value
2418
-
2419
- @property
2420
- def bit_count(self) -> int:
2421
- return self.com_obj.BitCount
2422
-
2423
- @property
2424
- def comment(self) -> str:
2425
- return self.com_obj.Comment
2426
-
2427
- @comment.setter
2428
- def comment(self, text: str) -> None:
2429
- self.com_obj.Comment = text
2430
-
2431
- @property
2432
- def element_count(self) -> int:
2433
- return self.com_obj.ElementCount
2434
-
2435
- @property
2436
- def full_name(self) -> str:
2437
- return self.com_obj.FullName
2438
-
2439
- @full_name.setter
2440
- def full_name(self, full_name: str) -> None:
2441
- self.com_obj.FullName = full_name
2442
-
2443
- @property
2444
- def name(self) -> str:
2445
- return self.com_obj.Name
2446
-
2447
- @property
2448
- def init_value(self) -> tuple[int, float, str]:
2449
- return self.com_obj.InitValue
2450
-
2451
- @property
2452
- def min_value(self) -> tuple[int, float, str]:
2453
- return self.com_obj.MinValue
2454
-
2455
- @property
2456
- def max_value(self) -> tuple[int, float, str]:
2457
- return self.com_obj.MaxValue
2458
-
2459
- @property
2460
- def is_array(self) -> bool:
2461
- return self.com_obj.IsArray
2462
-
2463
- @property
2464
- def is_signed(self) -> bool:
2465
- return self.com_obj.IsSigned
2466
-
2467
- @property
2468
- def read_only(self) -> bool:
2469
- return self.com_obj.ReadOnly
2470
-
2471
- @property
2472
- def type(self) -> int:
2473
- return self.com_obj.Type
2474
-
2475
- @property
2476
- def unit(self) -> str:
2477
- return self.com_obj.Unit
2478
-
2479
- @property
2480
- def value(self) -> tuple[int, float, str]:
2481
- return self.com_obj.Value
2482
-
2483
- @value.setter
2484
- def value(self, value: tuple[int, float, str]) -> None:
2485
- self.com_obj.Value = value
2486
-
2487
- def get_member_phys_value(self, member_name: str):
2488
- return self.com_obj.GetMemberPhysValue(member_name)
2489
-
2490
- def get_member_value(self, member_name: str):
2491
- return self.com_obj.GetMemberValue(member_name)
2492
-
2493
- def get_symbolic_value_name(self, value: int):
2494
- return self.com_obj.GetSymbolicValueName(value)
2495
-
2496
- def set_member_phys_value(self, member_name: str, value):
2497
- return self.com_obj.setMemberPhysValue(member_name, value)
2498
-
2499
- def set_member_value(self, member_name: str, value):
2500
- return self.com_obj.setMemberValue(member_name, value)
2501
-
2502
- def set_symbolic_value_name(self, value: int, name: str):
2503
- self.com_obj.setSymbolicValueName(value, name)
1
+ from .py_canoe import CANoe, wait