Skip to content

Conversation

@lumagi
Copy link
Collaborator

@lumagi lumagi commented Dec 18, 2022

This pull request removes unused code in Bus.new that is responsible for creating BitTiming instances, but is incompatible with PEAK devices. See issue #1458 .

The BitTiming class is an attempt at unifying the various timing parameters of the individual interfaces. The idea is that instead of manually supplying multiple parameters that make up the timing definition of the interface, one can instead supply a single instance of the BitTiming class, which will also automatically calculate derivative values from its input.

At the moment, this class is only used by two interfaces: CANtact and CANanalystii. Both either accept a single bitrate or a BitTiming instance. The latter will overrule the former. For reference, a pull request that would implement BitTiming for PEAK devices has not been merged, see #625 .

The code that is removed with this commit is part of the generic Bus.new constructor. The removed code searches the set of kwargs parameters for timing-related values. If it finds at least one such value, it creates a BitTiming class instance and adds it to the list of parameters. However, it breaks compatibility with the PEAK interface, see issue #1458. Additionally, the code in question is generic and applies to all interfaces. Instantiating a class here is prone to issues since it must be generic enough to fit all use cases. A better approach would be to simply forward the parameters as was done previously and leave it up to the individual interfaces to handle things properly.

lumagi and others added 3 commits December 18, 2022 21:27
The BitTiming class is an attempt at unifying the various timing
parameters of the individual interfaces. The idea is that instead of
manually supplying multiple parameters that make up the timing
definition of the interface, one can instead supply a single instance of
the BitTiming class, which will also automatically calculate derivative
values from its input.

At the moment, this class is only used by two interfaces: CANtact and
CANanalystii. Both either accept a single bitrate or a BitTiming
instance. The latter will overrule the former.

The code that is removed with this commit is part of the generic
Bus.__new__ constructor. The removed code searches the set of kwargs
parameters for timing-related values. If it finds at least one such
value, it creates a BitTiming class instance and adds it to the list of
parameters. However, it breaks compatibility with the PEAK interface,
see issue hardbyte#1458. Additionally, the code in question is generic and
applies to all interfaces. Instantiating a class here is prone to issues
since it must be generic enough to fit all use cases. A better approach
would be to simply forward the parameters as was done previously and
leave it up to the individual interfaces to handle things properly.
):
if key in config:
timing_conf[key] = int(str(config[key]), base=0)
del config[key]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have you tried just removing this line with del instead of everything?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For my specific issue with the PCAN interface, it's actually line 252 that's causing the immediate problem (although the del would also be an issue further down the road). Since it detects that f_clock is present in kwargs, it automatically tries to create the timing_conf and simply assumes that the config must also contain a bitrate key in line 252. This is not always the case for PCAN.

There are multiple reasons for me suggesting the removal of this piece of code:

  • It causes issues with at least two interfaces
  • It doesn't look like the code is actively used by any interface or anyone has picked up on it since it was merged
  • The contract between Bus.__new__ and the interface implementations is very weak. It basically says: If you name your parameters in the correct way, we'll automagically create the BitTiming instance for you. But only for Classic CAN, not CAN-FD.
  • The author itself stated in his commit that it (obviously) doesn't support CAN-FD.

@zariiii9003 zariiii9003 merged commit 4136f37 into hardbyte:develop Dec 21, 2022
@lumagi lumagi deleted the fix_peak_can_fd_constructor branch December 21, 2022 18:20
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.

Opening a PCanBus in FD mode with Bus.__new__ breaks with python-can 4.0.0 / 4.1.0 bit timing is invalid in kvaser

2 participants