Heidenhain TNC 320: Tables & System Data

On a TNC everything that matters at run time lives in a table: tools, pockets, presets, datums, probe data, compensations. The control gives an NC program four doors into that data — FN 26/27/28 for your own .TAB files, TABDATA for the active tool/compensation/preset tables, SQL for everything at full speed, and FN 18: SYSREAD for live system data via ID/NR/IDX numbers. FN 16: F-PRINT then gets results out as a formatted log. This page maps all of it for the TNC 320.

The Table Landscape

Standard tables live in TNC:\table\. Table and column names must start with a letter and must not contain arithmetic operators like + — SQL chokes on them. All tables can be viewed as list or form (Screen Layout key), and the code number 555343 unlocks the EDIT FORMAT structure editor.

TableFileKey columns / notes
Tools
Tool tableTOOL.TUp to 32,767 tools. Geometry: L, R, R2, deltas DL/DR/DR2; life: TIME1, TIME2, CUR_TIME, OVRTIME, lock TL, replacement RT; cycles read LCUTS, LU, RN, ANGLE, RCUTS, T-ANGLE, PITCH, NMAX, LIFTOFF; TT measurement: CUT, LTOL, RTOL, R2TOL, LBREAK, RBREAK, DIRECT, R-OFFS, L-OFFS; probe link TP_NO. Indexed tools: T 5.15.9 rows for step tools. Never delete row 0 — it destroys the table structure.
Pocket tableTOOL_P.TCHMagazine map for the tool changer: P pocket, T tool, RSV reserved, ST special tool, F fixed pocket, L locked, LOCKED_ABOVE/BELOW/LEFT/RIGHT for box magazines. OEM can rename/re-path it.
Touch probe tabletchprobe.tpNO (linked from TP_NO in TOOL.T), TYPE, calibration offsets CAL_OF1/CAL_OF2, CAL_ANG, feed rates F/FMAX/F_PREPOS, DIST, SET_UP, TRACK, REACTION, STYLUS (SIMPLE / L-TYPE)
Reference points
Preset tablePRESET.PRBASE TRANSFORM. view: X, Y, Z, SPA, SPB, SPC (basic rotation in SPC for tool axis Z); OFFSET view for axis offsets; LOCKED write-protection; ACTNO. Row 0 always holds the last manually set preset (PR MAN(0)). Activate via Cycle 247 or PRESET SELECT; new rows only at the end.
Datum tables*.DD number, X/Y/Z (shifts in W-CS), A/B/C/U/V/W (shifts in M-CS), DOC. Values are always relative to the current preset. Activate with SEL TABLE before Cycle 7 / TRANS DATUM.
Compensation & user data
Compensation tables*.tco / *.wco.tco compensates in the tool coordinate system (alternative to DL/DR/DR2 in TOOL CALL — and it overrides them); .wco shifts in the working-plane system. Select with SEL CORR-TABLE TCS|WCS, activate a row with FUNCTION CORRDATA; editable during program run.
Freely definable tables*.TABYour own columns via the structure editor: types TEXT, DEC, INT, LENGTH, FEED, FLOAT, BOOL, TSTAMP, PATHNAME… Save your own templates in TNC:\system\proto. Text-type columns can only be read/written through QS parameters.
Point tables*.PNTIrregular position patterns; FADE column hides points. Select with SEL PATTERN, machine with CYCL CALL PAT.

FN 26/27/28 — Your Own Tables

The classic trio for .TAB files. Only one table can be open at a time; a new FN 26 closes the previous one. Within one block you can address several columns but only one row; multi-column transfers use consecutive variables of the same type.

