11from __future__ import annotations
2+
23import logging
3- from typing import Union , TextIO , List , TYPE_CHECKING
4+ from typing import TextIO , Union , List
45
5- from canopen .sdo import SdoClient , SdoCommunicationError , SdoAbortedError
6- from canopen .nmt import NmtMaster
6+ import canopen .network
77from canopen .emcy import EmcyConsumer
8- from canopen .pdo import TPDO , RPDO , PDO
9- from canopen .objectdictionary import ODRecord , ODArray , ODVariable , ObjectDictionary
8+ from canopen .nmt import NmtMaster
109from canopen .node .base import BaseNode
10+ from canopen .objectdictionary import ODArray , ODRecord , ODVariable , ObjectDictionary
11+ from canopen .pdo import PDO , RPDO , TPDO
12+ from canopen .sdo import SdoAbortedError , SdoClient , SdoCommunicationError
1113
12- if TYPE_CHECKING :
13- from canopen .network import Network
1414
1515logger = logging .getLogger (__name__ )
1616
@@ -50,7 +50,7 @@ def __init__(
5050 if load_od :
5151 self .load_configuration ()
5252
53- def associate_network (self , network : Network ):
53+ def associate_network (self , network : canopen . network . Network ):
5454 self .network = network
5555 self .sdo .network = network
5656 self .pdo .network = network
@@ -67,23 +67,22 @@ def associate_network(self, network: Network):
6767 network .subscribe (0x80 + self .id , self .emcy .on_emcy )
6868 network .subscribe (0 , self .nmt .on_command )
6969
70- def remove_network (self ):
71- network = self .network
70+ def remove_network (self ) -> None :
7271 for sdo in self .sdo_channels :
73- network .unsubscribe (sdo .tx_cobid , sdo .on_response )
74- if network .is_async ():
75- network .unsubscribe (0x700 + self .id , self .nmt .aon_heartbeat )
76- network .unsubscribe (0x80 + self .id , self .emcy .aon_emcy )
72+ self . network .unsubscribe (sdo .tx_cobid , sdo .on_response )
73+ if self . network .is_async ():
74+ self . network .unsubscribe (0x700 + self .id , self .nmt .aon_heartbeat )
75+ self . network .unsubscribe (0x80 + self .id , self .emcy .aon_emcy )
7776 else :
78- network .unsubscribe (0x700 + self .id , self .nmt .on_heartbeat )
79- network .unsubscribe (0x80 + self .id , self .emcy .on_emcy )
80- network .unsubscribe (0 , self .nmt .on_command )
81- self .network = None
82- self .sdo .network = None
83- self .pdo .network = None
84- self .tpdo .network = None
85- self .rpdo .network = None
86- self .nmt .network = None
77+ self . network .unsubscribe (0x700 + self .id , self .nmt .on_heartbeat )
78+ self . network .unsubscribe (0x80 + self .id , self .emcy .on_emcy )
79+ self . network .unsubscribe (0 , self .nmt .on_command )
80+ self .network = canopen . network . _UNINITIALIZED_NETWORK
81+ self .sdo .network = canopen . network . _UNINITIALIZED_NETWORK
82+ self .pdo .network = canopen . network . _UNINITIALIZED_NETWORK
83+ self .tpdo .network = canopen . network . _UNINITIALIZED_NETWORK
84+ self .rpdo .network = canopen . network . _UNINITIALIZED_NETWORK
85+ self .nmt .network = canopen . network . _UNINITIALIZED_NETWORK
8786
8887 def add_sdo (self , rx_cobid , tx_cobid ):
8988 """Add an additional SDO channel.
@@ -100,7 +99,7 @@ def add_sdo(self, rx_cobid, tx_cobid):
10099 """
101100 client = SdoClient (rx_cobid , tx_cobid , self .object_dictionary )
102101 self .sdo_channels .append (client )
103- if self .network is not None :
102+ if self .has_network () :
104103 self .network .subscribe (client .tx_cobid , client .on_response )
105104 return client
106105
0 commit comments