Skip to content

Conversation

@ttcontrol-brunnthaler
Copy link

@ttcontrol-brunnthaler ttcontrol-brunnthaler commented Mar 25, 2019

…P, TSEG2, TSEG1 with the bitrate argument

Closes #538.

@ttcontrol-brunnthaler
Copy link
Author

#538

@codecov
Copy link

codecov bot commented Mar 25, 2019

Codecov Report

Merging #539 into develop will decrease coverage by 0.03%.
The diff coverage is 0%.

@@             Coverage Diff             @@
##           develop     #539      +/-   ##
===========================================
- Coverage       64%   63.96%   -0.04%     
===========================================
  Files           63       63              
  Lines         5700     5703       +3     
===========================================
  Hits          3648     3648              
- Misses        2052     2055       +3

@felixdivo
Copy link
Collaborator

felixdivo commented Apr 4, 2019

But thank you for the contribution! Where did you find the information about the custom bitrate? We might just link it in the parameter documentation of bitrate.

@ttcontrol-brunnthaler
Copy link
Author

Hello felixdivo,
Sorry for answering this late!
There is this website: http://www.bittiming.can-wiki.info/ where you can find under the BOSCH 16 bit Bit Timing Register BTR how the custom CAN is built and where the bits are mapped too.
If you download the https://www.peak-system.com/Software-APIs.305.0.html PCANView you can enter the speed you want and get the Bus Timing Register as parameter back
Best regards

@felixdivo
Copy link
Collaborator

Okay, nice to see that Wiki! It would probably be nice to link it somewhere.

@ttcontrol-brunnthaler
Copy link
Author

@felixdivo sorry I overwrote some of the changes you made because the main develop branch was extended to CAN-FD could you redo the merge you did before.
Best regards

@felixdivo
Copy link
Collaborator

No sorry, only you can commit to your own branch. I think you should undo the rebase and apply b96a54f on top of a rebase from the GUI in GitLab or a new clean rebase done from CLI. Something seemed to have gone wrong.

@felixdivo
Copy link
Collaborator

And also by now I forgot what I changed. ^^

Copy link
Contributor

@bhass1 bhass1 left a comment

Choose a reason for hiding this comment

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

The proposed change doesn't seem to actually work. TPCANHandle(bitrate) isn't the proper interface.

It should be TPCANBaudrate(BTR0BTR1), and BTR0BTR1 needs to be calculated with an external tool which makes the current usage difficult for an ordinary user passing in arguments from the command line (i.e. simple 500000 does not translate directly to the proper BTR0BTR1 value for 500KBaud).

if not user_bit:
pcan_bitrate = pcan_bitrate_objs.get(bitrate, PCAN_BAUD_500K)
else:
pcan_bitrate = TPCANHandle(bitrate)
Copy link
Contributor

Choose a reason for hiding this comment

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

It isn't clear how this actually works. Where are the SJW, BRP, TSEG1, and TSEG2 set? Does TPCANHandle(bitrate) handle arbitrary bitrates?

I don't see this interface in the Python PCANBasic API docs: https://www.peak-system.com/produktcd/Develop/PC%20interfaces/Windows/PCAN-Basic%20API/Include/PCANBasic.py

Choose a reason for hiding this comment

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

Its just a type definition:
TPCANHandle = c_ushort # Represents a PCAN hardware channel handle
But you are right I should use the :
TPCANBaudrate = c_ushort # Represents a PCAN Baud rate register value

"(i.e. simple 500000 does not translate directly to the proper BTR0BTR1 value for 500KBaud)"
In this case it does because we look the default values (most used) up in a dictionary
line 55: pcan_bitrate_objs
In the docstring I describe it quite well I think:
This argument can also be used for a user defined CAN-speed (e.g.: 0x0012 for 1.33 MHz)
For details on how to write a user speed register (SJW, TSEG 1/2, BRP) see:
http://www.bittiming.can-wiki.info (NXP SJA1000)
Please tell me what I could add for better understandability

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem I see is that bitrate is an integer representation of the bitrate (e.g. 500000). If user_bit is set, then line 97 becomes pcan_bitrate = TPCANHandle(500000) but in the dictionary, for 500K bitrate, pcan_bitrate = TPCANBaudrate(0x1C) #or TPCANBaudrate(28). They both can't be right.

The same issue comes up for the written example in the docstring. I'd expect bitrate to be 1330000 for 1.33M bitrate.

So the definition of what bitrate represents changes if user_bit = True or user_bit = False, and I don't think it's a good idea to do that.

Perhaps it would be better to define a new configuration type or calculate the register value of BTR0BTR1 within this method based on bitrate.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this solved? Once it is, I'd merge this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still discussing in Issue #538

@ttcontrol-brunnthaler
Copy link
Author

@felixdivo
On 4th of april: @felixdivo Merge branch 'develop' into develop d8f3495
Could you redo this merge please?

@felixdivo
Copy link
Collaborator

I don't know how to do this, maybe @hardbyte has other rights? But maybe it's not possible since you applied changes on top of it.

@hardbyte
Copy link
Owner

@bhass1 are you happy to sign off on this? I'd like to hold off merging until I see your approving review.

I'm going to start getting develop ready for the 3.2 release so will target this feature for the next release - either 3.3 or 4.0.

@hardbyte hardbyte modified the milestones: 3.2 Release, 4.0 Release May 12, 2019
@bhass1
Copy link
Contributor

bhass1 commented May 13, 2019

@bhass1 are you happy to sign off on this? I'd like to hold off merging until I see your approving review.

I don't like the user-interface - it muddles the meaning of bitrate. I am too busy now to commit the changes to add a separate configuration parameter, btr0btr1. When is 3.3 due out?

@felixdivo
Copy link
Collaborator

felixdivo commented May 19, 2019

The next release will now be 4.0. It will be some weeks until we release it, since there are quite a few major changes, like dropping support for all Python versions below 3.6 and reworking how exceptions are used. Take your time.

@marcel-kanter
Copy link
Contributor

+1 for the separation of bitrate and btr0 btr1.
These settings seem to be available for many can controllers.

@felixdivo
Copy link
Collaborator

See #615

@felixdivo
Copy link
Collaborator

#615 is now merged.

@karlding
Copy link
Collaborator

Closing since this is superseeded by #625. Please reopen if necessary.

@karlding karlding closed this Oct 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow user defined PCAN speeds

7 participants