Rust EtherCAT equivalent to ecrt_master_create_domain()
Whereas in C++ you would use
ethercat_create_domain.cpp
// Create domain
domain = ecrt_master_create_domain(master);
if (!domain) {
std::cerr << "Failed to create domain!" << std::endl;
return -1;
}the Rust equivalent using the ethercat crate would be:
ethercat_create_domain.rs
use ethercat::{Domain, Master};
let domain_idx = master.create_domain()?;Full example including master request and domain creation:
ethercat_master_and_domain.rs
use ethercat::{Master, MasterAccess};
// You may also use MasterAccess::ReadOnly if you don't need write access
// 0 is the index of the master to open (usually 0)
let mut master = Master::open(0, MasterAccess::ReadWrite)?;
// Reserve (aka "request") the master (for exclusive access, basically)
master.reserve()?;
// Create domain
let domain_idx = master.create_domain()?;If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow