Table of Contents

Class FanucGotoIterationDependency

Namespace
Hi.NcParsers.Dependencys.Fanuc
Assembly
HiMech.dll

Watchdog for Fanuc Custom Macro B GOTO loops. Holds a MaxIterationsPerTarget limit (XML-persisted user config — the soft cap above which the upcoming FanucGotoSyntax stops firing and emits a warning) plus a runtime per-target hit counter (CountByTarget — not serialised, cleared at session start by the ISessionResettable sweep in RunControlLines(string, IEnumerable<string>, MachiningSession, SessionProgress, CancellationToken)).

The dependency is syntax-managed: FanucGotoSyntax reads the limit, increments the counter, and decides whether to fire. There is no host Func provider — the dep is placed in Hi.NcParsers.Dependencys.Fanuc rather than Hi.NcParsers.Dependencys.SystemWired because nothing outside the syntax pipeline writes it; OnSessionReset() is the session-init hook the runner invokes through ISessionResettable, not a host-wired Func.

The counter key is (FileName, TargetN) where FileName is the source-level file path of the block containing the GOTO (the relative path form carried on FilePath — same form used by IndexedFileLine labels). Source-level keying means multiple inline invocations of the same subprogram pool their counts (they ARE the same source-code GOTO), while two different files with their own N100 stay isolated (they ARE different jumps).

Default MaxIterationsPerTarget is 1000 — a runaway-loop guard, not a precise iteration budget. Legitimate macro loops (multi-hole drill matrices, calibration sweeps) sit well below this; truly infinite loops hit the limit fast. Projects with batch-style macros that legitimately need higher counts can raise the value in the project XML.

public class FanucGotoIterationDependency : INcDependency, IMakeXmlSource, ISessionResettable
Inheritance
FanucGotoIterationDependency
Implements
Inherited Members
Extension Methods

Constructors

FanucGotoIterationDependency()

Initializes a new instance with the default limit and an empty counter.

public FanucGotoIterationDependency()

FanucGotoIterationDependency(XElement)

Loads MaxIterationsPerTarget from XML produced by MakeXmlSource(string, string, bool); absent element falls back to DefaultMaxIterationsPerTarget.

public FanucGotoIterationDependency(XElement src)

Parameters

src XElement

Root element named XName.

Fields

DefaultMaxIterationsPerTarget

Default for MaxIterationsPerTarget. Sized as a runaway-loop guard: legitimate Fanuc macros (drill grids, calibration sweeps) stay well below, while truly unbounded loops hit it fast.

public const int DefaultMaxIterationsPerTarget = 1000

Field Value

int

Properties

CountByTarget

Per-target hit counter keyed by (FileName, TargetN). Runtime-only; not serialised. Cleared by OnSessionReset() on the session-init edge so a brand-preset runner reused across sessions does not leak counts.

public Dictionary<(string FileName, int TargetN), int> CountByTarget { get; }

Property Value

Dictionary<(string FileName, int TargetN), int>

MaxIterationsPerTarget

Soft cap on consecutive fires of any single GOTO target within one source file (see CountByTarget for the keying). Above this, the consuming syntax should emit a warning and suppress the redirect on the over-limit block; subsequent blocks flow through naturally.

public int MaxIterationsPerTarget { get; set; }

Property Value

int

XName

XML element name used to register this dependency with XFactory.

public static string XName { get; }

Property Value

string

Methods

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.

OnSessionReset()

Clears CountByTarget; leaves MaxIterationsPerTarget untouched.

public void OnSessionReset()

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