hardbyte / hardbyte/python-can

kvaser constructor should allow to set more flags

オープン
#1,587 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る
enhancement
主要言語
Python
スター
1.6k
フォーク
697
PR マージ指標
30日以内にマージされた PR はありません

説明

### Is your feature request related to a problem? Please describe.
I'd like to point out that the constructor of Kvaser Canlib has limited argument options available.

1. Unlike Vector's constructor, there doesn't appear to be a way to set tseg1, tseg2, and sjw of data bitrate.
2. Additionally, upon reviewing the code below, it seems that the flags parameter is restricted to only two options.

flags = 0
if accept_virtual:
flags |= canstat.canOPEN_ACCEPT_VIRTUAL
if fd:
flags |= canstat.canOPEN_CAN_FD

log.debug("Creating read handle to bus channel: %s", channel)
self._read_handle = canOpenChannel(channel, flags)

so, several flags of constants are unavailable.

canOPEN_ACCEPT_VIRTUAL = 0x0020
canOPEN_OVERRIDE_EXCLUSIVE = 0x0040
canOPEN_REQUIRE_INIT_ACCESS = 0x0080
canOPEN_NO_INIT_ACCESS = 0x0100
canOPEN_ACCEPT_LARGE_DLC = 0x0200
canOPEN_CAN_FD = 0x0400
canOPEN_CAN_FD_NONISO = 0x0800

### Describe the solution you'd like
I would suggest considering the following enhancements for the Kvaser constructor:

1. It may be beneficial to support additional FD parameters such as tseg1_dbr, tseg2_dbr, and sjw_dbr.
2. Adding support for more diverse flags in canOpenChannel's flags would be beneficial.

### Describe alternatives you've considered
In my opinion, the list provided above should suffice as an explanation. Currently, I am using a modified version of canlib.py from python-can 4.2.0, but I believe it would be beneficial to have native support for it.

Although I haven't put much thought into it, I would like to share a code snippet that could be helpful. Please kindly consider it as an example.

flags = kwargs.get("flags", 0)
if accept_virtual:
flags |= canstat.canOPEN_ACCEPT_VIRTUAL
if fd:
flags |= canstat.canOPEN_CAN_FD

tseg1_dbr = kwargs.get("tseg1_dbr", 0)
tseg2_dbr = kwargs.get("tseg2_dbr", 0)
sjw_dbr = kwargs.get("sjw_dbr", 0)

canSetBusParamsFd(self._read_handle, data_bitrate, tseg1_dbr, tseg2_dbr, sjw_dbr)

### Additional context

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。