Interpreter interface

INCT_Interpreter - interface that should be implemented in the interpreter software library. The interpreter library returns a SprutCAM X object that implements the interface as a result when the NCT_GetInterface function is called. Through this interface, SprutCAM X interacts with the interpreter at all stages of interpreting the text of the G-code.


Description of interface methods:

Method

Method Description

Description of use

GetIdentifier

The function should return a SprutCAM X string with the interpreter library identifier.

No input parameters.

When the interpreter is loaded into memory, SprutCAM X calls the GetIdentifier function and expects to get the ID of the program library. Then SprutCAM X compares it with the library identifier of the interpreter settings file, if the identifiers match, it continues the loading process.

GetRegisters

The function should return the SprutCAM X interface INCT_RegisterList , which implements the list of interpreter registers.

No input parameters.

When the interpreter is loaded into memory, SprutCAM X calls the GetRegisters function and expects to get a list of interpreter registers, then calls this function for the interpreter's parents. As a result, SprutCAM X generates a general list of registers, taking into account inheritance.

SetInterface

The method should receive and, if necessary to the interpreter, save the interfaces transmitted from SprutCAM X for subsequent use. The method will be called several times: according to the number of transmitted interfaces.

Input parameter: Intf (IUnknown interface)

No output parameters.

When the interpreter is initialized, SprutCAM X sequentially passes its interfaces to the interpreter library using the SetInterface method. Transmitted interfaces can be used to interpret the text of the NC-code and provide access to:

Initialize

The method informs the interpreter about the completion of the transfer of all SprutCAM X interfaces and the ability to perform initialization of the interpreter.

No input parameters.

No output parameters.

When the interpreter initialization is complete, SprutCAM X calls the Initialize method. The method call informs the interpreter that all SprutCAM X interfaces are transmitted; the interpreter can perform the necessary actions for initialization (for example, obtain the numbers of the machine axes).

NextOperation

The method informs the interpreter about the beginning of the next operation interpretation.

No input parameters.

No output parameters.

SprutCAM X calls this method before the next operation interpreting. The interpreter can perform the necessary actions (for example, initialize internal variables, establish the order of processing NC programs of the operation).

TransLine

The method passes the frame of the control program to the interpreter (or a part of the frame, depending on the current iteration of the frame translation) to attempt to read the lexeme or the semantic construction from its beginning. In case the interpreter has recognized a token or a structure, it must return the number of characters from the beginning of the line that the recognized lexeme or structure constitutes. Otherwise, returns an amount equal to 0.

Input parameters: CurrentLine (string) - the transmitted frame or part of the frame.

Input parameters:

  • ProcessedChars (integer), the number of characters from the beginning of the string that the interpreter was able to recognize (SprutCAM X does not analyze these characters). 0 - if the token or semantic construction is not recognized.

  • NextLine (boolean), after the translation of the current frame, proceed to the translation of the next frame of the G-code without interpreting the current one. All INCT_BlockExecArray objects of the current frame will be saved and processed together with the objects of the next frame as a single block.

  • BreakLine (boolean), interrupt the translation of the current frame while maintaining the position in the frame and proceed to the interpretation of the generated INCT_BlockExecArray. The next translation will start from the saved position of the current frame.

In the process of translation the frame of the G-code, SprutCAM X allows the interpreter to recognize the token or semantic structure from the beginning of the current frame. For this, SprutCAM X calls the TransLine interpreter method, passing the current frame as an input parameter to the CurrentLine. In response, in the ProccessedChars parameter, the interpreter should return the number of characters from the beginning of the transferred string that make up the lexeme or the meaning structure, if recognized. Otherwise, if the lexeme or construct is not recognized, the interpreter returns a value of 0.

If the interpreter recognizes a lexeme or semantic structure, it is removed from the current CurrentLine line, and the line is returned to the interpreter to attempt to read the next lexeme or semantic structure by calling the TransLine method.

If the interpreter does not recognize the lexeme or the meaning structure, SprutCAM X tries to determine the register and its value according to the algorithm described in this article. After that, all the read characters are removed from the CurrentLine line, and the line is passed to the interpreter to attempt to read the next token or semantic structure by calling the TransLine method.

The process continues until the string is completed or, if the BreakLine parameter is set to True.

If, after calling TransLine, the output parameter BreakLine is True, then the broadcast of the current frame is stopped and SprutCAM X performs the process of interpreting the translated part of the frame. That is, the INCT_BlockExecArray formed by this time will be interpreted.

If after calling TransLine the output parameter of NextLine is True, then after the translation of the current frame is completed, SprutCAM X reads and translates the next frame of the G-code without interpreting the current frame. INCT_BlockExecArray generated by the translation of the current frame is not cleared, and is supplemented with objects created during the interpretation of the next frame. After the translation of the next string is completed and, if the NextLine parameter again does not take the value True, the INCT_BlockExecArray accumulated as a result of the translation of two frames is interpreted. If NextLine is True again, after the second frame is completed, SprutCAM X reads and translates the third frame, and so on.

DefineRegister

The function should perform a register search by address, return the search result and the index of the found register.

Input parameter: Addr (string) - the address of the register.

Output parameter: Index (integer) - index of the found register.

When reading the token, SprutCAM X tries to determine the register in the character set read from the G-code frame. For this, SprutCAM X calls the Interpreter Interface DefineRegister function, where the read character set is passed as the Addr register address. If the interpreter responds positively, the register is considered defined and its index is contained in the output parameter Index. If the interpreter has a negative response, SprutCAM X tries to find the register by the address in the list of registers.

When implementing the function (INCT_Interpreter.DefineRegister), it is recommended to search and identify only those registers that cannot be uniquely determined by the kernel of SprutCAM X. In other cases, the search does not perform, return a negative result.

BeforeInterprete

The method informs the interpreter about the end of the current frame translation and the beginning of its interpretation.

No input parameters.

No output parameters.

Before interpreting the current frame of the G-code, SprutCAM X calls the interpreter's BeforeInterprete method. The method is designed to initialize variables and objects associated with the current frame, if necessary.

Interprete

The method passes to the interpreter the element number from the list of objects for interpreting the current frame. The interpreter must interpret the transmitted object, i.e. by object number, determine its type and, if necessary, add a command to form the element (s) of the tool path in INCT_CLData.

Input parameter: ExecNum (integer) - the number of the element of the list of objects for interpretation (INCT_BlockExecArray).

No output parameters.

In the process of interpreting the current frame of the G-code, if the INCT_BlockExecArray list is not empty, SprutCAM X consistently executes the Interprete method for each of the list objects. The method is intended to interpret an object from the list, i.e. for the formation of the element of the tool path of the previously translated object.

Example for Fanuc rack. If the transferred object is a register with the address F (feed), then to change the feed for the current tool path, you need to run the INCT_CLData.OutFeed method. Pass the register value as the feed parameter.

AfterInterprete

The method informs the interpreter about the end of the interpretation of the current frame.

No input parameters.

No output parameters.

After interpreting the current frame of the G-code, SprutCAM X calls the interpreter's AfterInterprete method. The method is designed to free memory of variables and objects associated with the processed frame, if necessary.

EndOfProgram

The function should return the end of the program to SprutCAM X if the end of the program command was processed when interpreting the text of the G-code. Translation and interpretation of the G-code is completed.

No output parameters.

Before executing the next Interprete method, SprutCAM X calls the EndOfProgram function. If the function returns True, then the interpretation of the current frame and the translation of the subsequent text of the G-code are terminated.