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
ncprog
This variable holds the CNC program. The program may have been created by the IEC-program or within the CNC-Editor.
Input
bExecute
BOOL
Execution starts on the rising edge.
bAbort
BOOL
If
TRUE
, the current processing of this function block is abortedbAppend
BOOL
The input
bAppend
is intended for the use-case of appending a further G-Code file to the last one, keeping the decoder state. The result is the same as if both G-Code files would have been copied into a single file, with a few exceptions as mentioned below. The out-queue is not cleared, only the bEndOfData flag is reset. State like the decoder coordinate system (G54, G55, G56), the arc coordinate system (G15, G16, G17, G18, G19), the current mode (G90, G91, G98, G99), or the implicit variable is kept and used for the new G-Code.Restrictions:
The first rising edge of
bExecute
must havebAppend = FALSE
, otherwise the errorSMC_CNC_APPEND_ON_FIRST_RISING_EDGE
is returend.Splines (G05/G10) cannot be continued. If the first G-Code ends with a spline, and the following G-Code starts with a spline, a spline stop is done at the end of the previous G-Code, nevertheless.
The inputs
piStartPosition
andvStartToolLength
are ignored ifbAppend
isTRUE
.bStepSuppress
BOOL
When this input is
TRUE
, lines of the CNC program starting with ‚/’ will be ignored. Otherwise they will be processed.piStartPosition
Start position of the path. Only the position of the axes (piStartPosition.dX/dY/dZ/dA/dB/dC/dA1/…/dA6) is used, the other members of piStartPosition are ignored.
vStartToolLength
SMC_Vector3d
Start tool length.
nSizeOutQueue
UDINT
This 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)
.pbyBufferOutQueue
POINTER 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.bEnableSyntaxChecks
BOOL
Turns 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.
eOriConv
SMC_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.
dCircleTolerance
LREAL
- 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
x
be 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.
dPrecision
LREAL
The precision of the path in technical units. This value indicates the precision of the positions read from the G-Code. For example, if the G-Code is given with 3 places after the decimal point, the precision should be set to 1e-3 units. The precision must be non-negative.
The precision value is used for example by path preprocessors like SMC_ToolRadiusCorr and SMC_AvoidLoop.
Output
bDone
BOOL
This variable will be set to
TRUE
as soon as the input data has been processed completely. The function block will not perform any further actions until it gets reset.bBusy
BOOL
TRUE
, while execution of function block is not finished.bError
BOOL
Signals that an error has occurred within the function block.
wErrorID
SMC_ERROR
Error identification
poqDataOut
POINTER TO SMC_OUTQUEUE
Pointer to the SMC_OUTQUEUE structure that manages the decoded SMC_GEOINFO objects.
iStatus
The current status.
iLineNumberDecoded
DINT
The variable contains the 0-based line number of the CNC file.
GCodeText
The G-Code text.
Methods:
Structure: