- Notifications
You must be signed in to change notification settings - Fork 665
introducing canal interface#161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
* almost just a copy of the usb2can module which is badly named * the usb2can module is for now left unchanged but should be changed to use the new CANAL interface * TODO serial_selector update...
* autodetect device ID failed * CanalOpen failed
grodansparadis commented May 9, 2017 via email
Applause! :) …On 09/05/17 14:17, krixkrix wrote: I have added a CANAL interface for python-can. It is more or less a copy of the usb2can interface code, which wraps the canal API the same way. The usb2can interface should IMHO be called "canal" but I did not want to interfere with that interface, so I have created a new one. I also extended the canal wrapper a bit with some error checking. The canal interface has been tested with a Lawicel CANUSB adapter. http://www.vscp.org/docs/vscpd/doku.php?id=level1_driver_canusb This is my first pull request ever, so feel free to teach me how I should have done. ------------------------------------------------------------------------ You can view, comment on, or merge this pull request online at: #161 Commit Summary * Introduce CANAL interface * make the serial device autodetect work * Canal interface: Raise CanError on various errors: * Add an example file File Changes * *M* can/interface.py <https://github.com/hardbyte/python-can/pull/161/files#diff-0> (3) * *M* can/interfaces/__init__.py <https://github.com/hardbyte/python-can/pull/161/files#diff-1> (2) * *A* can/interfaces/canal/__init__.py <https://github.com/hardbyte/python-can/pull/161/files#diff-2> (2) * *A* can/interfaces/canal/canalInterface.py <https://github.com/hardbyte/python-can/pull/161/files#diff-3> (183) * *A* can/interfaces/canal/canal_wrapper.py <https://github.com/hardbyte/python-can/pull/161/files#diff-4> (151) * *A* can/interfaces/canal/serial_selector.py <https://github.com/hardbyte/python-can/pull/161/files#diff-5> (39) * *A* examples/canal_demo.py <https://github.com/hardbyte/python-can/pull/161/files#diff-6> (50) Patch Links: * https://github.com/hardbyte/python-can/pull/161.patch * https://github.com/hardbyte/python-can/pull/161.diff — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#161>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ABS8I-VT5CKuh-Qg_fm2IHKVspvUhnI5ks5r4FlsgaJpZM4NVOry>. -- Stay Hungry - Stay Foolish! Åke Hedman Brattbergavägen 17, 82050 LOS, SWEDEN http://www.vscp.orghttp://www.akehedman.se |
christiansandberg left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. But it's bad practice for libraries to hide serious errors, so I suggest to add some more exceptions and let the application catch them and decide what to do. Preferably create a new exception class inheriting from CanError which can present it with an error description based on the status code.
| if timeout: | ||
| self.can.blocking_send(self.handle, byref(tx), int(timeout * 1000)) | ||
| else: | ||
| self.can.send(self.handle, byref(tx)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check result and raise exception if error.
| # CANAL_ERROR_RCV_EMPTY or CANAL_ERROR_TIMEOUT | ||
| rx = None | ||
| else: | ||
| log.error('Canal Error %s', status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raise exception instead.
| def shutdown(self): | ||
| """Shut down the device safely""" | ||
| status = self.can.close(self.handle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check status and raise exception if error.
| for i in range(length): | ||
| messagetx.data[i] = msg.data[i] | ||
| messagetx.flags = 80000000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be 0x80000000.
| REMOTE_FRAME = bool(messagerx.flags & IS_REMOTE_FRAME) | ||
| ERROR_FRAME = bool(messagerx.flags & IS_ERROR_FRAME) | ||
| msgrx = Message(timestamp=messagerx.timestamp, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in seconds, so divide with 1000.0.
felixdivo commented Dec 17, 2017
@krixkrix Can you put in these few changes? I would do it, but I do not know how to branch off a PR and mere it into that one again. |
hardbyte left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to merge after the changes Christian pointed out have been made.
felixdivo commented Feb 10, 2018
I rebased it, added the requested changes and created an new PR in #245. |
I have added a CANAL interface for python-can.
It is more or less a copy of the usb2can interface code, which wraps the canal API the same way.
The usb2can interface should IMHO be called "canal" but I did not want to interfere with that interface, so I have created a new one.
I also extended the canal wrapper a bit with some error checking.
The canal interface has been tested with a Lawicel CANUSB adapter.
http://www.vscp.org/docs/vscpd/doku.php?id=level1_driver_canusb
This is my first pull request ever, so feel free to teach me how I should have done.