@@ -33,7 +33,8 @@ class Network(MutableMapping):
3333 NOTIFIER_CYCLE : float = 1.0 #: Maximum waiting time for one notifier iteration.
3434 NOTIFIER_SHUTDOWN_TIMEOUT : float = 5.0 #: Maximum waiting time to stop notifiers.
3535
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 ):
3738 """
3839 :param can.BusABC bus:
3940 A python-can bus instance to re-use.
@@ -47,7 +48,7 @@ def __init__(self, bus: Optional[can.BusABC] = None, loop: Optional[AbstractEven
4748 #: List of :class:`can.Listener` objects.
4849 #: Includes at least MessageListener.
4950 self .listeners = [MessageListener (self )]
50- self .notifier : Optional [can .Notifier ] = None
51+ self .notifier : Optional [can .Notifier ] = notifier
5152 self .nodes : Dict [int , Union [RemoteNode , LocalNode ]] = {}
5253 self .subscribers : Dict [int , List [Callback ]] = {}
5354 self .send_lock = threading .Lock ()
@@ -59,6 +60,11 @@ def __init__(self, bus: Optional[can.BusABC] = None, loop: Optional[AbstractEven
5960 self .lss = LssMaster ()
6061 self .lss .network = self
6162
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+
6268 if self .is_async ():
6369 self .subscribe (self .lss .LSS_RX_COBID , self .lss .aon_message_received )
6470 else :
@@ -117,19 +123,13 @@ def connect(self, *args, **kwargs) -> Network:
117123 if node .object_dictionary .bitrate :
118124 kwargs ["bitrate" ] = node .object_dictionary .bitrate
119125 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 )
129126 if self .bus is None :
130127 self .bus = can .Bus (* args , ** kwargs )
131128 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 )
133133 return self
134134
135135 def disconnect (self ) -> None :
0 commit comments