All writing
Software & Data2 min read

Reading FANUC macro variables from a PC

Your control is quietly storing probing results, part counts, and tool data in macro variables. Read them from a PC and that data stops living on the machine and starts feeding your SPC, your dashboards, and your database.

A CNC control panel with an MDI keypad and axis handwheels

Photo: Carlos Vieira · CC BY-SA 2.0

Macro variables are the CNC's working memory. Probing cycles write measured values into them. Custom cycles use them for part families. The control keeps part counts and tool data in them. If you can read those variables from a PC — and with FOCAS you can — then every measurement your machine takes can flow straight into a database, an SPC chart, or a report, without anyone writing it on a clipboard.

A 60-second refresher on macro variables

  • #1–#33 — local. Arguments passed into a macro call; scoped to that call.
  • #100–#199 — common, volatile. Shared across programs, but cleared at power-off.
  • #500–#999 — common, retained. Shared and they survive a power cycle — this is where the values worth logging usually live.
  • #1000 and up — system. Read-only windows into the machine: positions, part counts (#3901/#3902), modal state, and more.

Reading them from a PC with FOCAS

The call is cnc_rdmacro: give it the handle, the variable number, and a buffer, and it returns the value. Reading the retained block #500–#520 looks like this:

# handle comes from cnc_allclibhndl3 (see the FOCAS post)
macro = MacroData()          # ODBM struct from fwlib.h

for number in range(500, 521):
    ret = fwlib.cnc_rdmacro(handle, number, 10, ctypes.byref(macro))
    if ret != 0:
        continue
    # FOCAS returns the value as an integer + a decimal-place count
    value = macro.mcr_val / (10 ** macro.dec_val)
    print(f'#{number} = {value}')

The decimal-place gotcha

FOCAS doesn't hand you a float. It gives you an integer mcr_val and a separate dec_val telling you how many decimal places it has. So 12345 with dec_val = 3 means 12.345. Miss this and every value you log is off by a factor of ten or a thousand — divide by 10 ** dec_val and you're right.

What this unlocks

  • Automatic SPC — probing cycles write to macros; read them on a timer and you have measurements flowing into control charts with zero manual entry.
  • Live part counts — pull #3901/#3902 to track production without an operator logging it.
  • Tool-life sync — read tool data off the control and reconcile it against your tool room instead of trusting a whiteboard.
  • Closed-loop corrections — read a measured offset, decide, and (carefully) write a correction back with cnc_wrmacro.
The machine is already measuring. Reading its macro variables is the difference between that measurement dying on the control and living in your quality system.

If you're probing parts and still typing the results into a spreadsheet, this is the gap to close — the data is right there in #500-something, waiting. Related reading: FOCAS + Python from scratch and why measurement uncertainty still matters.

Muerus Rodrigues

Applications Engineer

Get in touch

Keep reading

Home
Blog
Email
LinkedIn
Résumé