Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions canopen/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,11 @@ class NodeScanner:

SERVICES = (0x700, 0x580, 0x180, 0x280, 0x380, 0x480, 0x80)

def __init__(self, network: Optional[Network] = None):
self.network = network
def __init__(self, network: Optional[Network] = _UNINITIALIZED_NETWORK):
Comment thread
sveinse marked this conversation as resolved.
Outdated
# To preseve the old API where None is uninitialized network
Comment thread
acolomb marked this conversation as resolved.
Outdated
if network is None:
network = _UNINITIALIZED_NETWORK
self.network: Network = network
#: A :class:`list` of nodes discovered
self.nodes: List[int] = []

Expand All @@ -408,8 +411,6 @@ def reset(self):

def search(self, limit: int = 127) -> None:
"""Search for nodes by sending SDO requests to all node IDs."""
if self.network is None:
raise RuntimeError("A Network is required to do active scanning")
sdo_req = b"\x40\x00\x10\x00\x00\x00\x00\x00"
for node_id in range(1, limit + 1):
self.network.send_message(0x600 + node_id, sdo_req)
6 changes: 5 additions & 1 deletion canopen/objectdictionary/eds.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations
Comment thread
acolomb marked this conversation as resolved.
from typing import TYPE_CHECKING
Comment thread
acolomb marked this conversation as resolved.
Outdated
import copy
import logging
import re
Expand All @@ -7,6 +9,8 @@
from canopen.objectdictionary import ObjectDictionary, datatypes
from canopen.sdo import SdoClient

if TYPE_CHECKING:
import canopen.network
Comment thread
acolomb marked this conversation as resolved.

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -173,7 +177,7 @@ def import_eds(source, node_id):
return od


def import_from_node(node_id, network):
def import_from_node(node_id: int, network: canopen.network.Network):
""" Download the configuration from the remote node
:param int node_id: Identifier of the node
:param network: network object
Expand Down
6 changes: 5 additions & 1 deletion canopen/sync.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from typing import Optional
Comment thread
acolomb marked this conversation as resolved.
Outdated

if TYPE_CHECKING:
import canopen.network
Comment thread
acolomb marked this conversation as resolved.

class SyncProducer:
"""Transmits a SYNC message periodically."""

#: COB-ID of the SYNC message
cob_id = 0x80

def __init__(self, network):
def __init__(self, network: canopen.network.Network):
self.network = network
self.period: Optional[float] = None
self._task = None
Expand Down
6 changes: 5 additions & 1 deletion canopen/timestamp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from __future__ import annotations
from typing import TYPE_CHECKING
import struct
import time
from typing import Optional
Comment thread
acolomb marked this conversation as resolved.
Outdated

if TYPE_CHECKING:
import canopen.network
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import canopen.network
import canopen.network

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following code is not a class so it's strictly not needed to have two lines according to black. Is your preference to always have two spaces below imports?

(PS! Can I encourage you to write a coding guideline document? It certainly would lessen your need to review and comment on styling.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is your preference to always have two spaces below imports?

Yes.

Sorry I won't have much time to invest for documentation in the coming weeks I'm afraid. Hope it gets better soon.


# 1 Jan 1984
OFFSET = 441763200
Expand All @@ -17,7 +21,7 @@ class TimeProducer:
#: COB-ID of the SYNC message
cob_id = 0x100

def __init__(self, network):
def __init__(self, network: canopen.network.Network):
self.network = network

def transmit(self, timestamp: Optional[float] = None):
Expand Down
2 changes: 1 addition & 1 deletion test/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def test_scanner_reset(self):
self.assertListEqual(self.scanner.nodes, [])

def test_scanner_search_no_network(self):
with self.assertRaisesRegex(RuntimeError, "Network is required"):
with self.assertRaisesRegex(RuntimeError, "No actual Network object was assigned"):
self.scanner.search()

def test_scanner_search(self):
Expand Down