This example runs a counter completely without SDO transfers. There must be a CiA 401 device which is configured to send 'Read input 8-bit/Digital Inputs 1-8' and 'Read input 8-bit/Digital Inputs 9-16' via TPDO1 and to receive 'Write output 8-bit/Digital Outputs 1-8' via RPDO1.
#include <thread>
#include <chrono>
#include <cstdint>
#include "master.h"
#include "logger.h"
int main() {
const std::string busname = "slcan0";
const std::string baudrate = "500K";
PRINT("This example runs a counter completely without SDO transfers.");
PRINT("There must be a CiA 401 device which is configured to send 'Read input 8-bit/Digital Inputs 1-8'");
PRINT("and 'Read input 8-bit/Digital Inputs 9-16' via TPDO1 and to receive 'Write output 8-bit/Digital Outputs 1-8' via RPDO1.");
if (!master.
start(busname, baudrate)) {
PRINT("Starting Master failed.");
return EXIT_FAILURE;
}
std::this_thread::sleep_for(std::chrono::seconds(1));
ERROR("No devices found.");
return EXIT_FAILURE;
}
size_t index;
bool found = false;
index = i;
found = true;
PRINT(
"Found CiA 401 device with node ID "<<device.
get_node_id());
}
}
if (!found) {
ERROR("This example is intended for use with a CiA 401 device but I can't find one.");
return EXIT_FAILURE;
}
DUMP(device.
get_entry(
"Manufacturer device name"));
for (uint8_t i=0; i<10; ++i) {
PRINT("Set output to 0x"<<std::hex<<i<<" (via cache!) and wait 1 second");
device.
set_entry(
"Write output 8-bit/Digital Outputs 1-8", i, kaco::WriteAccessMethod::cache);
std::this_thread::sleep_for(std::chrono::seconds(1));
DUMP_HEX(device.
get_entry(
"Write output 8-bit/Digital Outputs 1-8",kaco::ReadAccessMethod::cache));
DUMP_HEX(device.
get_entry(
"Read input 8-bit/Digital Inputs 1-8",kaco::ReadAccessMethod::cache));
DUMP_HEX(device.
get_entry(
"Read input 8-bit/Digital Inputs 9-16",kaco::ReadAccessMethod::cache));
}
}