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.
| Table | File | Key columns / notes |
|---|---|---|
| Tools | ||
| Tool table | TOOL.T | Up 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.1…5.9 rows for step tools. Never delete row 0 — it destroys the table structure. |
| Pocket table | TOOL_P.TCH | Magazine 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 table | tchprobe.tp | NO (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 table | PRESET.PR | BASE 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 | *.D | D 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 | *.TAB | Your 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 | *.PNT | Irregular 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.
| Function | Syntax | Notes |
|---|---|---|
| FN 26: TABOPEN | FN 26: TABOPEN TNC:\DIR1\TAB1.TAB | Path fixed or from a variable; quote paths containing special characters |
| FN 27: TABWRITE | FN 27: TABWRITE 5/"RADIUS,DEPTH,D" = Q5 | Writes 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: TABREAD | FN 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.
| Command | Purpose |
|---|---|
SQL BIND | Link a Q/QS parameter to a table column (SQL BIND Q882 "Tab_Example.Measure_X"); without arguments, releases the binding |
SQL EXECUTE | Runs 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 FETCH | Reads one row of the result set into the bound parameters (HANDLE Q5 INDEX+Q2; rows count from 0; result 0 = OK) |
SQL UPDATE / SQL INSERT | Overwrite a row / append a row from the bound parameters (string lengths are checked against column width) |
SQL COMMIT / SQL ROLLBACK | Write everything back and close / discard and close. ROLLBACK with an INDEX keeps just that row and holds the transaction open. |
SQL SELECT | One-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:
| ID | Group | Highlights (NR) |
|---|---|---|
| Program & machine state | ||
| ID10 | Program information | NR3 active cycle, NR6 last probe cycle, NR110/111 does file/directory QS(IDX) exist |
| ID15 | Indexed Q access | NR11/12/13 read Q(IDX)/QL(IDX)/QR(IDX) |
| ID20 | Machine status | NR1 active tool, NR2 prepared tool, NR3 tool axis, NR4 programmed rpm, NR5 spindle state, NR8 coolant, NR9 active feed |
| ID35 | Modal status | NR1 G90/G91, NR2 radius compensation R0/RR/RL |
| ID992 | Block scan / mode | NR16 is the program running in simulation (guard for SQL/table writes) |
| Tools | ||
| ID50 | Tool 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 / ID52 | Pocket table / find pocket | ID51: NR1 tool in pocket, NR4 pocket locked; ID52 NR1: pocket of tool IDX |
| ID60 | Values from TOOL CALL | NR1 T number, NR3 S, NR4/5 DL/DR as programmed |
| ID950 | Current tool (read/write) | Same numbering as ID50 but for the active tool — NR1 L, NR2 R, NR4 DL… |
| ID975 | Tool usage test | NR1 result of the usage check |
| Transformations, positions, presets | ||
| ID210 | Coordinate transformations | NR1 basic rotation (manual), NR2 programmed rotation, NR3 mirror bits, NR4 scaling (IDX axis), NR6/7 tilted plane active in run/manual, NR10 tilt type |
| ID220 | Datum shift | NR2 current shift per axis, NR3 difference reference point vs. preset |
| ID230 | Traverse range | NR2/3 negative/positive software limits per axis |
| ID240 / 245 | REF positions | NR1 nominal position in the machine (REF) system |
| ID270 / 271 | Input-system position | NR1 current nominal position per axis (271 includes handwheel offsets) |
| ID290 | Kinematics | NR4 does rotary axis participate (M138), NR10 active FUNCTION MODE kinematics index |
| ID500 / 507 / 508 | Datum & preset tables | ID500 datum-table cell (row/column); ID507 preset basic transformation (IDX 1–6 = X, Y, Z, SPA, SPB, SPC); ID508 preset axis offsets |
| ID530 | Active preset | NR1 row number of the active preset |
| Probing, time, counters | ||
| ID360 | Probe results | NR1–6 last touch point in input/machine/workpiece system (varying compensation), NR10 oriented stop, NR11 probing error status |
| ID370 | Probe cycle settings | NR5 angle tracking, NR7 reaction of 14xx cycles when touch point not reached |
| ID320 / 321 | System time | NR1 seconds since 1.1.1970, NR3 processing time of current program; ID321 returns it formatted |
| ID920 | Workpiece counter | NR1 planned, NR2 machined, NR12 remaining (FUNCTION COUNT) |
| ID590 | Free machine status | NR2 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).
| Element | Meaning |
|---|---|
%F / %D / %I | Output a Q/QL/QR value as float / double / integer |
9.3 | Width spec: 9 characters total, 3 decimals (e.g. "X1 = %+9.3F", Q31; — +/- right/left align) |
%S / %RS | QS parameter formatted / raw (use %RS for paths so specials aren't parsed) |
M_CLOSE / M_APPEND / M_TRUNCATE | Close file (required before printing) / append on re-output / overwrite |
M_EMPTY_HIDE / M_EMPTY_SHOW | Suppress / show blank lines for undefined QS parameters |
CALL_PATH | Path of the calling NC program |
DAY, MONTH, YEAR4, HOUR, MIN, SEC | Date/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