example_slave.cpp
Go to the documentation of this file.
3 
4 // This shows a minimal example on how to use the soem_interface library.
5 // Keep in mind that this is non-working example code, with only minimal error handling
6 
7 int main(int argc, char** argv)
8 {
9  const std::string bus_name = "eth1";
10  const std::string slave_name = "ExampleSlave";
11  const uint32_t slave_address = 0;
12 
13  std::unique_ptr<rokubimini::soem_interface::EthercatBusBase> bus =
14  std::make_unique<rokubimini::soem_interface::EthercatBusBase>(bus_name);
15 
16  std::shared_ptr<soem_interface_examples::ExampleSlave> slave =
17  std::make_shared<soem_interface_examples::ExampleSlave>(slave_name, bus.get(), slave_address);
18 
19  bus->addSlave(slave);
20  bus->startup();
21  bus->setState(EC_STATE_OPERATIONAL);
22 
23  if (!bus->waitForState(EC_STATE_OPERATIONAL, slave_address))
24  {
25  // Something is wrong
26  return 1;
27  }
28 
29  while (true)
30  {
31  bus->updateRead();
32  bus->updateWrite();
33  }
34 
35  bus->shutdown();
36  return 0;
37 }
EC_STATE_OPERATIONAL
unsigned int uint32_t
int slave
int main(int argc, char **argv)


rokubimini_ethercat
Author(s):
autogenerated on Wed Mar 3 2021 03:09:16