FunctionSyntaxNotes
FN 26: TABOPENFN 26: TABOPEN TNC:\DIR1\TAB1.TABPath fixed or from a variable; quote paths containing special characters
FN 27: TABWRITEFN 27: TABWRITE 5/"RADIUS,DEPTH,D" = Q5Writes Q5, Q6, Q7 into row 5, columns RADIUS/DEPTH/D. Locked or missing cells → error. A fixed value writes the same value to every listed column.
FN 28: TABREADFN 28: TABREAD Q10 = 6/"X,Y,D"Reads row 6 into Q10, Q11, Q12; text columns need QS: FN 28: TABREAD QS1 = 6/"DOC"

TABDATA — the Active Tables Without SQL

The TABDATA functions (SPEC FCT → PROGRAM FUNCTIONS) address the currently active tables by column name and row key: tool table *.t (read-only), compensation tables *.tco/*.wco and preset table *.pr (read + write). Two properties make them the friendly option: values are automatically converted between mm and inch to match your NC program (FN 18 always returns metric), and write access only ever happens during program run — in simulation or block scan a write is a no-op. A typical use is pushing a probe-measured wear value into an active compensation table:

12 SEL CORR-TABLE TCS "TNC:\table\corr.tco"         ; activate compensation table
13 TABDATA READ  Q1 = CORR-TCS COLUMN "DR" KEY "5"  ; row 5, column DR -> Q1
14 TABDATA WRITE CORR-TCS COLUMN "DR" KEY "3" = Q1  ; write Q1 into row 3
15 TABDATA ADD   CORR-TCS COLUMN "DR" KEY "3" = Q1  ; or add Q1 to the existing value

SQL Statements

For anything bigger than single cells, the TNC 320 has a real SQL server — HEIDENHAIN explicitly recommends it over FN 26–28 for speed. Programming SQL requires the code number 555343. It is transaction-based: every transaction you open must be closed with SQL COMMIT or SQL ROLLBACK, even a pure read, or locks and resources stay held. Two warnings from the manual: SQL always works in metric regardless of program units, and SQL executed during simulation really writes to tables — guard with FN 18: SYSREAD ID992 NR16.

CommandPurpose
SQL BINDLink a Q/QS parameter to a table column (SQL BIND Q882 "Tab_Example.Measure_X"); without arguments, releases the binding
SQL EXECUTERuns an instruction: SELECT…WHERE…ORDER BY…FOR UPDATE (opens a transaction, returns a HANDLE; 0 = failed), plus CREATE/DROP SYNONYM, CREATE/COPY/RENAME/DROP TABLE, INSERT, UPDATE, DELETE, ALTER TABLE ADD/DROP, RENAME COLUMN
SQL FETCHReads one row of the result set into the bound parameters (HANDLE Q5 INDEX+Q2; rows count from 0; result 0 = OK)
SQL UPDATE / SQL INSERTOverwrite a row / append a row from the bound parameters (string lengths are checked against column width)
SQL COMMIT / SQL ROLLBACKWrite everything back and close / discard and close. ROLLBACK with an INDEX keeps just that row and holds the transaction open.
SQL SELECTOne-shot read of a single value, no transaction, no binding (SQL SELECT Q5 "SELECT Mess_X FROM Tab_Example WHERE Position_NR==3")

WHERE conditions: ==, !=/<>, <, <=, >, >=, IS NULL, IS NOT NULL, combined with AND/OR; compare against a Q parameter with WHERE Position_Nr==:'Q11' (Q/QL/QR get rounded to integers — use QS for exact text). The manual's complete read example:

0 BEGIN PGM SQL_READ_WMAT MM
1 SQL Q1800 "CREATE SYNONYM my_table FOR 'TNC:\table\WMAT.TAB'"  ; short name for path
2 SQL BIND QS1800 "my_table.WMAT"           ; bind QS1800 to column WMAT
3 SQL QL1 "SELECT WMAT FROM my_table WHERE NR==3"                ; open transaction, HANDLE -> QL1
4 SQL FETCH Q1900 HANDLE QL1                ; read row 0 into QS1800 (Q1900: 0=OK)
5 SQL ROLLBACK Q1900 HANDLE QL1             ; close the (read-only) transaction
6 SQL BIND QS1800                           ; release binding
7 SQL Q1 "DROP SYNONYM my_table"            ; clean up
8 END PGM SQL_READ_WMAT MM

FN 18: SYSREAD — System Data by ID/NR/IDX

Numeric system data is addressed by group ID, number NR, and an optional index IDX (often an axis 1–9 = X, Y, Z, A, B, C, U, V, W). Results are always metric. Because look-ahead pre-calculates blocks, sync the read with FN 20: WAIT FOR SYNC first when you need a live value; string system data goes through SYSSTR into a QS parameter instead.

11 FN 20: WAIT FOR SYNC                        ; stop look-ahead so the value is current
12 FN 18: SYSREAD Q1 = ID270 NR1 IDX1          ; current X position, input system
55 FN 18: SYSREAD Q25 = ID210 NR4 IDX3         ; active scaling factor, Z axis
11 QS25 = SYSSTR ( ID10950 NR1 )               ; current tool name (string)

The groups you will actually use, verified from the TNC 320 FN 18 list:

IDGroupHighlights (NR)
Program & machine state
ID10Program informationNR3 active cycle, NR6 last probe cycle, NR110/111 does file/directory QS(IDX) exist
ID15Indexed Q accessNR11/12/13 read Q(IDX)/QL(IDX)/QR(IDX)
ID20Machine statusNR1 active tool, NR2 prepared tool, NR3 tool axis, NR4 programmed rpm, NR5 spindle state, NR8 coolant, NR9 active feed
ID35Modal statusNR1 G90/G91, NR2 radius compensation R0/RR/RL
ID992Block scan / modeNR16 is the program running in simulation (guard for SQL/table writes)
Tools
ID50Tool table, any tool (IDX = tool no.)NR1 L, NR2 R, NR4/5 DL/DR, NR7 TL locked, NR8 RT, NR11 CUR_TIME, NR15 CUT, NR16/17 LTOL/RTOL, NR21/22 LBREAK/RBREAK, NR28 NMAX, NR36 TYPE
ID51 / ID52Pocket table / find pocketID51: NR1 tool in pocket, NR4 pocket locked; ID52 NR1: pocket of tool IDX
ID60Values from TOOL CALLNR1 T number, NR3 S, NR4/5 DL/DR as programmed
ID950Current tool (read/write)Same numbering as ID50 but for the active tool — NR1 L, NR2 R, NR4 DL…
ID975Tool usage testNR1 result of the usage check
Transformations, positions, presets
ID210Coordinate transformationsNR1 basic rotation (manual), NR2 programmed rotation, NR3 mirror bits, NR4 scaling (IDX axis), NR6/7 tilted plane active in run/manual, NR10 tilt type
ID220Datum shiftNR2 current shift per axis, NR3 difference reference point vs. preset
ID230Traverse rangeNR2/3 negative/positive software limits per axis
ID240 / 245REF positionsNR1 nominal position in the machine (REF) system
ID270 / 271Input-system positionNR1 current nominal position per axis (271 includes handwheel offsets)
ID290KinematicsNR4 does rotary axis participate (M138), NR10 active FUNCTION MODE kinematics index
ID500 / 507 / 508Datum & preset tablesID500 datum-table cell (row/column); ID507 preset basic transformation (IDX 1–6 = X, Y, Z, SPA, SPB, SPC); ID508 preset axis offsets
ID530Active presetNR1 row number of the active preset
Probing, time, counters
ID360Probe resultsNR1–6 last touch point in input/machine/workpiece system (varying compensation), NR10 oriented stop, NR11 probing error status
ID370Probe cycle settingsNR5 angle tracking, NR7 reaction of 14xx cycles when touch point not reached
ID320 / 321System timeNR1 seconds since 1.1.1970, NR3 processing time of current program; ID321 returns it formatted
ID920Workpiece counterNR1 planned, NR2 machined, NR12 remaining (FUNCTION COUNT)
ID590Free machine statusNR2 IDX1–30 survives program change, NR3 IDX1–30 survives power failure — free scratch registers

FN 16: F-PRINT — Formatted Output

FN 16 renders a mask file (a text file, extension .A, created in PGM MGT) into an output file, a screen pop-up, a USB/network target, or a PostScript printer. Format lines are case-sensitive; each ends with ; and * starts a comment line. Output file max 20 kB; the extension of the target file sets its type (.TXT, .A, .XLS, .HTML).

ElementMeaning
%F / %D / %IOutput a Q/QL/QR value as float / double / integer
9.3Width spec: 9 characters total, 3 decimals (e.g. "X1 = %+9.3F", Q31;+/- right/left align)
%S / %RSQS parameter formatted / raw (use %RS for paths so specials aren't parsed)
M_CLOSE / M_APPEND / M_TRUNCATEClose file (required before printing) / append on re-output / overwrite
M_EMPTY_HIDE / M_EMPTY_SHOWSuppress / show blank lines for undefined QS parameters
CALL_PATHPath of the calling NC program
DAY, MONTH, YEAR4, HOUR, MIN, SECDate/time fields; L_ENGLISH… gate lines by conversational language

Mask file and call, straight from the manual — the output lands in TNC:\PROT1.TXT:

* MASKE1.A -- the format mask
"MEASURING LOG OF IMPELLER CENTER OF GRAVITY";
"DATE: %02d.%02d.%04d",DAY,MONTH,YEAR4;
"TIME: %02d:%02d:%02d",HOUR,MIN,SEC;
"X1 = %9.3F", Q31;
"Y1 = %9.3F", Q32;
"Z1 = %9.3F", Q33;
M_CLOSE;

; in the NC program:
96 FN 16: F-PRINT TNC:\MASKE\MASKE1.A / TNC:\PROT1.TXT
11 FN 16: F-PRINT TNC:\MASKE\MASKE1.A / SCREEN:      ; pop-up on the control screen
96 FN 16: F-PRINT / SCLR:                            ; close the pop-up

Repeated output to the same target appends by default — use M_TRUNCATE or M_CLOSE to overwrite. Default output paths can be preset in machine parameters fn16DefaultPath/fn16DefaultPathSim (no. 102202/102203), but a path in the FN 16 block wins. Paths (source and target) may come from QS parameters: :'QS1'.

FN 19/20/29/37/38 — PLC and the Outside World

FN 19: PLC (two values) and FN 29: PLC (up to eight values) transfer numbers to the PLC, and FN 37: EXPORT exposes local QL/QS parameters to a calling program when you build your own cycles. All three carry a collision NOTICE in the manual and are meant for HEIDENHAIN, the machine manufacturer, or third-party cycle authors — not for day-to-day part programs. FN 20: WAIT FOR synchronizes NC and PLC; its everyday use is FN 20: WAIT FOR SYNC before an FN 18 read, as shown above. FN 38: SEND writes fixed or variable text to the log or over TCP/IP to an external application such as StateMonitor (up to seven Q values per message, C-style placeholders):

FN 38: SEND /"Q-Parameter Q1: %f Q23: %f" / +Q1 / +Q23
FN 38: SEND /"JOB:1234_STEP:1_START"          ; StateMonitor job tracking
FN 38: SEND /"JOB:1234_STEP:1_OK_I:1"         ; report one good part (incremental)

References

  • HEIDENHAIN, TNC 320 Klartext Programming User's Manual, NC software 77185x-18, 10/2023, ID 1096950-25 (Q parameters, FN functions, SQL, freely definable tables, FN 18 list).
  • HEIDENHAIN, TNC 320 User's Manual for Setup, Testing and Running NC Programs, NC software 77185x-18, 10/2023, ID 1263173-21 (tool table, pocket table, touch probe table, preset management).

Have a question or want to contribute?

Contact us with corrections, additions, or topics you'd like covered.

Get in Touch