Skip to content

CANalyst-II interface#476

Merged
hardbyte merged 6 commits intohardbyte:developfrom
smeng9:develop
Dec 29, 2018
Merged

CANalyst-II interface#476
hardbyte merged 6 commits intohardbyte:developfrom
smeng9:develop

Conversation

@smeng9
Copy link

@smeng9 smeng9 commented Nov 30, 2018

Closes Issue #68

First I would like to thank @rapzak for providing the initial Python code on CANalyst-II hardware. I tried to follow his code and convert his code to python-can BusABC compatible interface. Till now I have come up with a minimal implementation that provides open/close/send/receive functionality.

I will try to write documentation about the CANalyst-II interface and come up with test cases in the following weeks.

I still need some help and hope someone will pickup in completing a more concrete implementation that can: 1. detect board info, 2. use the filter provided by CANalyst-II instead of python-can, 3. error handling.

@codecov
Copy link

codecov bot commented Dec 1, 2018

Codecov Report

Merging #476 into develop will decrease coverage by 0.37%.
The diff coverage is 37.68%.

@@             Coverage Diff             @@
##           develop     #476      +/-   ##
===========================================
- Coverage    63.66%   63.29%   -0.38%     
===========================================
  Files           56       57       +1     
  Lines         4715     4784      +69     
===========================================
+ Hits          3002     3028      +26     
- Misses        1713     1756      +43

@smeng9 smeng9 changed the title In Progress: CANalyst-II interface CANalyst-II interface Dec 18, 2018
@smeng9
Copy link
Author

smeng9 commented Dec 18, 2018

I added more settings for the canalystii interface, I also created documentation of this interface and the vendor of such device. It's ready to be merged with the master branch.

Copy link
Owner

@hardbyte hardbyte left a comment

Choose a reason for hiding this comment

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

Looks good for inclusion. Thanks for the contribution!

Timing0, Timing1 = (0x31, 0x1C)
elif baud == 5000:
Timing0, Timing1 = (0xBF, 0xFF)

Copy link
Owner

Choose a reason for hiding this comment

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

Raise an error if baud isn't supported


if baud == 1000000:
Timing0, Timing1 = (0x00, 0x14)
elif baud == 800000:
Copy link
Owner

Choose a reason for hiding this comment

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

This should be moved out of the init method. I'd have a timing dict which maps baud to each timing tuple.

Copy link
Author

Choose a reason for hiding this comment

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

Thank for your suggestion, this part is improved

:param channel: channel number
:param device: device number
:param baud: baud rate
:param Timing0: customize the timing register if baudrate is not specified
Copy link
Owner

Choose a reason for hiding this comment

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

Should these timing overrides default to None?

Copy link
Author

Choose a reason for hiding this comment

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

yes, good catch


timeout = -1 if timeout is None else int(timeout * 1000)

if CANalystII.VCI_Receive(VCI_USBCAN2, self.device, self.channels[0], byref(raw_message), 1, timeout) <= STATUS_ERR:
Copy link
Owner

Choose a reason for hiding this comment

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

Would be good to separate out the error responses and the timeout ones.

Copy link
Author

Choose a reason for hiding this comment

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

The VCI_Receive function will return the number of can frames read before a timeout. If it is not a positive number, it did not receive anything. I cannot differentiate error responses or timeout ones.

Copy link
Owner

Choose a reason for hiding this comment

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

Ok fair enough

@hardbyte
Copy link
Owner

If you would like to add yourself to the CONTRIBUTORS.txt and update the history.rst file then I think we're all good to merge.

Cheers!

@hardbyte hardbyte added this to the 3.1 Release milestone Dec 29, 2018
@hardbyte hardbyte merged commit 7d0783c into hardbyte:develop Dec 29, 2018
@atmlvs
Copy link
Contributor

atmlvs commented Feb 18, 2019

@smeng9 seems parameters in Bus init method were not same as documentation, i cannot find any clue for the value of channel parameter which was 'can0'/'vcan0' in doc. can pro can open device correctly.
"""
In [12]: bus = can.Bus(interface='canalystii', channel=0, baud=250000)
VCI_OpenDevice Error
VCI_InitCAN Error
"""

@smeng9
Copy link
Author

smeng9 commented Feb 20, 2019

Hi @atmlvs The channel for CANalyst-II is either 0(high speed) or 1(redundant). Because I don't know which operating system you are currently using, my initial guess from this error is you are using Linux and you have not given the program sudo permission, or you are not using a compatible device with the library.

@atmlvs
Copy link
Contributor

atmlvs commented Feb 21, 2019

Hi @smeng9 yes, I use channel 0 and finally opened the device. the latest device driver and 32/64 bits DLL version should be checked. thanks for the clarification.

@felixdivo felixdivo mentioned this pull request Feb 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants