SMC_NCDecoder (FB)¶
FUNCTION_BLOCK FINAL SMC_NCDecoder
This function block is used to convert a CNC program (Din 66025, G-code), into a list of SMC_GEOINFO objects. In each cycle, one line of the program is decoded.
Note
The maximum number of M-functions in a row is 64.
If the G-Code contains more than 64 M-functions in a row,
the error SMC_DEC_OUTQUEUE_RAN_EMPTY occurs.
This restriction can be circumvented by inserting a G75
previous to the first M-function of the sequence.
G4-elements count as M-functions, too.
Note
As from V3.5 SP2 of the programming system, iLineNumberDecoded
stores the just coded 0-based line number of the CNC file.
In earlier versions, in particular CODESYS V2.3, the sentence number
(= value of the N-word) had been stored there.
Note
This function block has been superseeded by SMC_NCInterpreter and is kept only for compatibility. It is recommended to use SMC_NCInterpreter (along with SMC_ReadNCFile2), which has additional features like mathematical expressions or sub programs in g-code
- InOut:
Scope
Name
Type
Initial
Comment
Inout
ncprogThis variable holds the CNC program. The program may have been created by the IEC-program or within the CNC-Editor.
Input
bExecuteBOOLExecution starts on the rising edge.
bAbortBOOLIf
TRUE, the current processing of this function block is abortedbAppendBOOLIf
TRUE, a rising edge ofbExecutewon’t lead to a reset of the out-queue. Instead, newly incoming data will be written to the end of the out-queue.bStepSuppressBOOLWhen this input is
TRUE, lines of the CNC program starting with ‚/’ will be ignored. Otherwise they will be processed.piStartPositionStart position of the path.
vStartToolLengthSMC_Vector3dStart tool length.
nSizeOutQueueUDINTThis variable contains the size of the data buffer, the list of SMC_GEOINFO structure objects will be written to. This buffer must be able to hold at least five SMC_GEOINFO objects. Otherwise, the function block will not execute any actions at all. Its size may be predefined, but may be modified later only during a reset. It is recommended to create the buffer as described by the example below:
ExampleBuf: Array[1..50] of SMC_GeoInfo;The appropriate buffer size will then be retrieved by use of the operator
sizeof(ExampleBuf).pbyBufferOutQueuePOINTER TO ARRAY [0..0] OF SMC_GEOINFO
This input must point to the first byte of the memory area that is allocated for the SMC_OUTQUEUE structure. This area must be at least as big as defined in
nSizeOutQueue. Typically the allocation of the memory buffer is done in the declaration part of the IEC-program by defining an array of SMC_GEOINFO (e.g.BUF: ARRAY[1..50] OF SMC_GEOINFO; for a buffer that can store 50 path elements). The value may be predefined, but may be modified later on only during a reset.bEnableSyntaxChecksBOOLTurns on syntax checks that will detect invalid G-code and stop with an error in this case. It is recommended to use the syntax checks.
eOriConvSMC_ORI_CONVENTION.ADDAXES
Defines the way the orientation in the A/B/C words is interpreted.
For movement commands (such as G01, G02, …), the value determines how A/B/C are treated. For values other than SMC_ORI_CONVENTION.``ADDAXES``, the angles A/B/C may be normalized, even if no coordinate rotation has been programmed. For example with orientation convention ZYZ, a programmed orientation of A=90° B=0° C=0° may result in the (equivalent) rotation A=0° B=0° C=90° in the path element.
For commands that set the decoder coordinate system (G54/G55/G56), the value determines how the coordinates A/B/C are treated. If the value is SMC_ORI_CONVENTION.``ADDAXES``, then A/B/C are treated as independent additional axes, for which offsets are set. For all other values, A/B/C are treated as an orientation, and the decoder coordinate system is rotated accordingly.
Note
If used with tool correction functions such as SMC_ToolLengthCorr, the same orientation convention has to be used there.
dCircleToleranceLREAL- Tolerance to decide whether the definition of a circle makes sense.
case definition via target-position and radius: If the distance between start- and end-position (both projected onto the circle plane) is greater than
2 * the radius + MAX(fCircleTolerance, 1e-06), the circle will be converted into a line.case definition via target- and center-position: Let
xbe the maximum of the distance between start- and center-position and the distance between target- and center-position (projecting everything onto the circle plane). If those distances differ by more thanMAX(fCircleTolerance, 0.1 * x), the circle will be converted into a line.
Output
bDoneBOOLThis variable will be set to
TRUEas soon as the input data has been processed completely. The function block will not perform any further actions until it gets reset.bBusyBOOLTRUE, while execution of function block is not finished.bErrorBOOLSignals that an error has occurred within the function block.
wErrorIDSMC_ERRORError identification
poqDataOutPOINTER TO SMC_OUTQUEUE
Pointer to the SMC_OUTQUEUE structure that manages the decoded SMC_GEOINFO objects.
iStatusThe current status.
iLineNumberDecodedDINTThe variable contains the 0-based line number of the CNC file.
GCodeTextThe G-Code text.
Methods:
Structure: