Skip to content

Commit 9cd3d93

Browse files
committed
Synchronization with main, removing supersceded code
1 parent 4b45c19 commit 9cd3d93

File tree

5 files changed

+6
-28
lines changed

5 files changed

+6
-28
lines changed

canopen/emcy.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,10 @@ def __init__(self, cob_id: int):
9090
self.cob_id = cob_id
9191

9292
def send(self, code: int, register: int = 0, data: bytes = b""):
93-
if self.network is None:
94-
raise RuntimeError("A Network is required")
9593
payload = EMCY_STRUCT.pack(code, register, data)
9694
self.network.send_message(self.cob_id, payload)
9795

9896
def reset(self, register: int = 0, data: bytes = b""):
99-
if self.network is None:
100-
raise RuntimeError("A Network is required")
10197
payload = EMCY_STRUCT.pack(0, register, data)
10298
self.network.send_message(self.cob_id, payload)
10399

canopen/network.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import logging
44
import threading
55
from collections.abc import MutableMapping
6-
from typing import Callable, Dict, Final, Iterator, List, Optional, Union
7-
from typing import Callable, Dict, Iterator, List, Optional, Union, TYPE_CHECKING, TextIO
6+
from typing import Callable, Dict, Final, Iterator, List, Optional, Union, TYPE_CHECKING, TextIO
87

98
import can
109
from can import Listener
@@ -168,7 +167,7 @@ def add_node(
168167

169168
def create_node(
170169
self,
171-
node: int,
170+
node: Union[int, LocalNode],
172171
object_dictionary: Union[str, ObjectDictionary, TextIO, None] = None,
173172
) -> LocalNode:
174173
"""Create a local node in the network.
@@ -234,6 +233,8 @@ def send_periodic(
234233
:return:
235234
An task object with a ``.stop()`` method to stop the transmission
236235
"""
236+
if not self.bus:
237+
raise RuntimeError("Not connected to CAN bus")
237238
return PeriodicMessageTask(can_id, data, period, self.bus, remote)
238239

239240
def notify(self, can_id: int, data: bytearray, timestamp: float) -> None:
@@ -315,7 +316,7 @@ def __init__(
315316
can_id: int,
316317
data: CanData,
317318
period: float,
318-
bus,
319+
bus: can.BusABC,
319320
remote: bool = False,
320321
):
321322
"""
@@ -352,12 +353,10 @@ def update(self, data: bytes) -> None:
352353
old_data = self.msg.data
353354
self.msg.data = new_data
354355
if hasattr(self._task, "modify_data"):
355-
assert self._task is not None # This will never be None, but mypy needs this
356356
self._task.modify_data(self.msg)
357357
elif new_data != old_data:
358358
# Stop and start (will mess up period unfortunately)
359-
if self._task is not None:
360-
self._task.stop()
359+
self._task.stop()
361360
self._start()
362361

363362

canopen/nmt.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ def send_command(self, code: int):
145145
super(NmtMaster, self).send_command(code)
146146
logger.info(
147147
"Sending NMT command 0x%X to node %d", code, self.id)
148-
if self.network is None:
149-
raise RuntimeError("A Network is required")
150148
self.network.send_message(0, [code, self.id])
151149

152150
def wait_for_heartbeat(self, timeout: float = 10):
@@ -189,8 +187,6 @@ def start_node_guarding(self, period: float):
189187
Period (in seconds) at which the node guarding should be advertised to the slave node.
190188
"""
191189
if self._node_guarding_producer : self.stop_node_guarding()
192-
if self.network is None:
193-
raise RuntimeError("A Network is required")
194190
self._node_guarding_producer = self.network.send_periodic(0x700 + self.id, [], period, True)
195191

196192
def stop_node_guarding(self):
@@ -226,8 +222,6 @@ def send_command(self, code: int) -> None:
226222

227223
if self._state == 0:
228224
logger.info("Sending boot-up message")
229-
if self.network is None:
230-
raise RuntimeError("A Network is required")
231225
self.network.send_message(0x700 + self.id, [0])
232226

233227
# The heartbeat service should start on the transition
@@ -258,8 +252,6 @@ def start_heartbeat(self, heartbeat_time_ms: int):
258252
self.stop_heartbeat()
259253
if heartbeat_time_ms > 0:
260254
logger.info("Start the heartbeat timer, interval is %d ms", self._heartbeat_time_ms)
261-
if self.network is None:
262-
raise RuntimeError("A network is required")
263255
self._send_task = self.network.send_periodic(
264256
0x700 + self.id, [self._state], heartbeat_time_ms / 1000.0)
265257

canopen/pdo/base.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,6 @@ def subscribe(self) -> None:
466466
known to match what's stored on the node.
467467
"""
468468
if self.enabled:
469-
if self.pdo_node.network is None:
470-
raise RuntimeError("A Network is required")
471469
if self.cob_id is None:
472470
raise RuntimeError("A valid COB-ID is required")
473471
logger.info("Subscribing to enabled PDO 0x%X on the network", self.cob_id)
@@ -517,8 +515,6 @@ def add_variable(
517515

518516
def transmit(self) -> None:
519517
"""Transmit the message once."""
520-
if self.pdo_node.network is None:
521-
raise RuntimeError("A Network is required")
522518
if self.cob_id is None:
523519
raise RuntimeError("A valid COB-ID is required")
524520
self.pdo_node.network.send_message(self.cob_id, self.data)
@@ -531,8 +527,6 @@ def start(self, period: Optional[float] = None) -> None:
531527
on the object before.
532528
:raises ValueError: When neither the argument nor the :attr:`period` is given.
533529
"""
534-
if self.pdo_node.network is None:
535-
raise RuntimeError("A Network is required")
536530
if self.cob_id is None:
537531
raise RuntimeError("A valid COB-ID is required")
538532

@@ -566,8 +560,6 @@ def remote_request(self) -> None:
566560
Silently ignore if not allowed.
567561
"""
568562
if self.enabled and self.rtr_allowed:
569-
if self.pdo_node.network is None:
570-
raise RuntimeError("A Network is required")
571563
if self.cob_id is None:
572564
raise RuntimeError("A valid COB-ID is required")
573565
self.pdo_node.network.send_message(self.cob_id, bytes(), remote=True)

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,3 @@ ignore_missing_imports = "True"
5656
disable_error_code = [
5757
"annotation-unchecked",
5858
]
59-

0 commit comments

Comments
 (0)