Skip to content
Contact Get Started

Macro Variables

The addresses a macro reads and writes. For the language they belong to, with arguments, arithmetic and branching, see Custom Macros.

A variable that has never been given a value is vacant, written #0. Test for it before trusting a number:

IF [#5083 EQ #0] GOTO 100 (tool 3 has never been measured)

Some variables can never be vacant: the clock, the machine signal bits and the R parameters always hold a value, so testing those against #0 is dead code.

RangeAreLive
#1#33local: arguments and scratchper call, cleared on return
#34#99reservedreads are vacant; a write is a block error
#100#499commonlost at power-down
#500#9999common, retainedkept when the machine is switched off

An argument the caller left out of a G65 reads vacant, so a macro can tell “not given” from “given as zero”.

VariablesHold
#5021#5026machine position: X, Y, Z, A, B, Cread-only
#5041#5046work position, in the active offsetread-only
#5061#5066where the probe last triggeredwritable
#50701 if the last G31 triggered, 0 if it ran to targetwritable
#5161#5166the position G28 returns towritable
#5181#5186the second reference position, for G30writable

The two read-only pairs are refused rather than ignored: a program that writes to one stops on that block. They read the position as the block executes, not as it is parsed.

Check #5070 before you read a trip position

Section titled “Check #5070 before you read a trip position”

A G31 that does not touch leaves #5061#5066 holding the previous trip. They are not cleared on a miss, deliberately. That means a macro that reads #5063 without testing #5070 first can measure yesterday’s touch and never know.

G31 Z-50. F100.
IF [#5070 EQ 0] GOTO 900 (never touched, do not use #5063)
#100 = #5063
VariablesHold
#5211#5216the G92 shift, as a report
#5221#5386the work offsets: G54 at #5221, and each further system twenty later, six axes each, up to G59.3 at #5381

Writing a work offset takes effect on the blocks that follow, the same as G10 L2. Writing #5211 changes the register only: the G92 shift the machine is actually using does not move with it.

There is no variable for “which offset is active”. Read the modal state from the program instead of looking for one.

#5081 onwards is the number the control cuts with: geometry plus wear:

VariablesHold
#5081#5180tool length in use, tool 1 first
#5500tool length geometry, as measured
#5600tool length wear
#5700tool radius geometry, radius and never diameter
#5800tool radius wear
#5900tool type, as a number

Every band is indexed the same way, tool 1 first, and all cover the same tools.

Writing #5081+i sets the geometry and leaves the wear alone, so a correction the setter made survives a macro that re-measures the tool. It does that by subtracting the current wear, so read and write in the same breath. A wear value that changes in between lands in the geometry.

#5081 is vacant while a tool has neither geometry nor wear. Writing a wear value on its own is enough to stop it being vacant, which is why a probing macro tests the length rather than the wear.

VariablesHold
#3000raise your own alarm: #3000 = 12 (TOOL TOO SHORT) stops the program with that messagewrite
#3002operating hours: the control adds to it, so a write is a resetboth
#3011date, as YYYYMMDDread-only
#3012time, as HHMMSSread-only
#3026the tool in the spindleread
#3901parts made, machine-wide, counted at M02 / M30both
#3902parts requiredboth
#9901tool changes since the machine was builtboth
#9902cutting hours since the machine was builtboth
#1000#1031machine signals from the PLC, one bit eachread-only
#1032the same 32 signals as one numberread-only

With #3902 set, cycle start is refused once #3901 reaches it. Clear #3901 or raise #3902 to carry on. See Production Counts and PLC Signals in Macros.

VariablesHold
#900#921the last probe cycle’s result: which cycle, its status, what it wrote, and #911 stamped with the run those values belong to
#800what a block search collected: the tool, speed and position to restart at, and the M codes to replay
#850#856the point a feed-held program will return to; #850 says whether there is one, and an axis the machine does not have is vacant

These are ordinary variables, so a macro can overwrite them. They are also retained, so a result survives a power cycle: compare #911 against #901 before believing a probe result, or you may read the run before last.

R0R99 are a second set, separate from #, written R1 = 25.4. An R that was never set reads 0, not vacant.