Table of Contents

Class ToolChangeSyntax

Namespace
Hi.NcParsers.LogicSyntaxs
Assembly
HiMech.dll

Consumes T (tool number) and M06 (tool change) from Parsing. T is modal — persists across blocks. M06 triggers the change. Writes resolved state to a ToolChange section: { “ToolId”: 1, “IsChange”: true, “Term”: “M06” }. TermKey records the trigger command and is only written when IsChangeKey is true (i.e. the block actually carried the tool-change M code); modal-only blocks omit it.

Two more keys mirror HardNc's T / PreparationT split. PreparedToolIdKey holds the second T of a dual tool word (T10 T2 M06: 10 is loaded, 2 is pre-selected) and is carried until the next change loads it. EquippedToolIdKey is written on non-change blocks and names the tool in the spindle — the ToolId of the last change — because ToolId on such a block may already be a pre-selection (T2 alone). Consumers read it through ReadEquippedToolId(JsonObject).

ToolId is an int for numeric calls (T5) and a string for Siemens string tool calls (T="D8R1", captured by SiemensToolCallSyntax); both shapes carry modally. String names are resolved to tool numbers at the semantic layer (ToolChangeSemantic) — this syntax records the call verbatim.

The trigger is machine-configurable. A custom tool-change M-code (Siemens MD22560 $MC_TOOL_CHANGE_M_CODE) is declared on the controller parameter table (IsToolChange) and reaches this syntax already expanded to M06 by MCodeExpansionSyntax. Turret/lathe machines where the T word itself performs the change (Siemens MD22550 $MC_TOOL_CHANGE_MODE = 0) set ToolWordTriggersChange; the block then triggers with ToolWordTerm recorded as TermKey. Without that config a bare T block stays pre-selection only — magazine rotation is the PLC's business and moves no feed axis.

public class ToolChangeSyntax : ISituNcSyntax, INcSyntax, IMakeXmlSource
Inheritance
ToolChangeSyntax
Implements
Inherited Members
Extension Methods

Examples

T5 + M06 — full tool change on one block; both T and M06 flag consumed, Term written: #BeforeBuild:

{ "Parsing": { "Flags": ["M06"], "T": 5 } }

#AfterBuild:

{ "ToolChange": { "ToolId": 5, "IsChange": true, "Term": "M06" } }

T5 alone alongside an unrelated flag — modal arming only, no actual change; IsChange=false and Term omitted. M03 is left in place because CleanupParsing only runs on the M06 branch: #BeforeBuild:

{ "Parsing": { "Flags": ["M03"], "T": 7 } }

#AfterBuild:

{
  "Parsing": { "Flags": ["M03"] },
  "ToolChange": { "ToolId": 7, "IsChange": false }
}

M06 alone — T comes from #Previous: modal lookback; IsChange=true, Term=“M06”: #Previous:

{ "ToolChange": { "ToolId": 5, "IsChange": false } }

#BeforeBuild:

{ "Parsing": { "Flags": ["M06"] } }

#AfterBuild:

{ "ToolChange": { "ToolId": 5, "IsChange": true, "Term": "M06" } }

Siemens string tool call + M06 — the name carries verbatim as a string ToolId: #BeforeBuild:

{ "Parsing": { "Flags": ["M06"], "T": "D16R3Z6" } }

#AfterBuild:

{ "ToolChange": { "ToolId": "D16R3Z6", "IsChange": true, "Term": "M06" } }

T alone under turret semantics (test hardcodes an IToolChangeTriggerConfig dependency with ToolWordTriggersChange = true) — the T word itself triggers the change and Term records “T”: #BeforeBuild:

{ "Parsing": { "T": 9 } }

#AfterBuild:

{ "ToolChange": { "ToolId": 9, "IsChange": true, "Term": "T" } }

Dual tool word T10 T2 M06 (Mazak; some Fanuc posts) — the parser keeps the first T in Parsing.T and lists the second under RepeatedWords: M06 loads 10, 2 is pre-selected as PreparedToolId (HardNc: T = first grab on the M06 branch, the leftover T becomes PreparationT): #BeforeBuild:

{ "Parsing": { "Flags": ["M06"], "T": 10, "RepeatedWords": { "T": [2] } } }

#AfterBuild:

{ "ToolChange": { "ToolId": 10, "PreparedToolId": 2, "IsChange": true, "Term": "M06" } }

