Skip to content

Add CAN discovery, probing and node ID APIs#143

Merged
beniroquai merged 1 commit into
masterfrom
mergemaster
Jun 23, 2026
Merged

Add CAN discovery, probing and node ID APIs#143
beniroquai merged 1 commit into
masterfrom
mergemaster

Conversation

@beniroquai

Copy link
Copy Markdown
Contributor

Extend CAN.scan to support SDO probing of an ID range (probe_range, id_from, id_to) and include SDO-reported build/fwVersion/mac for reachable nodes. Add payload support for probeRange/from/to. Introduce discover() as a convenience wrapper around scan(..., probe_range=True). Add helpers: get_device_build_info() to extract per-node build info from the latest scanResults, set_remote_node_id() to reassign a node's CAN id (by current id or by MAC) with optional safety checks and blocking behavior, and assign_node_id_by_mac() as a convenience call for MAC-keyed provisioning. Docstrings updated to describe return shapes and behavior (persisted ID, CANopen reset, etc.).

Extend CAN.scan to support SDO probing of an ID range (probe_range, id_from, id_to) and include SDO-reported build/fwVersion/mac for reachable nodes. Add payload support for probeRange/from/to. Introduce discover() as a convenience wrapper around scan(..., probe_range=True). Add helpers: get_device_build_info() to extract per-node build info from the latest scanResults, set_remote_node_id() to reassign a node's CAN id (by current id or by MAC) with optional safety checks and blocking behavior, and assign_node_id_by_mac() as a convenience call for MAC-keyed provisioning. Docstrings updated to describe return shapes and behavior (persisted ID, CANopen reset, etc.).
Copilot AI review requested due to automatic review settings June 23, 2026 13:36
@beniroquai beniroquai merged commit 0a9b35e into master Jun 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Extends the uc2rest Python CAN client API to support discovery/probing of node-ID ranges via SDO and adds convenience helpers for extracting probed build info and remotely reassigning node IDs (including MAC-keyed provisioning).

Changes:

  • Extend CAN.scan() with optional SDO probing (probe_range, id_from, id_to) and send corresponding payload fields (probeRange, from, to).
  • Add CAN.discover() as a convenience wrapper around scan(..., probe_range=True, ...).
  • Add helper APIs: get_device_build_info(), set_remote_node_id(), and assign_node_id_by_mac().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread uc2rest/can.py
Comment on lines +138 to +141
if probe_range:
payload["probeRange"] = True
payload["from"] = int(id_from)
payload["to"] = int(id_to)
Comment thread uc2rest/can.py
Comment on lines +243 to +256
if by_mac is None and target is None:
raise ValueError("set_remote_node_id requires either target or by_mac")
path = "/can_act"
payload = {
"task": path,
"setRemoteNodeId": int(new_id),
"qid": qid,
}
if by_mac is not None:
payload["byMac"] = str(by_mac)
else:
payload["target"] = int(target)
if expect_mac is not None:
payload["expectMac"] = str(expect_mac)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants