@@ -468,7 +468,9 @@ class NodeScanner:
468468 SERVICES = (0x700 , 0x580 , 0x180 , 0x280 , 0x380 , 0x480 , 0x80 )
469469
470470 def __init__ (self , network : Optional [Network ] = None ):
471- self .network = network
471+ if network is None :
472+ network = _UNINITIALIZED_NETWORK
473+ self .network : Network = network
472474 #: A :class:`list` of nodes discovered
473475 self .nodes : List [int ] = []
474476
@@ -477,10 +479,6 @@ def on_message_received(self, can_id: int):
477479 service = can_id & 0x780
478480 node_id = can_id & 0x7F
479481 if node_id not in self .nodes and node_id != 0 and service in self .SERVICES :
480- # NOTE: In the current CPython implementation append on lists are
481- # atomic which makes this thread-safe. However, other py
482- # interpreters might not. It should be considered if a better
483- # mechanism is needed to protect against race.
484482 self .nodes .append (node_id )
485483
486484 def reset (self ):
@@ -489,9 +487,6 @@ def reset(self):
489487
490488 def search (self , limit : int = 127 ) -> None :
491489 """Search for nodes by sending SDO requests to all node IDs."""
492- if self .network is None :
493- raise RuntimeError ("A Network is required to do active scanning" )
494- # SDO upload request, parameter 0x1000:0x00
495490 sdo_req = b"\x40 \x00 \x10 \x00 \x00 \x00 \x00 \x00 "
496491 for node_id in range (1 , limit + 1 ):
497492 self .network .send_message (0x600 + node_id , sdo_req )
0 commit comments