Bare M06 after a dual tool word — the change loads the prepared tool and consumes the slot (nothing stays armed): #Previous:

{ "ToolChange": { "ToolId": 10, "PreparedToolId": 2, "IsChange": true, "Term": "M06" } }

#BeforeBuild:

{ "Parsing": { "Flags": ["M06"] } }

#AfterBuild:

{ "ToolChange": { "ToolId": 2, "IsChange": true, "Term": "M06" } }

A block that performs no change carries the armed tool, the prepared tool and — for consumers that need the tool in the spindle rather than the armed one (ToolHeightOffsetSyntax's omitted-H fallback) — EquippedToolId, the ToolId of the last change: #Previous:

{ "ToolChange": { "ToolId": 10, "PreparedToolId": 2, "IsChange": true, "Term": "M06" } }

#BeforeBuild:

{ "Parsing": { "Flags": ["M03"] } }

#AfterBuild:

{
  "Parsing": { "Flags": ["M03"] },
  "ToolChange": { "ToolId": 10, "PreparedToolId": 2, "IsChange": false, "EquippedToolId": 10 }
}

Fields

EquippedToolIdKey

Section key holding the tool currently in the spindle on blocks that do not perform a change themselves (on a change block the equipped tool is ToolIdKey). Read through ReadEquippedToolId(JsonObject).

public const string EquippedToolIdKey = "EquippedToolId"

Field Value

string

IsChangeKey

Section key indicating whether the current block actually triggers a tool change.

public const string IsChangeKey = "IsChange"

Field Value

string

PreparedToolIdKey

Section key holding the tool pre-selected by the SECOND T word of a dual-word change block (T10 T2 M06: 10 is loaded, 2 is prepared). Carried modally until the next change consumes it.

public const string PreparedToolIdKey = "PreparedToolId"

Field Value

string

SectionName

JSON section name where the resolved tool-change state is written.

public const string SectionName = "ToolChange"

Field Value

string

TermKey

Section key recording the trigger command (e.g., M06) when IsChangeKey is true.

public const string TermKey = "Term"

Field Value

string

ToolIdKey

Section key holding the active tool number (modal).

public const string ToolIdKey = "ToolId"

Field Value

string

ToolWordTerm

TermKey value recorded when the T word itself triggered the change (ToolWordTriggersChange).

public const string ToolWordTerm = "T"

Field Value

string

Properties

Name

Syntax kind name (typically the concrete type name).

public string Name { get; }

Property Value

string

XName

XML element name used to register this syntax with XFactory.

public static string XName { get; }

Property Value

string

Methods

Build(LazyLinkedListNode<SyntaxPiece>, List<INcDependency>, NcDiagnosticProgress)

Build syntax arrangement into the syntaxPieceNode in-place.

public void Build(LazyLinkedListNode<SyntaxPiece> syntaxPieceNode, List<INcDependency> ncDependencyList, NcDiagnosticProgress ncDiagnosticProgress)

Parameters

syntaxPieceNode LazyLinkedListNode<SyntaxPiece>
ncDependencyList List<INcDependency>
ncDiagnosticProgress NcDiagnosticProgress

MakeXmlSource(string, string, bool)

Creates an XML representation of the object. This method may also generate additional resources such as related files.

public XElement MakeXmlSource(string baseDirectory, string relFile, bool exhibitionOnly)

Parameters

baseDirectory string

The base directory for resolving relative paths

relFile string

The relative file path for the XML source

exhibitionOnly bool

if true, the extended file creation is suppressed.

Returns

XElement

An XML element representing the object's state

Remarks

For the demand of easy moving source folder (especially project folder) without configuration file path corruption, the relative file path is applied. The baseDirectory is typically the folder at the nearest configuration file folder. Since the folder can be moving with the configuration file.

ReadEquippedToolId(JsonObject)

The numeric tool in the spindle at this block: the block's own ToolIdKey when it performs the change, otherwise the carried EquippedToolIdKey. Null before the first change of the program, and for a string (Siemens name) tool call. One-step read — no backward walk.

public static int? ReadEquippedToolId(JsonObject json)

Parameters

json JsonObject

The block's JSON object.

Returns

int?

Reg(XFactory)

Registers this type's deserializer with the given XFactory (or Default when factory is null). Idempotent.

public static void Reg(XFactory factory = null)

Parameters

factory XFactory