Code Library
CNC ProgrammingG-code (Macro B)FANUC control (or builder supporting Macro B) · DPRNT outputMIT licenseIntermediate

Log probe results out the serial port with Macro B (DPRNT)

A probe cycle measures a feature and quietly stores the result in a macro variable — useless until something gets it off the control. This macro runs immediately after a probe cycle, checks that it actually populated its variables, and streams the measured X, Y, size, and work offset out the serial port as readable text via DPRNT, formatted to line up in columns instead of a wall of raw numbers.

Before you run it

  • A probe cycle (Renishaw or your control's own) that populates macro variables #100-#103 before this runs — this macro logs, it doesn't probe
  • FANUC control (or Haas/other builder) with custom macro B and DPRNT enabled, wired to a serial port or DNC output

The code

GitHub
O2001 (PROBE RESULT LOGGER - DPRNT OUTPUT)
(RUN AFTER A RENISHAW/RENAMED PROBE CYCLE HAS SET #100-#103.)
(#100=MEASURED X  #101=MEASURED Y  #102=MEASURED SIZE  #103=WORK OFFSET NO.)

IF[#100 EQ #0]GOTO900
IF[#101 EQ #0]GOTO900
IF[#102 EQ #0]GOTO900

DPRNT[PROBE*RESULT*-*OFFSET*#103[20]]
DPRNT[X*=*#100[53]]
DPRNT[Y*=*#101[53]]
DPRNT[SIZE*=*#102[53]]
M30

N900
#3000=1(PROBE LOGGER: RUN A PROBE CYCLE FIRST - #100-#102 EMPTY)

What you get

What you get (DPRNT output)

PROBE RESULT - OFFSET 1
X = 12.487
Y = -3.219
SIZE = 24.991

How it works

  • Three IF[#10x EQ #0]GOTO900 checks guard against the most common mistake: running the logger before a probe cycle has actually populated its variables. An empty macro variable reads as #0 (undefined) in Macro B, not zero — that's the exact condition being checked.L5–7
  • DPRNT[...] is FANUC's built-in text-out-the-serial-port statement — no G-code motion involved, which is why this macro can run standalone right after any probe cycle.L9–12
  • #100[53] is a field-width/decimal-place format specifier — 5 total characters, 3 after the decimal — so measurements line up in a column instead of drifting with each value's length.L10
  • M30 ends the program on the success path; the #3000 alarm block below it is dead code unless the earlier GOTO900 actually fires — the same fail-loud pattern as the bolt-circle macro.L13–16

Gotchas & honest limits

  • DPRNT formatting is control-specific — the * characters here are a common convention for literal spaces some controls need in DPRNT text, and [53]-style suffixes set field width/decimals; check your control's macro manual before trusting the exact spacing.
  • This macro logs, it doesn't probe — run it immediately after whatever probe cycle populates #100-#103 on your control (Renishaw's or your builder's own). Adapt the variable numbers to match your actual cycle's outputs.
  • Output goes out the same port used for DNC transfers. A simple terminal program, or a small pyserial listener as the natural companion to the DNC sender sample, can capture it — this macro only covers the machine side.
  • #3000=1(...) catches the case where nothing set #100-#102 before this ran — it's insurance against logging garbage, not validation of the probe result itself.

Goes deeper

Want this adapted to your shop — or built into a real tool?

Samples are the free 80%. The last 20% is the part I do for a living.

Get in touch
Home
Blog
Tools
Code
Email
LinkedIn
Résumé