8
8
9
9
10
10
class Message :
11
- """A class representing a CANbus data frame"""
11
+ """A class representing a CANbus data frame
12
+
13
+ :param int id: The numeric ID of the message
14
+ :param bytes data: The content of the message, from 0 to 8 bytes of data
15
+ :param bool extended: True if the message has an extended identifier,
16
+ False if it has a standard identifier
17
+ """
12
18
13
19
# pylint:disable=too-many-arguments,invalid-name,redefined-builtin
14
20
def __init__ (self , id , data , extended = False ):
15
- """Create a `Message` to send
16
-
17
- Args:
18
- id (int): The numeric ID of the message
19
- data (bytes): The content of the message
20
- extended (bool): True if the
21
- Raises:
22
- AttributeError: If `data` of type `bytes` is not provided for a non-RTR message
23
- AttributeError: If `data` is larger than 8 bytes
24
- """
25
-
26
21
self ._data = None
27
22
self .id = id
28
23
self .data = data
29
24
self .extended = extended
30
25
26
+ id : int
27
+ """The numeric ID of the message"""
28
+
29
+ extended : bool
30
+ """Indicates whether the the message has an extended identifier"""
31
+
31
32
@property
32
33
def data (self ):
33
- """The content of the message, or dummy content in the case of an rtr """
34
+ """The content of the message"""
34
35
return self ._data
35
36
36
37
@data .setter
@@ -50,28 +51,41 @@ def data(self, new_data):
50
51
51
52
52
53
class RemoteTransmissionRequest :
53
- """A class representing a CANbus remote frame"""
54
-
55
- def __init__ (self , id : int , length : int , * , extended : bool = False ):
56
- """Construct a RemoteTransmissionRequest to send on a CAN bus
54
+ """A class representing a CANbus remote frame
57
55
58
- Args:
59
- id ( int) : The numeric ID of the requested message
60
- length (int): The length of the requested message
61
- extended (bool, optional): True if the message has an extended identifier, False if it \
62
- has a standard identifier. Defaults to False.
56
+ :param int id: The numeric ID of the message
57
+ :param length int: The length of the requested message
58
+ :param bool extended: True if the message has an extended identifier,
59
+ False if it has a standard identifier
60
+ """
63
61
64
- """
62
+ def __init__ ( self , id : int , length : int , * , extended : bool = False ):
65
63
self .id = id
66
64
self .length = length
67
65
self .extended = extended
68
66
67
+ id : int
68
+ """The numeric ID of the message"""
69
+
70
+ extended : bool
71
+ """Indicates whether the the message has an extended identifier"""
72
+
73
+ length : int
74
+ """The length of the requested message, from 0 to 8"""
75
+
76
+
77
+ # Replace the above implementation with core canio implementation if it is available
78
+ try :
79
+ from canio import Message , RemoteTransmissionRequest
80
+ except ImportError :
81
+ pass
82
+
69
83
70
84
class Listener :
71
85
"""Listens for a CAN message
72
86
73
- canio.Listener is not constructed directly, but instead by calling the `listen` method of a \
74
- canio.CAN object.
87
+ canio.Listener is not constructed directly, but instead by calling the
88
+ ``listen`` method of a canio.CAN object.
75
89
"""
76
90
77
91
def __init__ (self , can_bus_obj , timeout = 1.0 ):
@@ -82,8 +96,8 @@ def __init__(self, can_bus_obj, timeout=1.0):
82
96
83
97
@property
84
98
def timeout (self ):
85
- """The maximum amount of time in seconds that `read` or `readinto` will wait before giving \
86
- up"""
99
+ """The maximum amount of time in seconds that `` read`` or `` readinto``
100
+ will wait before giving up"""
87
101
return self ._timeout
88
102
89
103
@timeout .setter
0 commit comments