-
Notifications
You must be signed in to change notification settings - Fork 1
/
CANoeTrace.py
33 lines (27 loc) · 1.1 KB
/
CANoeTrace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from typing import List, Union, Optional
from CANoeMessage import CANoeMessage
class CANoeTrace:
"""
Description: Responsible for reading signals in trace window
"""
def __init__(self, canoe_instance):
if not canoe_instance:
raise Exception("CANoe instance required for initializing trace class.")
self.canoe_instance = canoe_instance
self.messages: List[CANoeMessage] = []
self.canoe_bus = canoe_instance.Bus
def get_message_value_on_can_bus(self, message: CANoeMessage) -> Optional[str]:
"""
Returns data of message if valid message
Returns None if message is invalid and not found
"""
try:
self._verify_message_type_(message)
res = self.canoe_bus.GetSignal(message.channel, message.message, message.signal)
return str(res.Value)
except:
return None
@classmethod
def _verify_message_type_(cls, messages):
if type(messages) != CANoeMessage:
raise TypeError(f"Expected type: List[CANoeMessage] or CANoeMessage, got {type(messages)}")