Getting SocketCAN to output data

Hey - I am extremely new to Rust (even the so-called noobs look like geniuses to me...) and want to set myself a challenge of getting SocketCAN to output some CAN goodness onto my screen.

I've read through the Rust book and done the worked examples, but I've hit a brick wall when trying to interface with SocketCAN.

Having a look at the (limited) documentation socketcan - Rust, I think I'm after something along the lines of socketcan::dump::Reader ? (I don't actually know if that's right - feel free to put me on the right path) I'm also pretty lost when it comes to implementing it in VS Code and what 'uses' I need to include up the top... let alone what I need to write to get it to output something a vcan0 and/or physical CAN connection.

Any help would be VERY appreciated!! :smiley:



Have you gotten any progress on the socketcan stuff? I'm also struggeling to get it working.

This is as far as I've gotten without the compiler throwing a bunch of errors :slight_smile:

use socketcan;
fn main() {

It would probably help if someone would show the errors they are getting here.

Else, how can anyone know what is going on?

Meanwhile the SocketCAN repository has shown no signs of development for 4 years and the README says:

Maintenance status : This crate is in the process of entering renewed joint maintainership with @fpagliughi. Please stay patient for a while for this to get cleaned up. -- @mbr.

Perhaps try raising an issue on that repository to ask what your errors are about.

Unfortunately I cannot help you without any error message.

The issue with the code from @jbear above is not a socketcan issue, but a generic Rust issue instead; you're not doing anything with the result from open! Add an .unwrap() or .expect("failed to open CAN socket"). If you run it again and don't see a panic, opening worked.

can0 is possibly the wrong device name, on my devices, they're usually named socan0. On the other hand, it is possible to use VCAN for testing.

open returns a CANSocket, so be sure to bind it (let can = CANSocket::open(....).unwrap()), then you can just let frame = can.read_frame().expect("failed to read frame") and receive a CAN frame.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.