Unhashable type for Systec interface errors
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- python
- Lĩnh vực
- embedded-iot
Hướng nghiên cứu
Bắt đầu với UcanError.init trong can/interfaces/systec/exceptions.py và lần theo kết quả được truyền bởi check_result trong can/interfaces/systec/ucan.py. Báo cáo xác định một mã lỗi ctypes.c_ubyte và một lần tra cứu cụ thể bị lỗi. Hãy xác minh rằng việc khởi tạo exception sẽ đưa ra lỗi CAN ban đầu thay vì phát sinh TypeError; script DroneCAN được cung cấp sẽ cung cấp một kiểm tra tích hợp khi có phần cứng Systec.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
When running DroneCAN on top of the systec interface, error messages that appear raise TypeError: unhashable type exceptions. This swallows the actual error messages and prevents troubleshooting.
The cause of error messages is likely a config/hardware issue, so it is probably irrelevant. What matters is that the CAN error messages disappear and are not relayed to the user.
To Reproduce
Below is a script to monitor messages coming through DroneCAN. Error messages do not always happen, but they tend to be triggered by sending commands through DroneCAN.
The actual mechanism triggering error messages is more likely a config/hardware issue than anything.
Expected behavior
The error message raised during operation should be exposed to the user.
Additional context
OS and version: Windows 11
Python version: 3.10
python-can version:
python-can interface/s (if applicable): systec
Traceback and logs
Traceback:
Traceback (most recent call last):
File "c:\Users\thoma\OneDrive\Documents\Tyto\Python scripts\test.py", line 51, in <module>
dc_node.spin(timeout=0.001)
File "C:\Python310\lib\site-packages\dronecan\node.py", line 439, in spin
execute_once()
File "C:\Python310\lib\site-packages\dronecan\node.py", line 431, in execute_once
frame = self._can_driver.receive(read_timeout)
File "C:\Python310\lib\site-packages\dronecan\driver\python_can.py", line 137, in receive
self._check_write_feedback()
File "C:\Python310\lib\site-packages\dronecan\driver\python_can.py", line 124, in _check_write_feedback
raise item
File "C:\Python310\lib\site-packages\dronecan\driver\python_can.py", line 101, in _writer_thread_loop
self._bus.send(msg)
File "C:\Python310\lib\site-packages\can\interfaces\systec\ucanbus.py", line 212, in send
self._ucan.write_can_msg(self.channel, [message])
File "C:\Python310\lib\site-packages\can\interfaces\systec\ucan.py", line 488, in write_can_msg
UcanWriteCanMsgEx(self._handle, channel, c_can_msg, c_count)
File "C:\Python310\lib\site-packages\can\interfaces\systec\ucan.py", line 109, in check_result
raise UcanError(result, func, arguments)
File "C:\Python310\lib\site-packages\can\interfaces\systec\exceptions.py", line 16, in __init__
message = self._error_message_mapping.get(result, "unknown")
TypeError: unhashable type
Script to recreate the bug:
import can
import dronecan
from dronecan.driver import python_can as pycan_driver
from dronecan.app.node_monitor import NodeMonitor
import time
can_bus = pycan_driver.PythonCAN(channel=0, interface="systec", bustype="systec", bitrate=1000000)
node_id = 45
dc_node = dronecan.node.Node(can_bus, node_id=node_id, bitrate=1000000)
print("=== Local Node ===")
print(f" node_id : {dc_node.node_id}")
print(f" mode : {dc_node.mode}")
print(f" health : {dc_node.health}")
print()
# Print every NodeStatus as it is received:
def on_node_status(event):
print(
f"[NodeStatus] from node {event.transfer.source_node_id}: "
f"uptime={event.message.uptime_sec}s "
f"health={event.message.health} "
f"mode={event.message.mode}"
)
dc_node.add_handler(dronecan.uavcan.protocol.NodeStatus, on_node_status)
LISTEN_SECONDS = 10
monitor = NodeMonitor(dc_node)
print(f"Listening for {LISTEN_SECONDS} seconds...\n")
deadline = time.monotonic() + LISTEN_SECONDS
while time.monotonic() < deadline:
try:
dc_node.spin(timeout=0.001)
msg = dronecan.uavcan.equipment.esc.RPMCommand()
msg.cmd = int(0)
dc_node.broadcast(msg)
except dronecan.transport.TransferError as ex:
print(f" (transfer error, continuing: {ex})")
dc_node.close()
With Claude, I tracked down the error to interfaces/systec/exceptions.py. A ctypes.c_ubyte error code is passed to the Python interface, and the systec backend fails to interpret it. By changing Line 16 in exceptions.py, I can see the underlying exception and original error message:
message = self._error_message_mapping.get(result, "unknown")
should become
message = self._error_message_mapping.get(result.value, "unknown")
This seems to have solved the issue, and now I can troubleshoot my hardware problems better. I cannot make a PR for this at the moment, but I might later.
- Ngôn ngữ chính
- Python
- Star
- 1.6k
- Fork
- 697
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của hardbyte/python-can
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
hardbyte/python-can#1922 · 1 reaction ·
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
hardbyte/python-can#2102 ·
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
hardbyte/python-can#2092 ·
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
hardbyte/python-can#2091 ·
-
`BitTiming.from_sample_point` rejects valid timing solutions due to hardcoded register limits Đang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
hardbyte/python-can#2083 ·
Tất cả issue của hardbyte/python-can
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100