Is there a code example for the Connect CAN expansion module.
The datasheet says "Accessible via SocketCAN of the Linux operating system" but under which device name?
Code Example for ConCAN?
Re: Code Example for ConCAN?
The device is available as can0. You can list the connection parameters with the same tools you would use for an ethernet adapter (eg. ip link show, ...)
Nicolai
Nicolai
Re: Code Example for ConCAN?
What are the LEDs on the front of the ConCAN module?
Is there a network status LED? As at the moment all I'm getting is network down errors.
If they are user LEDs, what names do we use to access them?
Is there a network status LED? As at the moment all I'm getting is network down errors.
If they are user LEDs, what names do we use to access them?
Re: Code Example for ConCAN?
The ConCan has just a power LED. The other LEDs are not populated (it's a standard enclosure for our extension modules thus all 6 leds are cut out).
How did you try to use the CAN interface?
Nicolai
How did you try to use the CAN interface?
Nicolai
Re: Code Example for ConCAN?
I am using these as example code:
https://github.com/craigpeacock/CAN-Examples
I am running my two RevPi's, one with the transmit code, one with the receive code, but both report network down.
When I add in can_get_state() from libsocketcan I get a state of CAN_STATE_STOPPED
https://github.com/craigpeacock/CAN-Examples
I am running my two RevPi's, one with the transmit code, one with the receive code, but both report network down.
When I add in can_get_state() from libsocketcan I get a state of CAN_STATE_STOPPED
Code: Select all
CAN Sockets Transmit Demo
Write: Network is down
bus state is STOPPED
Code: Select all
CAN Sockets Transmit Demo
Write: Network is down
bus state is STOPPED
Re: Code Example for ConCAN?
This code wont work. It uses hsrd coded vcan adapter and no physical interface.
From the guthub readme:
Hardcoded to use the vcan0 virtual CAN device.
From the guthub readme:
Hardcoded to use the vcan0 virtual CAN device.
Re: Code Example for ConCAN?
Of course I have modified it to connect to the "can0" you mentioned above, which is why I asked. (line 29 in receive and line 28 in transmit)
I have now managed to send and receive over CAN by using a combination of command line to set the CAN to UP and the C code above. Having proven the connection I can move on, but it would be nice if there was some documentation for this module beyond how to wire it up.
For anyone else finding this thread:
https://blog.mbedded.ninja/programming/ ... -in-linux/
When I get it all working in C I'll update here.
I have now managed to send and receive over CAN by using a combination of command line to set the CAN to UP and the C code above. Having proven the connection I can move on, but it would be nice if there was some documentation for this module beyond how to wire it up.
For anyone else finding this thread:
https://blog.mbedded.ninja/programming/ ... -in-linux/
When I get it all working in C I'll update here.
Re: Code Example for ConCAN?
All examples I can find online use libsocketcan to interact with the can0 device from within C.
By using the following commands I can get the can0 connection to be seen as "UP" and then the example C code works:
However, if I restart the Revpi and attempt to access the equivalent using libsocketcan with C:
then I get the following errors:
By using the following commands I can get the can0 connection to be seen as "UP" and then the example C code works:
Code: Select all
~$ sudo ip link set can0 type can bitrate 250000
~$ sudo ip link set up can0
Code: Select all
if (-1 == can_set_bitrate(def_CAN0, def_CAN_SPEED)) {
perror("can_set_bitrate");
}
if (-1 == can_do_start(def_CAN0)) {
perror("can_do_start");
}
if (-1 == can_get_state(def_CAN0, &state)) {
perror("can_get_state");
}
Code: Select all
CAN Sockets Receive Demo
RTNETLINK answers: Operation not permitted
can_set_bitrate: Operation not permitted
RTNETLINK answers: Operation not permitted
can_do_start: Operation not permitted
Re: Code Example for ConCAN?
The permission errors are probably due to missing privileges. Call the program with sudo.
Re: Code Example for ConCAN?
That explains it.. command line I'm using sudo, cross platform debugging using standard Pi login.
With root login for debugging, those commands now run without error. Still doesn't work yet, but getting closer.
With root login for debugging, those commands now run without error. Still doesn't work yet, but getting closer.