我想找...

搜尋

分享

目錄

EthercatDevice_DmpHID.mpgSetCallback()

[EthercatDevice_DmpHID_Generic]

描述

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).

衍生類別:

Class NameVendor IDProduct CodeUARTKeypadLCMMPG
EthercatDevice_QECR11HU1S0x00000bc30x0086d404OO
EthercatDevice_QECR11HU9S0x00000bc30x0086d402OOOO
EthercatDevice_QECR00HU9S0x00000bc30x0086d401OOOO

語法

int mpgSetCallback(void (*callback)(int));

參數

  • [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:
定義代碼描述
ECAT_MPG_AXIS_CHANGE1The status of the Axis knob has changed.
ECAT_MPG_RATIO_CHANGE2The status of the Ratio knob has changed.
ECAT_MPG_EMERGENCY_STOP_CHANGE3The status of the Emergency Stop switch has changed.
ECAT_MPG_ENABLE_SWITCH_CHANGE4The status of the Enable switch has changed.
ECAT_MPG_ENCODER_CHANGE5The logical counter of the Encoder has changed.

回傳值

Return an error code. If the returned value is zero, it indicates a successful execution of this function.

備註

This function must be called after a successful execution of EthercatMaster::begin(). This function is blocking and cannot be called within the Cyclic Callback.

範例

#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 類別 for more QEC HID slave instructions and API usage.

返回頂端