I want to find...

Search

Shares

Table of Content

EthercatDevice_DmpStepper.machineGcode()

[EthercatDevice_DmpStepper_Generic]

Description

Send a G-code command to the EtherCAT slave device.

Since this function is a non-blocking function and the update() function needs to be called continuously to execute the state machine, it may take some time to complete, so the related status may take some time to respond, such as machineIsMoving().

Derived Class:

Class NameVendor IDProduct Code
EthercatDevice_QECR11MP3S0x00000bc30x0086d0d6
EthercatDevice_QECR00MP3S0x00000bc30x0086d0d9

Syntax

int machineGcode(const char *fmt, ...);

Parameters

  • [in] const char *fmt
    The string of the G-code command to be transmitted to the EtherCAT slave device. This is a pointer to a null-terminated string containing the format specification for the output. The format string follows the same format as the printf function in C, allowing for insertion of variables and formatting options.
  • [in] ...
    This is a variable number of arguments that will be inserted into the formatted string according to the format specifiers in the fmt string.

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::start() and before EthercatMaster::stop(). This function is blocking and cannot be called within the callback functions.

This function only works in G-code Controller mode on the EtherCAT slave device. For more details, please refer to configDeviceMode().

This function does not work in the following cases:

  • The machine is emergency stopped.
  • The machine is servo-off.
  • The machine is homing.

Example

#include "Ethercat.h"

EthercatMaster master;
EthercatDevice_QECR11MP3S slave;

void CyclicCallback() {
  slave.update();
}

void setup() {
  master.begin();
  slave.attach(0, master);
  master.attachCyclicCallback(CyclicCallback);
  master.start();

  slave.machineServoOn();
  while (slave.machineIsServoOn() == 0);

  while (1) {
    slave.machineGcode("G1 X100 Y50 Z25");
    delay(1000);
    slave.machineGcode("G1 X0 Y0 Z0");
    delay(1000);
    // ...
  }

  slave.machineServoOff();
  while (slave.machineIsServoOn() == 1);
}

void loop() {
  // ...
}

Please see EthercatDevice_DmpStepper_Generic Class for more QEC Stepper Drivers instructions and API usage.

Scroll to Top