@@ -33,7 +33,8 @@ class Network(MutableMapping):
33
33
NOTIFIER_CYCLE : float = 1.0 #: Maximum waiting time for one notifier iteration.
34
34
NOTIFIER_SHUTDOWN_TIMEOUT : float = 5.0 #: Maximum waiting time to stop notifiers.
35
35
36
- def __init__ (self , bus : Optional [can .BusABC ] = None , loop : Optional [AbstractEventLoop ] = None ):
36
+ def __init__ (self , bus : Optional [can .BusABC ] = None , notifier : Optional [can .Notifier ] = None ,
37
+ loop : Optional [AbstractEventLoop ] = None ):
37
38
"""
38
39
:param can.BusABC bus:
39
40
A python-can bus instance to re-use.
@@ -47,7 +48,7 @@ def __init__(self, bus: Optional[can.BusABC] = None, loop: Optional[AbstractEven
47
48
#: List of :class:`can.Listener` objects.
48
49
#: Includes at least MessageListener.
49
50
self .listeners = [MessageListener (self )]
50
- self .notifier : Optional [can .Notifier ] = None
51
+ self .notifier : Optional [can .Notifier ] = notifier
51
52
self .nodes : Dict [int , Union [RemoteNode , LocalNode ]] = {}
52
53
self .subscribers : Dict [int , List [Callback ]] = {}
53
54
self .send_lock = threading .Lock ()
@@ -59,6 +60,11 @@ def __init__(self, bus: Optional[can.BusABC] = None, loop: Optional[AbstractEven
59
60
self .lss = LssMaster ()
60
61
self .lss .network = self
61
62
63
+ # Register this function as the means to check if canopen is run in
64
+ # async mode. This enables the @ensure_not_async() decorator to
65
+ # work. See async_guard.py
66
+ set_async_sentinel (self .is_async )
67
+
62
68
if self .is_async ():
63
69
self .subscribe (self .lss .LSS_RX_COBID , self .lss .aon_message_received )
64
70
else :
@@ -117,19 +123,13 @@ def connect(self, *args, **kwargs) -> Network:
117
123
if node .object_dictionary .bitrate :
118
124
kwargs ["bitrate" ] = node .object_dictionary .bitrate
119
125
break
120
- # The optional loop parameter goes to can.Notifier()
121
- kwargs_notifier = {}
122
- if "loop" in kwargs :
123
- self .loop = kwargs .pop ("loop" )
124
- kwargs_notifier ["loop" ] = self .loop
125
- # Register this function as the means to check if canopen is run in
126
- # async mode. This enables the @ensure_not_async() decorator to
127
- # work. See async_guard.py
128
- set_async_sentinel (self .is_async )
129
126
if self .bus is None :
130
127
self .bus = can .Bus (* args , ** kwargs )
131
128
logger .info ("Connected to '%s'" , self .bus .channel_info )
132
- self .notifier = can .Notifier (self .bus , self .listeners , self .NOTIFIER_CYCLE , ** kwargs_notifier )
129
+ if self .notifier is None :
130
+ self .notifier = can .Notifier (self .bus , [], self .NOTIFIER_CYCLE , loop = self .loop )
131
+ for listener in self .listeners :
132
+ self .notifier .add_listener (listener )
133
133
return self
134
134
135
135
def disconnect (self ) -> None :
0 commit comments