I want to find...

Search

Shares

Table of Content

EthercatMaster.attachEventCallback()

[Ethercat Master]

Description

Register Event Callback Function.

Syntax

void attachEventCallback(void (*callback)(uint32_t));

Parameters

  • [in] void (*callback)(uint32_t)
    The event callback function to be registered, which only has one parameter, a 32-bit event code.

Return Value

None.

Comment

This function must be called before EthercatMaster::begin() or after EthercatMaster::end().

Example

#include "Ethercat.h"

EthercatMaster master;
EthercatDevice_Generic slave;

uint32_t EventCode = 0;

void EventCallback(uint32_t eventcode) {
  EventCode = eventcode;
}

void setup() {
  Serial.begin(115200);

  master.attachEventCallback(EventCallback); // EventCallback Function.

  master.begin();
  slave.attach(0, master);
  master.start(1000000, ECAT_SYNC);  // 1000000 ns = 1 ms
}

void loop() {
  /* Event Code */
  uint32_t event = EventCode;
  EventCode = 0;
  if (event) {
    Serial.print("EventCode:");
    Serial.println(event);
  }
}

Please see the EtherCAT Library User Manual for more QEC EtherCAT instructions and API usage.

Leave a Comment

Scroll to Top