Skip to content

Conversation

@krixkrix
Copy link

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.

krixkrix added 4 commits May 9, 2017 11:53
 * 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
Copy link

grodansparadis commented May 9, 2017 via email

Copy link
Collaborator

@christiansandbergchristiansandberg 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. 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))
Copy link
Collaborator

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)
Copy link
Collaborator

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)
Copy link
Collaborator

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
Copy link
Collaborator

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,
Copy link
Collaborator

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
Copy link
Collaborator

@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.

Copy link
Owner

@hardbytehardbyte left a 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.

@felixdivofelixdivo mentioned this pull request Feb 10, 2018
@felixdivo
Copy link
Collaborator

I rebased it, added the requested changes and created an new PR in #245.

Sign up for freeto 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.

5 participants

@krixkrix@grodansparadis@felixdivo@hardbyte@christiansandberg