99 from can import BusABC , Notifier
1010 from asyncio import AbstractEventLoop
1111
12- try :
13- import can
14- from can import Listener
15- from can import CanError
16- except ImportError :
17- # Do not fail if python-can is not installed
18- can = None
19- CanError = Exception
20- class Listener :
21- """ Dummy listener """
12+ import can
13+ from can import Listener
14+ from can import CanError
2215
2316from canopen .node import RemoteNode , LocalNode
2417from canopen .sync import SyncProducer
@@ -37,11 +30,10 @@ class Listener:
3730class Network (MutableMapping ):
3831 """Representation of one CAN bus containing one or more nodes."""
3932
40- def __init__ (
41- self ,
42- bus : Optional [BusABC ] = None ,
43- loop : Optional [AbstractEventLoop ] = None
44- ):
33+ NOTIFIER_CYCLE : float = 1.0 #: Maximum waiting time for one notifier iteration.
34+ NOTIFIER_SHUTDOWN_TIMEOUT : float = 5.0 #: Maximum waiting time to stop notifiers.
35+
36+ def __init__ (self , bus : Optional [can .BusABC ] = None , loop : Optional [AbstractEventLoop ] = None ):
4537 """
4638 :param can.BusABC bus:
4739 A python-can bus instance to re-use.
@@ -55,7 +47,7 @@ def __init__(
5547 #: List of :class:`can.Listener` objects.
5648 #: Includes at least MessageListener.
5749 self .listeners = [MessageListener (self )]
58- self .notifier : Optional [Notifier ] = None
50+ self .notifier : Optional [can . Notifier ] = None
5951 self .nodes : Dict [int , Union [RemoteNode , LocalNode ]] = {}
6052 self .subscribers : Dict [int , List [Callback ]] = {}
6153 self .send_lock = threading .Lock ()
@@ -106,7 +98,7 @@ def connect(self, *args, **kwargs) -> Network:
10698
10799 :param channel:
108100 Backend specific channel for the CAN interface.
109- :param str bustype :
101+ :param str interface :
110102 Name of the interface. See
111103 `python-can manual <https://python-can.readthedocs.io/en/stable/configuration.html#interface-names>`__
112104 for full list of supported interfaces.
@@ -138,7 +130,7 @@ def connect(self, *args, **kwargs) -> Network:
138130 if self .bus is None :
139131 self .bus = can .Bus (* args , ** kwargs )
140132 logger .info ("Connected to '%s'" , self .bus .channel_info )
141- self .notifier = can .Notifier (self .bus , self .listeners , 1 , ** kwargs_notifier )
133+ self .notifier = can .Notifier (self .bus , self .listeners , self . NOTIFIER_CYCLE , ** kwargs_notifier )
142134 return self
143135
144136 def disconnect (self ) -> None :
@@ -150,7 +142,7 @@ def disconnect(self) -> None:
150142 if hasattr (node , "pdo" ):
151143 node .pdo .stop ()
152144 if self .notifier is not None :
153- self .notifier .stop ()
145+ self .notifier .stop (self . NOTIFIER_SHUTDOWN_TIMEOUT )
154146 if self .bus is not None :
155147 self .bus .shutdown ()
156148 self .bus = None
@@ -352,7 +344,6 @@ def __init__(
352344 self .msg = can .Message (is_extended_id = can_id > 0x7FF ,
353345 arbitration_id = can_id ,
354346 data = data , is_remote_frame = remote )
355- self ._task = None
356347 self ._start ()
357348
358349 def _start (self ):
@@ -418,9 +409,6 @@ class NodeScanner:
418409 The network to use when doing active searching.
419410 """
420411
421- #: Activate or deactivate scanning
422- active = True
423-
424412 SERVICES = (0x700 , 0x580 , 0x180 , 0x280 , 0x380 , 0x480 , 0x80 )
425413
426414 def __init__ (self , network : Optional [Network ] = None ):
0 commit comments