hardbyte / hardbyte/python-can

Kvaser Shutdown Error With Multiple Tasks

未關閉
#899 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
backend:kvaser question
主要語言
Python
星號
1.6k
分支
697
PR 合併指標
30 天內沒有已合併 PR

描述

I observed (on python-can 3.3.3 / Python 3.7.0) that with multiple periodic tasks, when calling the shutdown() function for a kvaser interface, the following error message is shown, maybe :
```
RESTART: testfile.py
Message sent on Kvaser Memorator, S/N XXXX (#1)
>>> Function canWrite failed - Handle is invalid
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\site-packages\can\broadcastmanager.py", line 136, in _run
self.bus.send(self.message)
File "C:\Program Files\Python37\lib\site-packages\can\interfaces\kvaser\canlib.py", line 555, in send
flags)
File "C:\Program Files\Python37\lib\site-packages\can\interfaces\kvaser\canlib.py", line 99, in __check_status
raise CANLIBError(function, result, arguments)
can.interfaces.kvaser.canlib.CANLIBError: Function canWrite failed - Handle is invalid
```
Does anyone have any idea?

Code for issue reproduction:
(with only one task, there is no error message)
```
import can
import time

from can.bus import BusABC

def send_periodic(bus_a):

msg1 = can.Message(arbitration_id=0x444,
data=[0, 25, 0, 1, 3, 1, 4, 1],
is_extended_id=False)

msg2 = can.Message(arbitration_id=0x454,
data=[1, 26, 1, 2, 4, 2, 5, 2],
is_extended_id=False)

msg3 = can.Message(arbitration_id=0x464,
data=[2, 27, 2, 3, 5, 3, 6, 3],
is_extended_id=False)

try:
#task1 = bus_a.send_periodic(msg1, 0.3)
task2 = bus_a.send_periodic(msg2, 0.5)
task3 = bus_a.send_periodic(msg3, 1.0)
if not isinstance(task1, can.ModifiableCyclicTaskABC):
print("This interface doesn't seem to support modification")
task1.stop()
return
counter=0
while counter<10:
msg2.data[0] = msg2.data[0] + 1
task2.modify_data(msg2)
time.sleep(1)
counter+=1
print("Message sent on {}".format(bus.channel_info))
except can.CanError:
print("Message NOT sent")

if __name__ == '__main__':
counter=0
bus = can.interface.Bus(bustype='kvaser', channel=0, bitrate=250000)
send_periodic(bus)
time.sleep(10)
bus.stop_all_periodic_tasks()
bus.shutdown()
```

貢獻指南

開啟貢獻指南

研究方向

Start with can/broadcastmanager.py at _run and can/interfaces/kvaser/canlib.py at send and __check_status, then reproduce the supplied multiple-periodic-task shutdown sequence on Python 3.7 with Kvaser. Done means stopping all periodic tasks and shutting down no longer emits the shown invalid-handle traceback.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
embedded-iot, networking
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。