TwinCAT 3 G-Code: Configuring HMI Step-by-Step Mode

Stefan Weidner3 min read
BeckhoffHMI ProgrammingTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Define the Step-Mode Boundary

The available evidence confirms a Beckhoff controller programmed with TwinCAT 3 and an HMI requirement to run a G-code program one line at a time while displaying progress. It does not identify the G-code interpreter, motion library, PLC block, or interface that exposes the current interpreter line. Therefore, direct interpreter control or direct access to its source text cannot be assumed.

Use an application-managed step pointer only if the PLC can associate each pointer value with an executable G-code line or step. A UINT can hold that pointer. Define the indexing convention explicitly: if indexing begins at zero, the last valid index is one less than the line count; if indexing begins at one, the last valid index equals the line count.

Structure Auto and Manual Operation

HMI control Application action Required constraint
Auto Run the program using its normal execution mode. Disable manual pointer changes while automatic execution is active.
Manual Enable controlled step selection and execution. Keep the pointer within the valid program range.
Next Increment the UINT pointer and select the next step. Do not advance beyond the last valid step.
Previous Optionally decrement the pointer to select an earlier line. Changing the pointer does not reverse motion already executed.

Separate line selection from line execution. This prevents a pointer change from being interpreted automatically as permission to move. The implementation must also prevent one sustained HMI button press from causing uncontrolled repeated increments.

Display the Active G-Code Line

Two display strategies are supported by the proposed design. Map the current pointer to a STRING and show only the active G-code line, or display the complete G-code text and highlight the line selected by the pointer. The second option provides more context but requires the HMI to receive the program text and a current-line reference.

If the interpreter does not expose its current line, the highlighted line represents the PLC application's selected step, not verified interpreter execution. Label that distinction on the HMI so operators do not mistake a requested line for a completed line.

Implement and Verify the Sequence

  1. Determine whether the selected G-code interpreter exposes program text, current-line status, and a command for executing one line. If these interfaces are unavailable, use the PLC-managed pointer only for a program representation controlled by the application.
  2. Create the bounded UINT pointer and associate each valid value with the corresponding executable step and display STRING.
  3. Add mutually exclusive Auto and Manual selections. In Manual mode, provide a separate command to select or execute the next line; add Previous only if earlier-line selection is required.
  4. Verify the first and last pointer limits, Auto-to-Manual transitions, active-line display, and prevention of repeated advancement from a sustained HMI command.

Perform initial direction checks under the machine's established commissioning and motion-safety controls. The evidence does not define the motion hardware, interpreter behavior, or safety architecture, so those controls must be resolved in the actual machine design.

FAQ

Can TwinCAT 3 display the current G-code line on an HMI?

It can display a line supplied as a STRING, but the evidence does not establish that the unspecified interpreter exposes its current line. Confirm that interface before treating the display as interpreter status.

How do I create a G-code single-step mode in TwinCAT 3?

Use a bounded UINT as the current-step pointer, map it to the corresponding line, and provide separate Manual and Next controls. Keep selection separate from execution and block pointer values outside the program range.

Can a Previous button reverse a G-code move?

No. Decrementing the UINT selects an earlier line; it does not reverse motion that has already occurred. Any reverse operation requires separately defined and validated machine behavior.

Back to blog