43 const std::string busname =
"slcan0";
47 const std::string baudrate =
"500K";
49 PRINT(
"This example runs a counter completely without SDO transfers.");
50 PRINT(
"There must be a CiA 401 device which is configured to send 'Read input 8-bit/Digital Inputs 1-8'");
51 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.");
54 if (!master.
start(busname, baudrate)) {
55 PRINT(
"Starting Master failed.");
59 std::this_thread::sleep_for(std::chrono::seconds(1));
62 ERROR(
"No devices found.");
74 PRINT(
"Found CiA 401 device with node ID "<<device.
get_node_id());
79 ERROR(
"This example is intended for use with a CiA 401 device but I can't find one.");
89 DUMP(device.
get_entry(
"Manufacturer device name"));
102 for (uint8_t i=0; i<10; ++i) {
104 PRINT(
"Set output to 0x"<<std::hex<<i<<
" (via cache!) and wait 1 second");
105 device.
set_entry(
"Write output 8-bit/Digital Outputs 1-8", i, kaco::WriteAccessMethod::cache);
106 std::this_thread::sleep_for(std::chrono::seconds(1));
108 DUMP_HEX(device.
get_entry(
"Write output 8-bit/Digital Outputs 1-8",kaco::ReadAccessMethod::cache));
109 DUMP_HEX(device.
get_entry(
"Read input 8-bit/Digital Inputs 1-8",kaco::ReadAccessMethod::cache));
110 DUMP_HEX(device.
get_entry(
"Read input 8-bit/Digital Inputs 9-16",kaco::ReadAccessMethod::cache));
void add_transmit_pdo_mapping(uint16_t cob_id, const std::vector< Mapping > &mappings, TransmissionType transmission_type=TransmissionType::ON_CHANGE, std::chrono::milliseconds repeat_time=std::chrono::milliseconds(0))
Adds a transmit PDO mapping. This means values from the dictionary cache are sent to the device...
Device & get_device(size_t index) const
Returns a reference to a slave device object.
const Value & get_entry(const std::string &entry_name, const ReadAccessMethod access_method=ReadAccessMethod::use_default)
Gets the value of a dictionary entry by name internally. If there is no cached value or the entry is ...
void start()
Starts the node via NMT protocol and loads mandatory entries, operations, and constants.
size_t num_devices() const
Returns the number of slave devices in the network.
void add_receive_pdo_mapping(uint16_t cob_id, const std::string &entry_name, uint8_t offset)
Adds a receive PDO mapping. This means values sent by the device via PDO are saved into the dictionar...
bool start(const std::string busname, const std::string &baudrate)
Starts master and creates Core.
uint16_t get_device_profile_number()
Returns the CiA profile number.
This class represents a master node. It listens for new slaves and provides access to them via get_sl...
uint8_t get_node_id() const
Returns the node ID of the device.
std::string load_dictionary_from_library()
Tries to load the most specific EDS file available in KaCanOpen's internal EDS library. This is either device specific, CiA profile specific, or mandatory CiA 301.
This class represents a CanOpen slave device in the network.
void set_entry(const std::string &entry_name, const Value &value, const WriteAccessMethod access_method=WriteAccessMethod::use_default)
Sets the value of a dictionary entry by name internally. If the entry is configured to send an SDO on...