ethercat-rs / ethercat

Rust wrapper for the IgH EtherCAT master
Apache License 2.0
58 stars 18 forks source link

Info needed for rust novice. #41

Closed spiderdab closed 1 year ago

spiderdab commented 1 year ago

Hi, I'm a rust novice, but used ethercat c lib for the last 2 years. I wanted to try to go the rust way, that's why I'm trying this repo, but I can't go on with the examples, possibly for my limited knowledge on how to use rust libraries.

I succesfully built ethercat from Igh on a raspberry pi 400 with latest 64bit raspberry pi OS. Master runs ok and a slave is correctly found. Than, thanks to #40 , I could build ethercat-rs doing: export ETHERCAT_PATH=~/ethercat cargo build

I see that examples are not built, so I've tried: $ rustc examples/info.rs $ rustc examples/info.rs -L ./

also tried adding extern crate ethercat; to the beginning of info.rs, but in every case the result is that ethercat is missing.

What should I do to run an example? Would it be possible to write in the documentation a simple list of commands to run an example?

birkenfeld commented 1 year ago

To run an example, you use e.g. cargo run --example info.

By the way, the default build mode is unoptimized, so you might also want to try out release mode (cargo run --release ...) at some point.

I'll add something to the README.

spiderdab commented 1 year ago

Thanks, I can confirm it works with this result:

dab@raspberrypi:~/rust_ethercat/ethercat $ cargo run --example info
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
     Running `target/debug/examples/info`
EtherCAT Master: Ok(
    MasterInfo {
        slave_count: 1,
        link_up: true,
        scan_busy: false,
        app_time: 0,
    },
)

I have to say I missed (as a rust novice) that cargo has a special flag to run examples...

birkenfeld commented 1 year ago

No problem, there is a lot in there :)