[EthercatDevice_DmpHID_Generic]
Description
Register the MPG event callback function for the EtherCAT slave device. Since this callback function is called within update()
, it is prohibited to call blocking functions and system call-related functions within this callback function if update()
is called in an interrupt callback function (such as Cyclic Callback, Error Callback, or Event Callback).
Derived Class:
Class Name | Vendor ID | Product Code | UART | Keypad | LCM | MPG |
EthercatDevice_QECR11HU1S | 0x00000bc3 | 0x0086d404 | O | O | ||
EthercatDevice_QECR11HU9S | 0x00000bc3 | 0x0086d402 | O | O | O | O |
EthercatDevice_QECR00HU9S | 0x00000bc3 | 0x0086d401 | O | O | O | O |
Syntax
int mpgSetCallback(void (*callback)(int));
Parameters
[in] void (*callback)(int)
The MPG event callback function to be registered has an integer-type parameter that indicates the event type. The supported MPG event types are as follows:
Definition | Code | Description |
ECAT_MPG_AXIS_CHANGE | 1 | The status of the Axis knob has changed. |
ECAT_MPG_RATIO_CHANGE | 2 | The status of the Ratio knob has changed. |
ECAT_MPG_EMERGENCY_STOP_CHANGE | 3 | The status of the Emergency Stop switch has changed. |
ECAT_MPG_ENABLE_SWITCH_CHANGE | 4 | The status of the Enable switch has changed. |
ECAT_MPG_ENCODER_CHANGE | 5 | The logical counter of the Encoder has changed. |
Return Value
Return an error code. If the returned value is zero, it indicates a successful execution of this function.
Comment
This function must be called after a successful execution of EthercatMaster::begin()
. This function is blocking and cannot be called within the Cyclic Callback.
Example
#include "Ethercat.h" EthercatMaster master; EthercatDevice_QECR11HU9S slave; void MpgCallback(int event) { switch (event) { case ECAT_MPG_AXIS_CHANGE: Serial.print("MPG Axis changed. "); Serial.println(slave.mpgReadAxis()); break; case ECAT_MPG_RATIO_CHANGE: Serial.print("MPG Ratio changed. "); Serial.println(slave.mpgReadRatio()); break; case ECAT_MPG_EMERGENCY_STOP_CHANGE: Serial.print("MPG Emergency Stop changed "); Serial.println(slave.mpgReadEmergencyStop()); break; case ECAT_MPG_ENABLE_SWITCH_CHANGE: Serial.print("MPG Enable Switch changed. "); Serial.println(slave.mpgReadEnableSwitch()); break; case ECAT_MPG_ENCODER_CHANGE: Serial.print("MPG Encoder changed. "); Serial.println(slave.mpgReadEncoder()); break; } } void setup() { Serial.begin(115200); master.begin(); slave.attach(0, master); slave.mpgSetCallback(MpgCallback); master.start(); } void loop() { slave.update(); // ... }
Please see EthercatDevice_DmpHID_Generic Class for more QEC HID slave instructions and API usage.