Table of Contents

Class FanucWhileDoIterationDependency

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

Watchdog for Fanuc Custom Macro B WHILE/END m bounded loops. Sibling to FanucGotoIterationDependency with the same “soft-cap + runtime counter + session-init ISessionResettable” shape, but kept as a separate dep (rather than sharing the GOTO bucket) so loop and jump iteration limits can be tuned independently and so diagnostic codes do not cross.

The counter key is (FileName, LoopId) where FileName is the source-level file path of the WHILE/END pair (the relative path form carried on FilePath). Source-level keying means multiple inline invocations of the same subprogram pool their counts (same source-code loop), while two different files each with their own WHILE DO 1 stay isolated.

The consuming syntax (FanucWhileDoSyntax) increments the counter at the END m reverse-jump step — not on the WHILE entry — so a loop that exits on first WHILE evaluation (condition false from the outset) consumes zero iterations. Above MaxIterationsPerLoopId, the END m block emits a warning and suppresses the redirect; subsequent flow falls through past END.

Default MaxIterationsPerLoopId is 10000 — higher than the GOTO equivalent (1000) because WHILE/END is the legitimate iteration primitive that NcOpt-generated programs (drill grids, adaptive sweeps) depend on, and 1000 is too tight for those.

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

Constructors

FanucWhileDoIterationDependency()

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

public FanucWhileDoIterationDependency()

FanucWhileDoIterationDependency(XElement)

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

public FanucWhileDoIterationDependency(XElement src)

Parameters

src XElement

Root element named XName.

Fields

DefaultMaxIterationsPerLoopId

Default for MaxIterationsPerLoopId. Sized for legitimate macro iteration (NcOpt drill grids, calibration sweeps) while still catching runaway loops in a tractable time.

public const int DefaultMaxIterationsPerLoopId = 10000

Field Value

int

Properties

CountByLoop

Per-loop hit counter keyed by (FileName, LoopId). 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 LoopId), int> CountByLoop { get; }

Property Value

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

MaxIterationsPerLoopId

Soft cap on consecutive END m reverse-jumps for any single (FileName, LoopId) pair. Above this the END m block emits FanucWhileDo–IterationLimitExceeded and suppresses the redirect; flow falls through past END.

public int MaxIterationsPerLoopId { 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 CountByLoop; leaves MaxIterationsPerLoopId 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