SINUMERIK 840D sl/828D. Job Planning. Programming Manual (2010-2018) - page 3

 

  Index      Manuals     SINUMERIK 840D sl/828D. Job Planning. Programming Manual (2010-2018)

 

Search            copyright infringement  

 

   

 

   

 

Content      ..     1      2      3      4      ..

 

 

 

SINUMERIK 840D sl/828D. Job Planning. Programming Manual (2010-2018) - page 3

 

 

Flexible NC programming
2.17 Activate machine data (NEWCONF)
2.17
Activate machine data (NEWCONF)
The NEWCONF command activates all machine data. The function can also be activated in the
HMI user interface by pressing the "MD data effective" softkey.
When the "NEWCONF" function is executed there is an implicit preprocessing stop; in other
words, path movement is interrupted.
Syntax
NEWCONF
Meaning
NEWCONF:
Command for setting all machine data of the "NEW_CONFIG" effectiveness level active
Cross-channel execution of NEWCONF from the part program
If changes are made to axial machine data from the part program and then activated with
NEWCONF, NEWCONF will only activate the machine data containing changes affecting the part
program channel.
Note
In order to ensure that all changes are applied, the NEWCONF command must be executed in
every channel in which the axes or functions affected by the changes to the machine data is
being calculated.
No axial machine data is effective for NEWCONF.
An axial RESET must be performed for axes controlled by the PLC.
Example
Milling: Machine drill position with different technologies
Program code
Comment
N10 $MA_CONTOUR_TOL[AX]=1.0
; Change machine data.
N20 NEWCONF
; Activate machine data.
Job Planning
144
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.18 Write file (WRITE)
2.18
Write file (WRITE)
The WRITE command writes sets/data from the NC program at the end of a file (log file) in the
passive file system or to external program memory. This can also be the program that is
presently being executed.
Note
If no such file exists in the program memory, one will be created and can be written to using
the WRITE command.
Requirement
The currently set protection level must be equal to or greater than the WRITE right of the file.
If this is not the case, access is denied with an error message (return value of error variable
= 13).
Syntax
DEF INT <error>
WRITE(<error>,"<file name>"/"<ExtG>","<set/data>")
Meaning
WRITE:
Command for appending a block or data to the end of the specified file.
<error>:
Parameter 1: Variable for returning the error value
Type:
INT
Value:
0
No error
1
Path not permitted
2
Path not found
3
File not found
4
Incorrect file type
10
File is full
11
The file is in use
12
No resources available
13
No access rights
14
Missing or unsuccessful EXTOPEN for the output device
15
Error when writing to an external device
16
Invalid external path has been programmed
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
145
Flexible NC programming
2.18 Write file (WRITE)
<file name>:
Parameter 2: The name of the file in which the specified block or specified data is
to be added.
Type:
STRING
The absolute path can be specified before the actual file name. If a path is not
specified, the file is searched for in the current directory (= directory of selected
program).
Rules regarding path data, see "Addressing program memory files (Page 215)".
<ExtG>:
If the data is to be output to an external device/file using the "Process DataShare"
function, then the symbolic identifiers for the external device/file to be opened must
be specified instead of the file name.
Type:
STRING
For further information, see "Process DataShare - Output to an external device/file
(EXTOPEN, WRITE, EXTCLOSE): (Page 653)".
Note:
The identifier must be identical to the identifier specified in the EXTOPEN command.
<block/data>:
Parameter 3: The block or data to be added to the specified file.
Type:
STRING
Note
When writing to the passive file system or to an external program memory, the WRITE
command implicitly inserts an "LF" character (LINE FEED = new line) at the end of the output
string.
This behavior does not apply for output to an external device/file using the "Process
DataShare" function. If an "LF" is also to be output, then this must be explicitly specified in the
output string.
→ also refer to example 3: Implicit/explicit "LF"!
Supplementary conditions
● Maximum file size (→ machine manufacturer)
The maximum possible file size of log files in the passive file system is set with the machine
data:
MD11420 $MN_LEN_PROTOCOL_FILE
The maximum file length is applicable for all files created using the WRITE command in the
passive file system. If it is exceeded, an error message is output and the block or data is
not saved. If there is sufficient free memory, a new file can be created.
Examples
Example 1: WRITE command into the passive file system without absolute path data
Program code
Comment
N10 DEF INT ERROR
; Definition of error variables.
N20 WRITE(ERROR,"PROT","LOG FROM 7.2.97")
; Write the text "LOG FROM 7.2.97"
to file _N_PROT_MPF.
N30 IF ERROR
;Error evaluation.
Job Planning
146
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.18 Write file (WRITE)
Program code
Comment
N40 MSG ("Error with WRITE command:" <<ERROR)
N50 M0
N60 ENDIF
Example 2: WRITE command into the passive file system with absolute path data
Program code
WRITE(ERROR,"/_N_WKS_DIR/_N_PROT_WPD/_N_PROT_MPF","LOG FROM 7.2.97")
Example 3: Implicit/explicit "LF"
a) Write to the passive file system with implicitly generated "LF"
Program code
N110 DEF INT ERROR
N120 WRITE(ERROR,"/_N_MPF_DIR/_N_MYPROTFILE_MPF","MY_STRING")
N130 WRITE(ERROR,"/_N_MPF_DIR/_N_MYPROTFILE_MPF","MY_STRING")
N140 M30
Output result:
MY_STRING
MY_STRING
b) Write to an external file without implicitly generated "LF"
Program code
N200 DEF STRING[30] DEV_1
N210 DEF INT ERROR
N220 DEV_1="LOCAL_DRIVE/myprotfile.mpf"
N230 EXTOPEN(ERROR,DEV_1)
N240 WRITE(ERROR,DEV_1,"MY_STRING")
N250 WRITE(ERROR,DEV_1,"MY_STRING")
N260 EXTCLOSE(ERROR,DEV_1)
N270 M30
Output result:
MY_STRINGMY_STRING
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
147
Flexible NC programming
2.18 Write file (WRITE)
c) Write to an external file with explicitly generated "LF"
The following must be programmed in order to achieve the same result as under a:
Program code
N200 DEF STRING[30] DEV_1
N210 DEF INT ERROR
N220 DEV_1="LOCAL_DRIVE/myprotfile.mpf"
N230 EXTOPEN(ERROR,DEV_1)
N240 WRITE(ERROR,DEV_1,"MY_STRING'H0A'")
N250 WRITE(ERROR,DEV_1,"MY_STRING'H0A'")
N260 EXTCLOSE(ERROR,DEV_1)
N270 M30
Output result:
MY_STRING
MY_STRING
Job Planning
148
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.19 Delete file (DELETE)
2.19
Delete file (DELETE)
The DELETE command deletes all files, irrespective of whether these were created using the
WRITE command or not. Files that were created using a higher access authorization can also
be deleted with DELETE.
Syntax
DEF INT <error>
DELETE(<error>,"<file name>")
Meaning
DELETE:
Command for deleting the specified file.
<error>:
Variable for returning the error value.
Type.
INT
Value:
0
No error
1
Path not allowed
2
Path not found
3
File not found
4
Incorrect file type
11
The file is in use
12
No resources available
20
Other error
<file name>:
Name of the file to be deleted
Type:
STRING
The absolute path can be specified before the actual file name. If a path is not
specified, the file is searched for in the current directory (= directory of selected
program).
Rules regarding path data, see "Addressing program memory files (Page 215)".
Example
Program code
Comment
N10 DEF INT ERROR
; Definition of error variables.
N15 STOPRE
; Preprocessing stop.
N20 DELETE(ERROR,"/_N_SPF_DIR/_N_TEST1_SPF")
; Deletes file TEST1 in the sub-
program directory.
N30 IF ERROR
; Error evaluation.
N40 MSG("error for DELETE command:" <<ERROR)
N50 M0
N60 ENDIF
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
149
Flexible NC programming
2.20 Read lines in the file (READ)
2.20
Read lines in the file (READ)
The READ command reads one or several lines in the specified file and stores the information
read in a STRING type array. In this array, each read line occupies an array element.
Requirement
The currently set protection level must be equal to or greater than the READ right of the file.
If this is not the case, access is denied with an error message (return value of error variable
= 13).
Syntax
DEF INT <error>
DEF STRING[<string length>] <result>[<n>,<m>]
READ(<error>,"<file name>",<start line>,<number of lines>,<result>)
Meaning
READ:
Command for reading lines from the specified file and storing these lines in a
variable array.
<error>:
Variable for returning the error value (call-by-reference parameter)
Type.
INT
Value:
0
No error
1
Path not allowed
2
Path not found
3
File not found
4
Incorrect file type
11
The file is in use
13
Insufficient access rights
21
Line does not exist (<start line> or <number of
lines> parameter exceeds the number of lines in the
specified file).
22
Field length of the result variable (<result>) is too
small.
23
Line range too large (<number of lines> parameter
selected so large that the read would go beyond the end
of the file).
<file name>:
Name of the file to be read (call-by-value parameter)
Type:
STRING
The absolute path can be specified before the actual file name. If a path is
not specified, the file is searched for in the current directory (= directory of
selected program).
Rules regarding path data, see "Addressing program memory files
(Page 215)".
Job Planning
150
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.20 Read lines in the file (READ)
<start line>:
Start line of the file section to be read (call-by-value parameter)
Type:
INT
Value:
0
Reads the number of lines specified with the
<number of lines> parameter before the end
of the file.
1 to n
Number of the first line to be read.
<number of
Number of lines to be read (call-by-value parameter)
lines>:
Type:
INT
<result>:
Result variable (call-by-reference parameter)
Variable array in which the read text is stored.
Type:
STRING (max. length: 255)
If fewer lines are specified in the <number of lines> parameter than the
array size [<n>,<m>] of the result variable, the remaining array elements
will not be modified.
Termination of a line by means of the control characters "LF" (Line Feed) or
"CR LF" (Carriage Return Line Feed) is not stored in the result variable.
Read lines are cropped if the line is longer than the defined string length. An
error message is not output.
Note
Binary files cannot be read in. The "incorrect data type" error is output (return value of the error
variable = 4). The following types of file are not readable: _BIN, _EXE, _OBJ, _LIB, _BOT,
_TRC, _ACC, _CYC, _NCK.
Example
Program code
Comment
N10 DEF INT ERROR
; Definition of error variables.
N20 DEF STRING[255] RESULT[5]
; Definition of result variables.
N30 READ(ERROR,"/_N_CST_DIR/_N_TESTFILE_MPF", ;File name with domain and file iden-
1,5,RESULT)
tifier
and path name.
N40 IF ERROR <>0
;Error evaluation.
N50 MSG("ERROR"<<ERROR<<"ON READ COMMAND")
N60 M0
N70 ENDIF
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
151
Flexible NC programming
2.21 Check for presence of file (ISFILE)
2.21
Check for presence of file (ISFILE)
The ISFILEcommand checks whether a file exists in the program memory.
Syntax
<Result>=ISFILE("<File name>")
Meaning
ISFILE:
Command to check the availability of a file
<file name>:
Name of the file whose availability is to be checked.
Type:
STRING
The absolute path can be specified before the actual file name. If a path is not
specified, the file is searched for in the current directory (= directory of selected
program).
Rules regarding path data, see "Addressing program memory files (Page 215)".
<result>:
Result variable to which the result of the check is assigned.
Type.
BOOL
Value:
TRUE
File exists
FALSE
File does not exist
Examples
Example 1
Program code
Comment
N10 DEF BOOL RESULT
; Definition of result variables.
N20 RESULT=ISFILE("TESTFILE")
N30 IF(RESULT==FALSE)
N40
MSG("FILE DOES NOT EXIST")
N50
M0
N60 ENDIF
Example 2
Program code
Comment
N10 DEF BOOL RESULT
; Definition of result variables.
N20 RESULT=ISFILE("TESTFILE")
N30 IF(NOT ISFILE("TESTFILE"))
N40
MSG("FILE DOES NOT EXIST")
N50
M0
N60 ENDIF
Job Planning
152
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.22 Read out file information (FILEDATE, FILETIME, FILESIZE, FILESTAT, FILEINFO)
2.22
Read out file information (FILEDATE, FILETIME, FILESIZE,
FILESTAT, FILEINFO)
The FILEDATE, FILETIME, FILESIZE, FILESTAT, and FILEINFO commands read out
specific file information such as date/time of the last write access, current file size, file status
or all of this information.
Requirement
The currently set protection level must be equal to or greater than the show right of the
superordinate directory. If this is not the case, access is denied with an error message (return
value of error variable = 13).
Syntax
FILE
(<Error>,"<File name>",<Result>)
Meaning
FILEDATE:
Returns the date of the last write access to a file
FILETIME:
Returns the time of the last write access to a file
FILESIZE:
Returns the current size of a file
FILESTAT:
Returns a file with regard to the following rights for the status:
● Read (r: read)
● Write (w: write)
● Execute (x: execute)
● Show (s: show)
● Delete (d: delete)
Note:
These protection levels are specific properties of the passive file system. When
accessing an external program memory, FILESTAT therefore supplies default
access rights (77777).
FILEINFO:
For a file, supplies the sum of the information, which can be read out via
FILEDATE, FILETIME, FILESIZE and FILESTAT
<Error>:
Variable for returning the error value (call-by-reference parameter)
Type.
VAR INT
Value:
0
No error
1
Path not allowed
2
Path not found
3
File not found
4
Incorrect file type
13
Insufficient access rights
22
String length of the result variable (<result>) is too small.
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
153
Flexible NC programming
2.22 Read out file information (FILEDATE, FILETIME, FILESIZE, FILESTAT, FILEINFO)
<file name>:
Name of the file from which the file information is to be read out
Type:
CHAR[160]
The absolute path can be specified before the actual file name. If a path is not
specified, the file is searched for in the current directory (= directory of selected
program).
Rules regarding path data, see "Addressing program memory files (Page 215)".
<result>:
Result variable (Call-By-Reference parameter)
Variable in which the requested file information is stored.
Type:
VAR CHAR[8]
at
FILEDATE
Format: "dd.mm.yy"
VAR CHAR[8]
at
FILETIME
Format: "hh.mm.ss"
VAR INT
at
FILESIZE
The file size is output in bytes.
VAR CHAR[5]
at
FILESTAT
Format: "rwxsd"
(r: read, w: write, x: execute, s: show,
d: delete)
VAR CHAR[32]
at
FILEINFO
Format: "rwxsd nnnnnnnn dd.mm.yy
hh:mm:ss"
Example
Program code
Comment
N10 DEF INT ERROR
; Definition of error varia-
bles.
N20 STRING[32] RESULT
; Definition of result varia-
bles.
N30 FILEINFO(ERROR,"/_N_MPF_DIR/_N_TESTFILE_MPF",RE-
; File name with domain, file
SULT)
ID and path data.
N40 IF ERROR <> 0
; Error evaluation
N50
MSG("ERROR"<<ERROR<<"FOR FILE INFORMATION COM-
MAND")
N60
M0
N70 ENDIF
In the result variables RESULT, the example could supply the following result:
"77777 12345678 26.05.00 13:51:30"
Job Planning
154
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.23 Roundup (ROUNDUP)
2.23
Roundup (ROUNDUP)
Input values, type REAL (fractions with decimal point) can be rounded up to the next higher
integer number using the ROUNDUP" function.
Syntax
ROUNDUP(<value>)
Meaning
ROUNDUP:
Command to roundup an input value
<value>:
Input value, type REAL
Note
Input value, type INTEGER (an integer number) is returned unchanged.
Examples
Example 1: Various input values and their rounding up results
Example
Rounding up result
ROUNDUP(3.1)
4.0
ROUNDUP(3.6)
4.0
ROUNDUP(-3.1)
-3.0
ROUNDUP(-3.6)
-3.0
ROUNDUP(3.0)
3.0
ROUNDUP(3)
3.0
Example 2: ROUNDUP in the NC program
Program code
N10 X=ROUNDUP(3.5) Y=ROUNDUP(R2+2)
N15 R2=ROUNDUP($AA_IM[Y])
N20 WHEN X=100 DO Y=ROUNDUP($AA_IM[X])
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
155
Flexible NC programming
2.24 Subprogram technique
2.24
Subprogram technique
2.24.1
General information
2.24.1.1
Subprogram
The term "subprogram" has its origins during the time when part programs were split strictly
into main and subprograms. Main programs were the part programs selected for processing
on the control and then launched. Subprograms were the part programs called from within the
main program.
This strict division no longer exists with today's SINUMERIK NC language. In principle, each
part program can be selected as a main program and launched or called from another part
program as a subprogram.
Accordingly, the subprogram can then be used to refer to a part program called from within
another part program.
0DLQ SURJUDP
6XESURJUDP
Application
As in all high-level programming languages, in the NC language, subprograms swaps out
program sections used more than once to independent, self-contained programs.
Subprograms offer the following advantages:
● Increase the transparency and readability of programs
● Increase quality by reusing tested program parts
● Offer the possibility of creating specific machining libraries
● Save memory space
Job Planning
156
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
2.24.1.2
Subprogram names
Naming rules
The subprogram name can be chosen freely providing the following rules are observed:
● Permissible characters:
- Letters: A ... Z, a ... z
- Numbers: 0 ... 9
- Underscore: _
● The first two characters should either be two letters or an underscore followed by a letter.
Note
If this condition is satisfied, then an NC program can be called as subprogram from another
program just by specifying the program name. However, if the program name starts with
digits, the subprogram call is then only possible via the CALL statement.
● Maximum length: 24 characters
Note
Uppercase/lowercase letters
The SINUMERIK NC language does not distinguish between uppercase and lowercase letters.
Note
Impermissible program names
To avoid problems with Windows applications, the following program names may not be used:
● CON, PRN, AUX, NUL
● COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9
● LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9
Control-internal extensions
The program name assigned when the subprogram is created is expanded within the control
with the addition of a prefix and a suffix:
● Prefix: _N_
● Postfix: _SPF
Using the program name
When using the program name, e.g. in the context of a subprogram call, all combinations of
prefix, program name, and suffix are possible.
Example:
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
157
Flexible NC programming
2.24 Subprogram technique
The subprogram with the program name SUB_PROG can be started using the following
identifiers:
1. SUB_PROG
2. _N_SUB_PROG
3. SUB_PROG_SPF
4. _N_SUB_PROG_SPF
Main programs and subprograms with the same name
If a main program (.MPF) and a subprogram (.SPF) exist with the same program name, the
appropriate file extension for the unique identification must be specified when the program
name in the NC program is used. Otherwise the program found first in the search path with
the specified name is used.
2.24.1.3
Nesting of subprograms
A main program can call subprograms which in turn call more subprograms. As such, the
sequences of the programs are nested within each other. Each program runs on a dedicated
program level.
Nesting depth
The NC language currently provides 16 program levels. The main program always runs at the
uppermost program level, 0. A subprogram always runs at the next lowest program level
following the call. Program level 1 is, therefore, the first subprogram level.
Division of program levels:
● Program level 0: Main program level
● Program level 1 to 15: Subprogram level 1 to 15
3URJUDP OHYHOV PD[
0DLQ
6XE
SURJU
6XE
SURJU
SURJU
6XE
SURJU
Job Planning
158
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
Interrupt routines (ASUB)
If a subprogram is called in the context of an interrupt routine, this will not be executed at the
program level currently active in the channel (n) but at the next lowest program level (n+1). So
that this remains possible even at the lowest program level, 2 additional program levels (16
and 17) are available in conjunction with interrupt routines.
If more than 2 program levels are required, this has to be taken into account explicitly in the
structuring of the part program executed in the channel. In other words, only a maximum of as
many program levels may be used in order to leave sufficient program levels available for
interrupt processing.
If interrupt processing needs 4 program levels for example, the part program must be structured
so that it uses a maximum of up to program level 13. In the event of an interrupt, the 4 program
levels it requires (14 to 17) will be available to it.
Siemens cycles
Siemens cycles need 3 program levels. Therefore, a Siemens cycle must be called at the latest
in:
● Part program processing: program level 12
● interrupt routine: program level 14
2.24.1.4
Search path
When a subprogram without path details is called, the control system searches the available
program memory using a predefined search sequence (see "Search path for subprogram call
(Page 219)").
2.24.1.5
Formal and actual parameters
Formal and actual parameters occur in conjunction with the definition and calling of
subprograms with parameter transfer.
Formal parameter
When a subprogram is defined, the parameters to be transferred to it (known as the formal
parameters) have to be defined with type and parameter name.
The formal parameters define, therefore, the interface of the subprogram.
Example:
Program code
Comment
PROC CONTOUR (REAL X, REAL Y)
; Formal parameters: X and Y, both REAL type
N20 X1=X Y1=Y
; Traversing of axis X1 to position X and axis
Y1 to position Y
N100 RET
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
159
Flexible NC programming
2.24 Subprogram technique
Actual parameters
When a subprogram is called, absolute values or variables (known as actual parameters) have
to be transferred to it.
As such, the actual parameters assign up-to-date values to the interface of the subprogram
when the latter is called.
Example:
Program code
Comment
N10 DEF REAL WIDTH
; Variable definition
N20 WIDTH=20.0
; Variable assignment
N30 CONTOUR(5.5, WIDTH)
; Subprogram call with actual parameters: 5.5
and WIDTH
N100 M30
2.24.1.6
Parameter transfer
Definition of a subprogram with parameter transfer
A subprogram with parameter transfer is defined using the PROC keyword and a complete list
of all the parameters expected by the subprogram.
Incomplete parameter transfer
When the subprogram is called, not all the parameters defined in the subprogram interface
have to be transferred explicitly. If a parameter is omitted, the default value "0" is transferred
for it.
So that the parameter sequence can be uniquely identified, however, the commas used as
parameter separators always have to be included. The last parameter is an exception. If it is
omitted from the call, the last comma can also be left out.
Example:
Subprogram:
Program code
Comment
PROC SUB_PROG (REAL X, REAL Y, REAL Z)
; Formal parameters: X, Y, and Z
N100 RET
Main program:
Program code
Comment
PROC MAIN_PROG
Job Planning
160
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
Program code
Comment
N30 SUB_PROG(1.0,2.0,3.0)
; Subprogram call with complete parameter transfer:
X=1.0, Y=2.0, Z=3.0
…
N100 M30
Examples for the subprogram call in N30 with incomplete parameter transfer:
N30 SUB_PROG( ,2.0,3.0)
; X=0.0, Y=2.0, Z=3.0
N30 SUB_PROG(1.0, ,3.0)
; X=1.0, Y=0.0, Z=3.0
N30 SUB_PROG(1.0,2.0)
; X=1.0, Y=2.0, Z=0.0
N30 SUB_PROG( , ,3.0)
; X=0.0, Y=0.0, Z=3.0
N30 SUB_PROG( , , )
; X=0.0, Y=0.0, Z=0.0
NOTICE
Call-by-reference parameter transfer
Parameters transferred using call-by-reference must not be left out of the subprogram call.
NOTICE
AXIS data type
AXIS data type parameters must not be left out of the subprogram call.
Checking the transfer parameters
System variable $P_SUBPAR [ n ] where n = 1, 2, etc., can be used to check whether a
parameter has been transferred explicitly or left out in the subprogram. The index n refers to
the sequence of the formal parameters. Index n = 1 refers to the first formal parameter, index
n = 2 to the second formal parameter, and so on.
The following program excerpt shows an example of how a check can be performed based on
the first formal parameter:
Programming
Comment
PROC SUB_PROG (REAL X, REAL Y, REAL Z)
; Formal parameters: X, Y, and Z
N20 IF $P_SUBPAR[1]==TRUE
; Check of the first formal parameter
X.
; These actions are taken if the formal
parameter X has been transferred ex-
plicitly.
N40 ELSE
; These actions are taken if the formal
parameter X has not been transferred.
N60 ENDIF
; General actions
N100 RET
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
161
Flexible NC programming
2.24 Subprogram technique
2.24.2
Definition of a subprogram
2.24.2.1
Subprogram without parameter transfer
When defining subprograms without parameter transfer, the definition line at the beginning of
the program can be omitted.
Syntax
[PROC <program name>]
Meaning
PROC:
Definition operation at the beginning of a program
<program name>:
Name of the program
Example
Example 1: Subprogram with PROC operation
Program code
Comment
PROC SUB_PROG
; Definition line
N10 G01 G90 G64 F1000
N20 X10 Y20
N100 RET
; Subprogram return
Example 2: Subprogram without PROC operation
Program code
Comment
N10 G01 G90 G64 F1000
N20 X10 Y20
N100 RET
; Subprogram return
See also
Subprogram call without parameter transfer (Page 188)
2.24.2.2
Subprogram with call-by-value parameter transfer (PROC)
A subprogram with call-by-value parameter transfer is defined using the PROC keyword
followed by the name of the program and a complete list of all the parameters with their type
and name. The definition operation must appear in the first program line.
Job Planning
162
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
Call-by-value
The calling program transfers only the value of a variable to the subprogram on a call-by-value
parameter transfer. Thus the subprogram is not given direct access to the variable. In this way,
only the value visible in the subprogram is modified when the parameter value is changed.
The value of the variables defined in the calling program remains unchanged. As a
consequence, the call-by-value parameter transfer does not affect the calling program.
0DLQ SURJUDP
9DOXH DVVLJQPHQW
/(1*7+
:,'7+
6XESURJUDP
/(1*7+ :,'7+
1HZ YDOXH
DVVLJQPHQW
/(1*7+
:,'7+
1HZ YDOXHV
YDOLG
2OG YDOXHV YDOLG
Syntax
PROC <program name> (<parameter type> <parameter
name>=<init_value>, ...)
Note
Up to 127 parameters can be transferred.
Meaning
PROC:
Definition operation at the beginning of a program
<program name>:
Name of the program
<parameter type>:
Data type of the parameter (e.g. REAL, INT, BOOL)
<parameter name>:
Name of the parameter
<init_value>:
Optional value for the initialization of the parameter (optional)
If no parameter is specified when calling the subprogram, the param-
eter is assigned the initialization value.
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
163
Flexible NC programming
2.24 Subprogram technique
Examples
Example 1
Definition of a subprogram SUB_PROG with three parameters of type REAL with default
values:
Program code
PROC SUB_PROG(REAL LENGTH=10.0, REAL WIDTH=20.0, REAL HIGHT=30.0)
Example 2
Various call versions
Program code
PROC MAIN_PROG
REAL PAR_1 = 100
REAL PAR_2 = 200
REAL PAR_3 = 300
; Call variants
SUB_PROG
SUB_PROG(PAR_1, PAR_2, PAR_3)
SUB_PROG(PAR_1)
SUB_PROG(PAR_1, , PAR_3)
SUB_PROG( , , PAR_3)
N100 RET
See also
Subprogram call with parameter transfer (EXTERN) (Page 190)
2.24.2.3
Subprogram with call-by-reference parameter transfer (PROC, VAR)
A subprogram with call-by-reference parameter transfer is defined using the PROC keyword
followed by the name of the program and a complete list of all the parameters with the VAR
keyword, type, and name. The definition operation must appear in the first program line. As
parameters, references to arrays can also be transferred.
Call-by-reference
The calling program transfers not the value of a variable to the subprogram on a call-by-
reference parameter transfer, but a reference (pointer) to the variable. This gives the
subprogram direct access to the variable. In this way, not only the value visible in the
subprogram is modified when a parameter value is changed, but also the value of the variables
defined in the calling program. Call-by-reference parameter transfer therefore affects the
calling program, even after the subprogram has ended.
Job Planning
164
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
0DLQ SURJUDP
9DOXH
DVVLJQPHQW
/(1*7+
:,'7+
6XESURJUDP
/(1*7+ :,'7+
1HZ YDOXH
DVVLJQPHQW
/(1*7+
:,'7+
1HZ YDOXHV
YDOLG
/(1*7+ :,'7+
1HZ YDOXHV YDOLG
Note
The call-by-reference parameter transfer is then only necessary if the transferred variable was
defined locally in the calling program (LUD). Channel-global or NC-global variables do not
have to be transferred, since these cannot be accessed directly from within the subprogram.
Syntax
PROC <program name> (VAR <parameter type> <parameter name>, etc.)
PROC <program name> (VAR <array type> <array name>, [<m>,<n>,<o>],
etc.)
Note
Up to 127 parameters can be transferred.
Meaning
PROC:
Definition operation at the beginning of a program
VAR:
Keyword for parameter transfer via reference
<program name>:
Name of the program
<parameter type>:
Data type of the parameter (e.g. REAL, INT, BOOL)
<parameter name>:
Name of the parameter
<array type>:
Data type of the array elements (e.g. REAL, INT, BOOL)
<array name>:
Name of the array
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
165
Flexible NC programming
2.24 Subprogram technique
[<m>,<n>,<o>]:
Array size
Currently, up to 3-dimensional arrays are possible:
<m>:
Array size for 1st dimension
<n>:
Array size for 2nd dimension
<o>:
Array size for 3rd dimension
Note
● The program name specified after the PROC keyword must match the program name
assigned on the user interface.
● With arrays of an undefined array length, subprograms can process arrays of variable length
as formal parameter. When defining a two-dimensional array as a formal parameter, for
example, the length of the 1st dimension is not specified. However, the comma must be
written.
Example: PROC <program name> (VAR REAL ARRAY[,5])
Example
Definition of a subprogram with two parameters as reference to REAL type:
Program code
; Parameter 1: Reference to type: REAL, name: LENGTH
; Parameter 2: Reference to type: REAL, name: WIDTH
PROC SUB_PROG(VAR REAL LENGTH, VAR REAL WIDTH)
See also
Subprogram call with parameter transfer (EXTERN) (Page 190)
2.24.2.4
Save modal G functions (SAVE)
The SAVE attribute means that before the subprogram call, active modal G commands are
saved and are reactivated after the end of the subprogram.
NOTICE
Interrupt continuous-path mode
If, for active continuous-path mode, a subprogram is called with the SAVE attribute, the
continuous-path mode is interrupted at the end of the subprogram (return jump).
Syntax
PROC <subprogram name> SAVE
Job Planning
166
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
Meaning
SAVE:
Saves the modal G commands before the subprogram call and restores after the end of
the subprogram.
Example
In the CONTOUR subroutine, the modal G command G91 incremental dimension applies. The
modal G command G90 is effective in the main program (absolute dimension). G90 is again
effective in the main program after the end of the subprogram due to the subprogram definition
with SAVE.
Subprogram definition:
Program code
Comment
PROC CONTOUR (REAL VALUE1) SAVE
; Subprogram definition with the SAVE parame-
ter
N10 G91 ...
; Modal G command G91: Incremental dimension
N100 M17
; End of subprogram
Main program:
Program code
Comment
N10 G0 X... Y... G90
; Modal G command G90: Absolute dimensions
N20 ...
N50 CONTOUR (12.4)
;Subprogram call
N60 X... Y...
; Modal G command G90 reactivated using SAVE
Supplementary conditions
Frames
The behavior of frames regarding subprograms with the SAVE attribute depends on the frame
time and can be set using machine data.
References
Function Manual, Basic Functions; Axes, Coordinate Systems, Frames (K2),
Section: "Subprogram return with SAVE"
2.24.2.5
Suppress single block execution (SBLOF, SBLON)
Single-block suppression for the complete program
Programs designated with SBLOF are completely executed just like a block when single-block
execution is active, i.e. single-block execution is suppressed for the complete program.
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
167
Flexible NC programming
2.24 Subprogram technique
SBLOF is in the PROC line and is valid up to the end of the subprogram or until it is interrupted.
At the return command, the decision is made whether to stop at the end of the subprogram:
Return jump with M17:
Stop at the end of the subprogram
Return jump with RET:
No stop at end of subprogram
Single-block suppression within the program
SBLOF alone must remain in the block. Single block is deactivated after this block until:
● The next SBLON
or
● The end of the active subprogram level
Syntax
Single-block suppression for the complete program:
PROC ... SBLOF
Single-block suppression within the program:
SBLOF
SBLON
Meaning
PROC:
First operation in a program
SBLOF:
Command to deactivate single-block execution
SBLOF can be written in a PROC block or alone in the block.
SBLON:
Command to activate single-block execution
SBLON must be in a separate block.
Job Planning
168
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
Supplementary conditions
● Single-block suppression and block display
The current block display can be suppressed in cycles/subprograms using DISPLOF. If
DISPLOF is programmed together withSBLOF, then the cycle/subprogram call continues to
be displayed on single-block stops within the cycle/subprogram.
● Single-block suppression in the system ASUB or user ASUB
If the single-block stop in the system or user ASUB is suppressed using the settings in
machine data MD10702 $MN_IGNORE_SINGLEBLOCK_MASK (bit0 = 1 or bit1 = 1), then
the single-block stop can be reactivated by programming SBLON in the ASUB.
If the single-block stop in the user ASUB is suppressed using the setting in machine data
MD20117 $MC_IGNORE_SINGLEBLOCK_ASUP, then the single-block stop cannot be
reactivated by programming SBLON in the ASUB.
● Special features of single-block suppression for various single-block execution types
When single-block execution SBL2 is active (stop after each part program block) there is
no execution stop in the SBLON block if bit 12 is set to "1" in the
MD10702 $MN_IGNORE_SINGLEBLOCK_MASK (prevent single-block stop).
When single-block execution SBL3 is active (stop after every part program block - also in
the cycle), the SBLOF command is suppressed.
Examples
Example 1: Single-block suppression within a program
Program code
Comment
N10 G1 X100 F1000
N20 SBLOF
; Deactivate single block.
N30 Y20
N40 M100
N50 R10=90
N60 SBLON
; Reactivate single block.
N70 M110
N80 ...
The area between N20 and N60 is executed as one step in single-block mode.
Example 2: A cycle is to act like a command for a user
Main program:
Program code
N10 G1 X10 G90 F200
N20 X-4 Y6
N30 CYCLE1
N40 G1 X0
N50 M30
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
169
Flexible NC programming
2.24 Subprogram technique
Cycle CYCLE1:
Program code
Comment
N100 PROC CYCLE1 DISPLOF SBLOF
; Suppress single block
N110 R10=3*SIN(R20)+5
N120 IF (R11 <= 0)
N130
SETAL(61000)
N140 ENDIF
N150 G1 G91 Z=R10 F=R11
N160 M17
CYCLE1 is processed for active single-block execution, i.e. the Start key must be pressed
once to process CYCLE1.
Example 3: An ASUB, which is started by the PLC in order to activate a modified zero offset
and tool offsets, is to be executed invisibly.
Program code
N100 PROC ZO SBLOF DISPLOF
N110 CASE $P_UIFRNUM OF
0 GOTOF _G500
1 GOTOF _G54
2 GOTOF _G55
3 GOTOF _G56
4 GOTOF _G57
DEFAULT GOTOF END
N120 _G54: G54 D=$P_TOOL T=$P_TOOLNO
N130 RET
N140 _G54: G55 D=$P_TOOL T=$P_TOOLNO
N150 RET
N160 _G56: G56 D=$P_TOOL T=$P_TOOLNO
N170 RET
N180 _G57: G57 D=$P_TOOL T=$P_TOOLNO
N190 RET
N200 END: D=$P_TOOL T=$P_TOOLNO
N210 RET
Example 4: Is not stopped with MD10702 Bit 12 = 1
Initial situation:
● Single-block execution is active.
● MD10702 $MN_IGNORE_SINGLEBLOCK_MASK Bit12 = 1
Job Planning
170
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
Main program:
Program code
Comment
N10 G0 X0
; Stop in this part program line.
N20 X10
; Stop in this part program line.
N30 CYCLE
; Traversing block generated by the cycle.
N50 G90 X20
; Stop in this part program line.
M30
Cycle CYCLE:
Program code
Comment
PROC CYCLE SBLOF
; Suppress single-block stop.
N100 R0 = 1
N110 SBLON
; Execution is not stopped in the part program line due
to the fact that MD10702 bit12=1.
N120 X1
; Execution is stopped in this part program line.
N140 SBLOF
N150 R0 = 2
RET
Example 5: Single-block suppression for program nesting
Initial situation:
Single-block execution is active.
Program nesting:
Program code
Comment
N10 X0 F1000
; Execution is stopped in this block.
N20 UP1(0)
PROC UP1(INT _NR) SBLOF
; Suppress single-block stop.
N100 X10
N110 UP2(0)
PROC UP2(INT _NR)
N200 X20
N210 SBLON
; Activate single-block stop.
N220 X22
; Execution is stopped in this block.
N230 UP3(0)
PROC UP3(INT _NR)
N300 SBLOF
; Suppress single-block stop.
N305 X30
N310 SBLON
; Activate single-block stop.
N320 X32
; Execution is stopped in this block.
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
171
Flexible NC programming
2.24 Subprogram technique
Program code
Comment
N330 SBLOF
; Suppress single-block stop.
N340 X34
N350 M17
; SBLOF is active.
N240 X24
; Execution is stopped in this block.
SBLON is active.
N250 M17
; Execution is stopped in this block.
SBLON is active.
N120 X12
N130 M17
; Execution is stopped in this return
jump block. SBLOF of the PROC statement
is active.
N30 X0
; Execution is stopped in this block.
N40 M30
; Execution is stopped in this block.
Further information
Single-block disable for unsynchronized subprograms
In order to execute an ASUB in the single block in one step, a PROC statement must be
programmed in the ASUB with SBLOF. This also applies to the function "Editable system
ASUB" (MD11610 $MN_ASUP_EDITABLE).
Example of an editable system ASUB:
Program code
Comment
N10 PROC ASUP1 SBLOF DISPLOF
N20 IF $AC_ASUP==’H200’
N30 RET
; No REPOS for mode change.
N40 ELSE
N50 REPOSA
; REPOS in all other cases.
N60 ENDIF
Program control in single-block mode
With the single-block execution function, the user can execute a part program block-by-block.
The following setting types exist:
● SB1: Machining stops after every machine function block (except for cycles).
● SB2: Machining stops after every block, i.e. also for data blocks (except for cycles)
● SB3: Machining stops after every machine function block (also in cycles).
Single-block suppression for program nesting
If SBLOF was programmed in the PROC statement in a subprogram, then execution is stopped
at the subprogram return jump with M17. That prevents the next block in the calling program
from already running. If SBLOF, without SBLOF is programmed in the PROC statement in a
subprogram, single-block suppression is activated, execution is only stopped after the next
machine function block of the calling program. If that is not wanted, SBLON must be
programmed in the subprogram before the return (M17). Execution does not stop for a return
jump to a higher-level program with RET.
Job Planning
172
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
2.24.2.6
Suppress current block display (DISPLOF, DISPLON, ACTBLOCNO)
The current program block is displayed as standard in the block display. The display of the
current block can be suppressed in cycles and subprograms using the DISPLOF command.
Instead of the current block, the call of the cycle or the subprogram is displayed. The
DISPLON command revokes suppression of the block display.
DISPLOF and DISPLON are programmed in the program line with the PROC operation and are
effective for the entire subprogram and implicitly for all subprograms called from it which do
not contain a DISPLON or DISPLOF command. This is true for all ASUBs.
Syntax
PROC … DISPLOF
PROC … DISPLOF ACTBLOCNO
PROC … DISPLON
Meaning
DISPLOF:
Command to suppress the current block display.
Location:
At the end of the program line with the PROC operation
Effective:
Up to the return jump from the subprogram or end of program.
Note:
If further subprograms are called from the subprogram using the DISPLOF com-
mand, then the current block display is also suppressed in these subprograms
unless DISPLON is explicitly programmed in them.
DISPLON:
Command for revoking suppression of the display of the current block
Location:
At the end of the program line with the PROC operation
Effective:
Up to the return jump from the subprogram or end of program.
Note:
If further subprograms are called from the subprogram using the DISPLON com-
mand, then the current block will also be displayed in these subprograms unless
DISPLOF is explicitly programmed in them.
ACTBLOCNO:
DISPLOF together with the ACTBLOCNO attribute means that in the case of an
alarm, the number of the actual block is output in which the alarm occurred. This
also applies if only DISPLOF is programmed in a lower program level.
On the other hand, for DISPLOF without ACTBLOCNO, the block number of the
cycle or subprogram call from the last program level not designated with
DISPLOF is displayed.
Examples
Example 1: Suppress current block display in the cycle
Program code
Comment
PROC CYCLE (AXIS TOMOV, REAL POSITION)
; Suppress current block display Instead,
SAVE DISPLOF
the cycle call should be displayed, e.g.:
CYCLE(X,100.0)
DEF REAL DIFF
;Cycle contents
G01 ...
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
173
Flexible NC programming
2.24 Subprogram technique
Program code
Comment
RET
; Subprogram return jump. The block follow-
ing the cycle call is displayed in the block
display.
Example 2: Block display for alarm output
Subprogram SUBPROG1 (with ACTBLOCNO):
Program code
Comment
PROC SUBPROG1 DISPLOF ACTBLOC-
NO
N8000 R10 = R33 + R44
N9040 R10 = 66 X100
; Trigger alarm 12080
N10000 M17
Subprogram SUBPROG2 (without ACTBLOCNO):
Program code
Comment
PROC SUBPROG2 DISPLOF
N5000 R10 = R33 + R44
N6040 R10 = 66 X100
; Trigger alarm 12080
N7000 M17
Main program:
Program code
Comment
N1000 G0 X0 Y0 Z0
N1010 ...
N2050 SUBPROG1
; Alarm output = "12080 channel K1 block N9040 syntax
error for text R10="
N2060 ...
N2350 SUBPROG2
; Alarm output = "12080 channel K1 block N2350 syntax
error for text R10="
N3000 M30
Job Planning
174
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
Example 3: Revoke suppression of the current block display
Subprogram SUB1 with suppression:
Program code
Comment
PROC SUB1 DISPLOF
; Suppress current block display in SUB1 subprogram.
Instead, the block is to be displayed with the SUB1
call.
N300 SUB2
; Call subprogram SUB2.
N500 M17
Subprogram SUB2 without suppression:
Program code
Comment
PROC SUB2 DISPLON
; Revoke suppression of the current block display in
subprogram SUB2.
N200 M17
; Return to subprogram SUB1. Suppression of the cur-
rent block display is restored in SUB1.
Example 4: Display response for different DISPLON/DISPLOF combinations
3URJUDP OHYHO
03
ZLWKRXW
63
352&
63
352&
63
',63/2)
ZLWKRXW
63
352&
352&
$68%
',63/21
352&
63
',63/2)
352&
63
352&
',63/2)
63
',63/2)
352&
ZLWKRXW
63
',63/21
352&
352&
',63/2)
03 0DLQ SURJUDP
63 6XESURJUDP
$68% $V\QFKURQRXV VXESURJUDP LQWHUUXSW URXWLQH
① The part program lines from program level 0 are displayed in the current block display.
② The part program lines from program level 3 are displayed in the current block display.
③ The part program lines from program level 3 are displayed in the current block display.
④ The part program lines from program level 7/8 are displayed in the current block display.
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
175
Flexible NC programming
2.24 Subprogram technique
2.24.2.7
Identifying subprograms with preparation (PREPRO)
All files can be identified with the PREPRO keyword at the end of the PROC operation line during
power up.
Note
This type of program preparation depends on the relevant set machine data. Please follow the
manufacturer's instructions.
References:
Function Manual, Special Functions, Preprocessing (V2)
Syntax
PROC … PREPRO
Meaning
PREPRO:
Keyword for identifying all files (of the NC programs stored in the cycle directories)
prepared during power up
Read subprogram with preparation and subprogram call
The cycle directories are processed in the same order both for subprograms preprocessed
with parameters during power up and during subprogram call.
1. _N_CUS_DIR user cycles
2. _N_CMA_DIR manufacturer cycles
3. _N_CST_DIR standard cycles
In the case of NC programs sharing the same name but having different characteristics, the
first PROC operation found is activated and the other PROC operation is overlooked without an
alarm message.
2.24.2.8
Subprogram return M17
The return command M17 (or the part program end command M30) appears at the end of a
subprogram. It prompts the return to the calling program at the part program block following
the subprogram call.
Note
M17 and M30 are treated as equivalents in the NC language.
Syntax
PROC <program name>
Job Planning
176
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
M17/M30
Supplementary conditions
Effect of the subprogram return on continuous-path mode
If M17 (or M30) appears on its own in the part program block, active continuous-path mode in
the channel will be interrupted.
To avoid continuous-path mode being interrupted, M17 (or M30) has to be included in the last
traversing block. Furthermore, the following machine data must be set to "0":
MD20800 $MC_SPF_END_TO_VDI = 0 (no M30/M17 output to the NC/PLC interface)
Example
1. Subprogram with M17 in a separate block
Program code
Comment
N10 G64 F2000 G91 X10 Y10
N20 X10 Z10
N30 M17
; Return jump with interruption of continuous-path
mode.
2. Subprogram with M17 in the last traversing block
Program code
Comment
N10 G64 F2000 G91 X10 Y10
N20 X10 Z10 M17
; Return jump without interruption of continuous-
path mode.
2.24.2.9
RET subprogram return
The RET command can also be used in the subprogram as a substitute for the M17 return jump
command. RET must be programmed in a separate part program block. Like M17, RET prompts
the return to the calling program at the part program block following the subprogram call.
Note
Parameters can be programmed to change the return jump behavior of RET (see
"Parameterizable subprogram return jump (RET ...) (Page 178)").
Application
The RET operation should then be used if a G64 continuous-path mode (G641 to G645) is not
to be interrupted by the return jump.
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
177
Flexible NC programming
2.24 Subprogram technique
Requirement
The RET command can only be used in subprograms, which were not defined with the SAVE
attribute.
Syntax
PROC <program name>
RET
Example
Main program:
Program code
Comment
PROC MAIN_PROGRAM
; Start of the program
N50 SUB_PROG
; Subprogram call: SUB_PROG
N60 ...
N100 M30
; End of program
Subprogram:
Program code
Comment
PROC SUB_PROG
N100 RET
; Return jump to block N60 in the main program.
2.24.2.10
Parameterizable subprogram return jump (RET ...)
Generally, a return jump is made from a subprogram into the calling program using the RET
command. Processing is then continued with the program line following the subprogram call.
The following options are available if program processing is to be continued at another location:
● Resume program execution after calling the stock removal cycles in the ISO dialect mode
(after describing the contour).
● Return to main program from any subprogram level (even after ASUB) for error handling.
● Return jump across several program levels for special applications in compile cycles and
in the ISO dialect mode.
To achieve this, the RET command should be programmed with additional parameters.
Search direction
When specifying parameter <target block>, a return jump is first made to the block after
the calling block. A search is then made for the target in the direction of the end of the program
Job Planning
178
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
into which a return jump was made. A search is made toward the start of the program if the
search was not successful.
Syntax
RET("<target block>")
RET("<target block>",<block after target block>)
RET("<target block>",<block after target block> <number of return
jump levels>)
RET("<target block>", ,<number of return jump levels>)
RET("<target block>",<block after target block>,<number of return
jump levels>,
<return jump to the beginning of the program>)
RET( , ,<number of return jump levels>,<return jump to the beginning
of the program>)
Meaning
RET:
End of subprogram
<target block>:
Declares as jump target the block where program execution
should be resumed.
If parameter <number of return jump levels> is not programmed,
then the jump target is in the program from which the current sub-
program was called.
Possible data include:
<block number>
Number of the target block.
The search for the block number is made in
the program to which a return jump is made
- initially toward the end of the program.
<jump marker>
Jump marker, which must be available in the
program into which a return jump is made.
The search for the jump marker is made in
the program to which a return jump is made
- initially toward the end of the program.
<character
Character string that must be available in the
string>
program into which a return jump is made
(e.g. program or variable name).
The search for the character string is made
in the program to which a return jump is made
- initially toward the end of the program.
The following rules apply when programming
the character string:
● Blank at the end (contrary to the jump
marker, which is identified by ":" at the
end).
● Before the character string only one block
number and/or a jump marker may be set,
no program commands.
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
179
Flexible NC programming
2.24 Subprogram technique
<block after target
The parameter specifies as to whether program processing
block>:
should be continued in the block specified under parameter <tar-
get block> or in the following block.
Type:
INT
Value:
0
The return jump is made to the block specified
in parameter <target block>.
> 0
The return jump is made to the next block
specified in parameter <target block>.
<number of
The parameter specifies the number of program levels that should
return jump levels>:
be jumped through (return jumps) to search there for the target
block and continue processing the program.
Type:
INT
Value:
1
The program is resumed at the "current pro-
gram level -1" (just like RET without parame-
ter).
2
The program is resumed at the "current pro-
gram level -2", i.e. one level is skipped.
3
The program is resumed at the "current pro-
gram level -3", i.e. two levels are skipped.
Range of
1 ... 15
values:
<return jump to the
The parameter specifies, for a return jump into the main program,
beginning of the program>:
whether the program should be continued at the start of the pro-
gram in the active ISO dialect mode.
Type:
BOOL
Value:
1
If the return jump is made into the main pro-
gram and an ISO dialect mode is active there,
then the program branches to the beginning of
the program.
Note
For a subprogram return jump with a character string to specify the target block search, initially,
a search is always made for a jump marker in the calling program.
If a jump target is to be uniquely defined using a character string, it is not permissible that the
character string matches the name of a jump marker, as otherwise the subprogram return jump
would always be made to the jump marker and not to the character string (refer to example 2).
Supplementary conditions
When making a return jump through several program levels, the SAVE statements of the
individual program levels are evaluated.
Job Planning
180
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
If, for a return jump over several program levels, a modal subprogram is active and if in one
of the skipped programs the deselection command MCALL is programmed for the modal
subprogram, then the modal subprogram remains active.
NOTICE
Programming error
For a return jump across several program levels, it is the user's responsibility to ensure that
processing is continued with the necessary modal settings. This can be achieved, e.g. by
programming an appropriate main block.
Examples
Example 1: Resuming in the main program after ASUB execution
Programming
Comment
N10010 CALL "UP1"
; Program level 0 (main program)
N11000 PROC UP1
; Program level 1
N11010 CALL "UP2"
N12000 PROC UP2
; Program level 2
N19000 PROC ASUP
; Program level 3 (ASUB execution)
N19100 RET("N10900", ,$P_STACK)
; Subprogram return jump into the main program
; $P_STACK: actual program level
N10900
; Target block in the main program
N10910 MCALL
; Deactivate the modal subprogram call
N10920 G0 G60 G40 M5
; Initialize additional modal settings
Example 2: Character string (string>) to specify the target block search
Main program:
Program code
Comment
PROC MAIN_PROGRAM
N1000 DEF INT iVar1=1, iVar2=4
N1010 ...
N1200 subProg1
; Calls subprogram "subProg1"
N1210 M2 S1000 X10 F1000
N1220
N1400 subProg2
; Calls subprogram "subProg2"
N1410 M3 S500 Y20
N1420 ..
N1500 lab1: iVar1=R10*44
N1510 F500 X5
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
181
Flexible NC programming
2.24 Subprogram technique
Program code
Comment
N1520 ...
N1550 subprog1: G1 X30
; "subProg1" is defined here as jump marker.
N1560 ...
N1600 subProg3
; Calls subprogram "subProg3"
N1610 ...
N1900 M30
Subprogram subProg1:
Program code
Comment
PROC subProg1
N2000 R10=R20+100
N2010 ...
N2200 RET("subProg2")
; Return jump into the main program at block
N1400
Subprogram subProg2:
Program code
Comment
PROC subProg2
N2000 R10=R20+100
N2010 ...
N2200 RET("iVar1")
; Return jump into the main program at block
N1500
Subprogram subProg3:
Program code
Comment
PROC subProg3
N2000 R10=R20+100
N2010 ...
N2200 RET("subProg1")
; Return jump into the main program at block
N1550
Additional information
The following diagrams show the different effects of return jump parameters
Job Planning
182
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
1. <target block> = "N200", <block after target block> = 0
0DLQ SURJUDP
6XESURJUDP
1
68%
1
*
352& 68%
1
1
5(7 ರ1
ರ
1
After the RET command, program execution is continued with block N200 in the main program.
2. <target block> = "N200", <block after target block> = 1
0DLQ SURJUDP
6XESURJUDP
1
68%
1
*
352& 68%
1
1
5(7 ರ
ರ
1
1
1
After the RET command, program execution is continued with the block (N210) that follows
block N200 in the main program.
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
183
Flexible NC programming
2.24 Subprogram technique
3. <target block> = "N220", <number of return jump levels> = 2
PD[
SURJUDP OHYHOV
0DLQ
SURJU
6XS
SURJU
6XE
SURJU
6XE
SURJU
5(7 1
1
5HWXUQ MXPS
5HWXUQ MXPS
After the RET command, two program levels are jumped through and program execution is
continued with block N220.
2.24.2.11
Parameterizable subprogram return jump (RETB ...)
Generally, a return jump is made from a subprogram into the calling program using the RETB
command. Processing is then continued with the program line following the subprogram call.
The following options are available if program processing is to be continued at another location:
● Resume program execution after calling the stock removal cycles in the ISO dialect mode
(after describing the contour).
● Return to main program from any subprogram level (even after ASUB) for error handling.
● Return jump across several program levels for special applications in compile cycles and
in the ISO dialect mode.
To achieve this, the RETB command should be programmed with additional parameters.
Search direction
When specifying parameter <target block>, a return jump is first made to the block after
the calling block. A search is then made for the target in the direction of the beginning of the
program into which a return jump is made. A search is made toward the end of the program if
the search was not successful.
Syntax
RETB("<target block>")
RETB("<target block>",<block after target block>)
RETB("<target block>",<block after target block> <number of return
jump levels>)
RETB("<target block>", ,<number of return jump levels>)
Job Planning
184
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
RETB("<target block>",<block after target block>,<number of return
jump levels>,
<return jump to the beginning of the program>)
RETB( , ,<number of return jump levels>,<return jump to the beginning
of the program>)
Meaning
RETB:
End of subprogram
<target block>:
Declares as jump target the block where program execution
should be resumed.
If parameter <number of return jump levels> is not programmed,
then the jump target is in the program from which the current sub-
program was called.
Possible data include:
<block number>
Number of the target block.
The search for the block number is realized
in the program to which a return jump was
made initially in the direction toward the be-
ginning of the program.
<jump marker>
Jump marker, which must be available in the
program into which a return jump is made.
The search for the jump marker is realized in
the program to which a return jump was made
initially in the direction toward the beginning
of the program.
<character
Character string that must be available in the
string>
program into which a return jump is made
(e.g. program or variable name).
The search for the character string is realized
in the program to which a return jump was
made initially in the direction toward the be-
ginning of the program.
The following rules apply when programming
the character string:
● Blank at the end (contrary to the jump
marker, which is identified by ":" at the
end).
● Before the character string only one block
number and/or a jump marker may be set,
no program commands.
<block after target
The parameter specifies as to whether program processing
block>:
should be continued in the block specified under parameter <tar-
get block> or in the following block.
Type:
INT
Value:
0
The return jump is made to the block specified
in parameter <target block>.
> 0
The return jump is made to the next block
specified in parameter <target block>.
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
185
Flexible NC programming
2.24 Subprogram technique
<number of
The parameter specifies the number of program levels that should
return jump levels>:
be jumped through (return jumps) to search there for the target
block and continue processing the program.
Type:
INT
Value:
1
The program is resumed at the "current pro-
gram level -1" (just like RET without parame-
ter).
2
The program is resumed at the "current pro-
gram level -2", i.e. one level is skipped.
3
The program is resumed at the "current pro-
gram level -3", i.e. two levels are skipped.
Range of
1 ... 15
values:
<return jump to the
The parameter specifies, for a return jump into the main program,
beginning of the program>:
whether the program should be continued at the start of the pro-
gram in the active ISO dialect mode.
Type:
BOOL
Value:
1
If the return jump is made into the main pro-
gram and an ISO dialect mode is active there,
then the program branches to the beginning of
the program.
Note
For a subprogram return jump with a character string to specify the target block search, initially,
a search is always made for a jump marker in the calling program.
If a jump target is to be uniquely defined using a character string, it is not permissible that the
character string matches the name of a jump marker, as otherwise the subprogram return jump
would always be made to the jump marker and not to the character string (refer to example 2).
Supplementary conditions
When making a return jump through several program levels, the SAVE statements of the
individual program levels are evaluated.
If, for a return jump over several program levels, a modal subprogram is active and if in one
of the skipped programs the deselection command MCALL is programmed for the modal
subprogram, then the modal subprogram remains active.
NOTICE
Programming error
For a return jump across several program levels, it is the user's responsibility to ensure that
processing is continued with the necessary modal settings. This can be achieved, e.g. by
programming an appropriate main block.
Job Planning
186
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
Example
Program code
Comment
EXAMPLE.MPF
…
N3000 START_CYC(parm1, param2, …)
N3010 TECH_CYC1(param1, param2, …)
N3020 TECH_CYC2(param1, param2, …)
N3030 TECH_CYC3(param1, param2, …)
N3040 END_CYC(param1, param2, …)
N3040 END_CYC(param1, param2, …)
N3050 …
N4500 START_CYC(param11, param12, …)
N4510 …
N4590 END_CYC(param11, param12, ..)
N5000 …
…
N6000 M30
Program code
Comment
PROC END_CYC(…)
; Call in the main program, line N3040
N10000 …
N15000 if status == 1
N15010 RETB(“START_CYC”)
; Return jump to the calling program EXAMPLE.MPF
; Search for character string "START_CYC"
; Search direction: backward in the program start
direction
; Program processing is continued with line N3000
N15020 endif
N15030 if status == 0
N15040 RET
; Return jump to the calling program EXAMPLE.MPF
; Program processing is continued with line N3050
N15050 endif
N16000 RET(“START_CYC”)
; Return jump to the calling program EXAMPLE.MPF
; Search for character string "START_CYC"
; Search direction: forward in the program end di-
rection
; Program processing is continued with line N4500
N17060 RETB
; Return jump to the calling program EXAMPLE.MPF
; Program processing is continued with line N3050
; RETB without parameter is identical to RET
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
187
Flexible NC programming
2.24 Subprogram technique
2.24.3
Subprogram call
2.24.3.1
Subprogram call without parameter transfer
A subprogram is called either with address L and subprogram number or by specifying the
program name.
A main program can also be called as a subprogram. The end of program M2 or M30 set in the
main program is evaluated as M17 in this case (end of program with return to the calling
program).
Note
Accordingly, a subprogram can also be started as a main program.
Search strategy of the control:
Are there any *_MPF?
Are there any *_SPF?
This means, if the name of the subprogram to be called is identical to the name of the main
program, the main program that issued the call is called again. This is generally an undesirable
effect and must be avoided by assigning unique names to subprograms and main programs.
Note
Subprograms not requiring parameter transfer can also be called from an initialization file.
Syntax
L<number>/<program name>
Note
The subprogram call must always be programmed in a separate NC block.
Meaning
L:
Address for the subprogram call
<number>:
Name of the subprogram
Type:
INT
Value:
Maximum 7 decimal places
Notice:
Leading zeros are significant in names (⇒ L123, L0123 and
L00123 are three different subprograms).
<program name>:
Name of the subprogram (or main program)
Job Planning
188
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
Examples
Example 1: Subprogram call without parameter transfer
0DLQ SURJUDP
1
/
RU
6XESURJUDP
1
6SLJRWB
Example 2: Calling a main program as a subprogram
0DLQ SURJUDP
1
03)
$GGLWLRQDO PDLQ
RU
SURJUDP
1
:(//(
1
1
0
See also
Subprogram without parameter transfer (Page 162)
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
189
Flexible NC programming
2.24 Subprogram technique
2.24.3.2
Subprogram call with parameter transfer (EXTERN)
For a subprogram call with parameter transfer, variables or values can be transferred directly
(but not VAR parameters).
Subprograms with parameter transfer must be declared with EXTERNAL in the main program
before they are called in the main program (e.g. at the beginning of the program). The name
of the subprogram and the variable types are thereby specified in the sequence in which they
are transferred.
NOTICE
Risk of confusion
Both the variable types and the sequence of the transfer must match the definitions declared
under PROC in the subprogram. The parameter names can be different in the main program
and the subprogram.
Syntax
EXTERNAL <program name>(<type_Par1>,<type_Par2>,<type_Par3>)
<program name>(<value_Par1>,<value_Par2>,<value_Par3>)
Note
The subprogram call must always be programmed in a separate NC block.
Meaning
<program name>:
Name of subprogram
EXTERNAL:
Keyword to declare a subprogram with pa-
rameter transfer.
Note:
You only have to specify EXTERNAL if the
subprogram is in the workpiece or in the
global subprogram directory. Cycles do not
have to be declared as EXTERNAL.
<type_par1>,<type_par2>,<type_par3>:
Variable types of the parameters to be trans-
ferred in the sequence of the transfer
<value_par1>,<value_par2>,<value_par3>:
Variable values for the parameters to be
transferred
Job Planning
190
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
Examples
Example 1: Subprogram call preceded by declaration
Program code
Comment
N10 EXTERNAL BORDERS(REAL,REAL,REAL)
; Specify the subprogram.
N40 BORDER(15.3,20.2,5)
; Call the subprogram with parameter
transfer.
0DLQ SURJUDP
1
(;7(51$/
%25'(5 5($/ 5($/ 5($/
1
%25'(5
Example 2: Subprogram call without declaration
Program code
Comment
N10 DEF REAL LENGTH, WIDTH, DEPTH
N20 …
N30 LENGTH=15.3 WIDTH=20.2 DEPTH=5
N40 BORDER(LENGTH,WIDTH,DEPTH)
; or: N40 BORDER(15.3,20.2,5)
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
191
Flexible NC programming
2.24 Subprogram technique
0DLQ SURJUDP
1
/(1*7+
:,'7+
'(37+
1
%25'(5 /(1*7+ :,'7+ '(37+
RU
1
%25'(5
See also
Subprogram with call-by-value parameter transfer (PROC) (Page 162)
Subprogram with call-by-reference parameter transfer (PROC, VAR) (Page 164)
2.24.3.3
Number of program repetitions (P)
If a subprogram is to be executed several times in succession, the desired number of program
repetitions can be entered at address P in the block with the subprogram call.
CAUTION
Subprogram call with program repetition and parameter transfer
Parameters are transferred only when the program is called, i.e., on the first run. The
parameters remain unchanged for the remaining repetitions. If you want to change the
parameters during program repetitions, you must make the appropriate provision in the
subprogram.
Syntax
<program name> P<value>
Meaning
<program name>:
Subprogram call
P:
Address to program program repetitions
Job Planning
192
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
<value>:
Number of program repetitions
Type:
INT
Range of values:
1 … 9999
(unsigned)
Example
Program code
Comment
N40 FRAME P3
; The BORDER subprogram is to be executed three times one after
the other.
0DLQ SURJUDP
6XESURJUDP
1
)5$0( 3
2.24.3.4
Modal subprogram call (MCALL)
The specified subprogram is not immediately called as a result of the modal subprogram call
MCALL(<program name>). Instead, the call is performed as of this time in the part program
after each traversing block with path motion. Also across program levels.
Note
When a program is being executed only the last modal subprogram call MCALL(<program
name>) is effective (this is always the case). The current modal subprogram call replaces the
one that has been active up until then.
If parameters are transferred to the subprogram, the parameters are only transferred with call
MCALL(<program name>(Par1, Par2, ...)).
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
193
Flexible NC programming
2.24 Subprogram technique
NOTICE
Modal subprogram calls without path motion
In the following situations the modal subprogram is also called without programming path
motion:
● Programming addresses S or F if G0 or G1 is active.
● If G0 or G1 were programmed alone in the block or with additional G commands.
Syntax
MCALL <program name>
MCALL
Meaning
MCALL <program
Activate the "Modal subprogram call" function
name>:
<program name>:
Name of subprogram
MCALL:
The "Modal subprogram call" function is deactivated with MCALL without
specification of a program name.
Supplementary conditions
ASUB
If the part program processing is interrupted by an ASUB (see Chapter "Interrupt routine
(ASUB) (Page 125)"), then no modal subprogram calls are executed in this ASUB.
If an ASUB is started in the "Reset" channel state, then it behaves just like a normal part
program with regard to the modal subprogram calls.
Tool change cycle
If the "Modal subprogram call" function is deselected during the tool change cycle, note that
the tool change cycle is called implicitly, even after a block search, via the search ASUB, or
manually via overstore. In this situation, the "Modal subprogram call" function must not be
deselected because otherwise the search result is falsified. It is therefore recommended that
the deselection of the "Modal subprogram call" function in the tool change cycle is programmed
as follows:
Program code
Comment
IF $AC_ASUP == 0
; Call is not performed via search ASUB or overstore.
MCALL
; Deactivate the "Modal subprogram call" function.
ENDIF
Job Planning
194
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
Program code
Comment
Examples
Example 1
Program code
Comment
N10 G0 X0 Y0
N20 MCALL L70
; Activate the modal subprogram call for L70.
N30 X10 Y10
; X10 Y10 is approached, and then L70 is called.
N40 X20 Y20
; X20 Y20 is approached, and then L70 is called.
N100 MCALL
; Deactivate the "Modal subprogram call" function.
N110 X0 Y0
; X0 Y0 is approached, L70 is not called.
Example 2
Program code
N10 G0 X0 Y0
N20 MCALL L70
N30 L80
In this example, the following NC blocks with programmed path axes are in subprogram L80.
L70 is called by L80.
2.24.3.5
Indirect subprogram call (CALL)
Depending on the prevailing conditions at a particular point in the program, different
subprograms can be called. The name of the subprogram is stored in a variable of the STRING
type. The subprogram call is realized with CALL and the variable name.
Note
The indirect subprogram call is only possible for subprograms without parameter transfer. For
a direct subprogram call, save the name in a STRING constant.
Syntax
CALL <program name>
Meaning
CALL:
Command for the indirect subprogram call.
<program name>:
Name of the subprogram (variable or constant)
Type:
STRING
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
195
Flexible NC programming
2.24 Subprogram technique
Example
Direct call with STRING constant:
Program code
Comment
…
CALL "/_N_WKS_DIR/_N_SUBPROG_WPD/_N_PART1_SPF"
; Direct call to subprogram
PART1 with CALL.
…
Indirect call via variable:
Program code
Comment
…
DEF STRING[100] PROGNAME
: Define variable.
PROGNAME="/_N_WKS_DIR/_N_SUBPROG_WPD/_N_PART1_SPF"
; Assign subprogram PART1 to
the PROGNAME variable.
CALL PROGNAME
; Indirect call to subprogram
PART1 via CALL and the PROG-
NAME variable.
…
2.24.3.6
Indirect subprogram call with specification of the calling program part (CALL BLOCK ...
TO ...)
CALL and the keyword combination BLOCK ... TO is used to call a subprogram indirectly
and execute the program section designated by the start and end labels.
Syntax
CALL <program name> BLOCK <start label> TO <end label>
CALL BLOCK <start label> TO <end label>
Meaning
CALL:
Command for the indirect subprogram call.
<program name>:
Name of the subprogram (variable or constant) that contains the pro-
gram section to be executed (specification optional).
Type:
STRING
Note:
If a <program name> has not been programmed, the program section
designated by <start label> and <end label> is searched for
in the current program and executed.
BLOCK ... TO ... :
Keyword combination for indirect program section execution
<start label>:
Variable that refers to the start of the program section to be executed.
Type:
STRING
Job Planning
196
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
<end label>:
Variable that refers to the end of the program section to be executed.
Type:
STRING
Example
Main program:
Program code
Comment
DEF STRING[20] STARTLABEL, ENDLABEL
; Variable definition for the start and
end labels.
STARTLABEL="LABEL_1"
ENDLABEL="LABEL_2"
CALL "CONTUR_1" BLOCK STARTLABEL TO ENDLA-
; Indirect subprogram call and identifi-
BEL
er associated with the calling program
section.
Subprogram:
Program code
Comment
PROC CONTUR_1 ...
LABEL_1
; Start label: Start of program section execution.
N1000 G1 ...
LABEL_2
; End label: End of program section execution.
2.24.3.7
Indirect call of a program programmed in ISO language (ISOCALL)
A program programmed in an ISO language can be called using the indirect program call
ISOCALL. The ISO mode set in the machine data is then activated. The original execution
mode becomes effective again at the end of the program. If no ISO mode is set in the machine
data, the subprogram is called in Siemens mode.
For further information about the ISO mode, see
References:
ISO Dialects Functional Description
Syntax
ISOCALL <program_name>
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
197
Flexible NC programming
2.24 Subprogram technique
Meaning
ISOCALL:
Keyword for an indirect subprogram call with which the ISO mode set in
the machine data is activated.
<program name>:
Name of the program programmed in an ISO language (variable or con-
stant, type STRING)
Example: Calling a contour with cycle programming from ISO mode
Program code
Comment
0122_SPF
; Contour description in ISO mode
N1010 G1 X10 Z20
N1020 X30 R5
N1030 Z50 C10
N1040 X50
N1050 M99
N0010 DEF STRING[5] PROGNAME = “0122“
; Siemens part program (cycle)
N2000 R11 = $AA_IW[X]
N2010 ISOCALL PROGNAME
N2020 R10 = R10+1
; Execute program 0122.spf in ISO mode
N2400 M30
2.24.3.8
Call subprogram with path specification and parameters (PCALL)
With PCALL, you can call subprograms with the absolute path and parameter transfer.
Syntax
PCALL <path/program name>(<parameter 1>,…,<parameter n>)
Meaning
PCALL:
Keyword for subprogram call with absolute path name
<path/program name>:
Absolute path data including subprogram names.
Rules regarding path data, see "Addressing program memory
files (Page 215)".
If no absolute path name is specified, PCALL behaves like a
standard subprogram call with a program identifier.
The program name is specified without prefix and without file
identifier. If the program name is to be programmed with prefix
and file identifier, then it must be explicitly declared with prefix
and file identifier using the EXTERN command.
<parameter 1>, ...:
Actual parameters in accordance with the PROC operation of the
subprogram.
Job Planning
198
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
Example
Program code
PCALL/_N_WKS_DIR/_N_SHAFT_WPD/SHAFT(parameter1,parameter2,…)
2.24.3.9
Extend search path for subprogram calls (CALLPATH)
The search path for subprogram calls can be extended using the CALLPATH command. This
means that also subprograms can be called from a non-selected workpiece directory without
having to specify the complete, absolute path name of the subprogram.
Another application option is possible in the EES mode "EES without GDIR", if another
directory is used on an external program memory to save global subroutines. In this case,
using CALLPATH the search path can be extended by this subprogram directory.
The search path extension is made before the entry for user cycles (_N_CUS_DIR).
The search path extension is deselected again as a result of the following events:
● CALLPATH with blanks
● CALLPATH without parameter
● End of part program
● Reset
Syntax
CALLPATH("<path name>")
Meaning
CALLPATH:
Keyword for the programmable search path exten-
sion.
Is programmed in a separate part program line.
<path name>:
Constant or variable, STRING type.
Contains the absolute path name of the directory
by which the search path should be extended.
Rules regarding path data, see "Addressing pro-
gram memory files (Page 215)".
Example
The search path should be extended by a certain workpiece directory:
Program code
CALLPATH ("/_N_WKS_DIR/_N_MYWPD_WPD")
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
199
Flexible NC programming
2.24 Subprogram technique
This means that the following search path is set (position 5. is new):
1. Actual directory/name
2. Actual directory/name_SPF
3. Actual directory/name_MPF
4.
//NC:/_N_SPF_DIR / name_SPF
5.
/_N_WKS_DIR/_N_MYWPD_WPD/name_SPF
6. /N_CUS_DIR/name_SPF
7.
/_N_CMA_DIR/name_SPF
8.
/_N_CST_DIR/name_SPF
Supplementary conditions
● CALLPATH checks whether the programmed path name actually exists. In the case of an
error, part program execution is interrupted with correction block alarm 14009.
● CALLPATH can also be programmed in INI files. It is only effective for the time it takes to
process the INI file (WPD-INI file or initialization program for NC active data, e.g. frames in
the 1st channel _N_CH1_UFR_INI). The search path is again reset.
2.24.3.10
Execute external subprogram (840D sl) (EXTCALL)
A part program can be loaded from an external memory and executed with the EXTCALL
command.
The following are available as external memory:
● Local drive
● Network drive
● USB drive
Note
Only the USB interfaces on the operator panel front or the TCU can be used as an interface
for processing an external program on a USB drive.
NOTICE
Tool/workpiece damage when using a USB flash drive
It is recommended that a USB flash drive is not used to execute an external subprogram.
A communication interruption to the USB flash drive while executing the subprogram as
a result of contact problems, drop out, interruption through a knock or accidental
unplugging stops the machining immediately. The tool and/or workpiece could be
damaged.
Default setting of the external program path
The path for the external program directory can be preset with the setting data:
SD42700 $SC_EXT_PROG_PATH
Job Planning
200
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
Together with the program path and identifier specified with the EXTCALL call, this forms the
entire path for the subprogram to be called.
Note
If the program path is specified only via the EXTCALL call, then SD42700 must be empty.
Note
Parameters
When an external program is called, no parameters can be transferred to it.
Syntax
EXTCALL("<Path/><Program name>")
Meaning
EXTCALL:
Command for calling an external subprogram.
"<Path/><Program name>":
Constant/variable of type STRING
<Path/>:
Absolute or relative path specifica-
tion (optional)
<Program name>:
The program name is specified with-
out prefix "_N_".
The file extensions ("MPF", "SPF")
can be attached to program names
using the "_" or "." character (option-
al).
Example:
"SHAFT"
"SHAFT_SPF"
"SHAFT.SPF"
Path specification: Short designations
The following short designations can be used to specify the path:
● Local drive: "LOCAL_DRIVE:"
● CF card: "CF_CARD:"
● USB drive (operator panel front): "USB:"
Alternatively, the abbreviations "CF_CARD:" and "LOCAL_DRIVE:" can be used.
Example
Execute from local drive
The "MAIN.MPF" main program is stored in the NC memory and is selected for execution.
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
201
Flexible NC programming
2.24 Subprogram technique
Subprogram "SP_1"
The external subprogram "SP_1.SPF" or "SP_1.MPF" is on the local drive in the directory "/
user/sinumerik/data/prog/WKS.DIR/WST1.WPD".
The path for the external program directory is set with:
SD42700 $SC_EXT_PROG_PATH = LOCAL_DRIVE:WKS.DIR/WST1.WPD
Note
Specification of the path for calling the external subprogram:
● Without the default setting: "LOCAL_DRIVE:WKS.DIR/WST1.WPD/SP_1"
● With the default setting: "SP_1"
Subprogram "SP_2"
The external subprogram "SP_2.SPF " or "SP_2.MPF " is in the WKS.DIR/WST1.WPD
directory of the USB drive. The default setting of the path to the external program directory is
used for the path of subprogram "SP_1" and is also not rewritten in the main program.
Therefore, the complete path has to be specified when subprogram "SP_2" is called.
Main program "MAIN"
Program code
N010 PROC MAIN
N020 ...
N030 EXTCALL("SP_1")
N030 EXTCALL("USB:WKS.DIR/WST1.WPD/SP_2")
N050 ...
N060 M30
Additional information
EXTCALL call with absolute path name
If the subprogram exists under the specified path, it is executed with the EXTCALL call. If the
subprogram does not exist under the specified path, the program execution is aborted with the
EXTCALL call.
Job Planning
202
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
EXTCALL call with relative path name / without path name
In the event of an EXTCALL call with a relative path name or without a path name, the available
program memories are searched as follows:
1. If a path name is preset in SD42700 $SC_EXT_PROG_PATH, the data specified in the
EXTCALL call (program name or with relative path name) is searched for first, starting from
this path. The absolute path is obtained from linking the following characters:
- Default path specification in SD42700 $SC_EXT_PROG_PATH
- Separator "/"
- Path specification and subprogram name in the EXTCALL command
2. If the subprogram was not found under 1., the directories of the user memory are searched.
The search ends when the subprogram is found for the first time. If the subprogram is not
found, the program execution is aborted with the EXTCALL call.
Adjustable reload memory (FIFO buffer)
A reload memory is required for the execution of an external subprogram. The size of the
reload memory is preset with 30KB and can only be changed by the machine manufacturer
(using MD18360 MM_EXT_PROG_BUFFER_SIZE).
Note
Subprograms with jump commands
For external subprograms that contain jump commands (GOTOF, GOTOB, CASE, FOR, LOOP,
WHILE, REPEAT, IF, ELSE, ENDIF etc.) the jump destinations must lie within the post loading
memory.
Note
ShopMill/ShopTurn programs
The contour descriptions added at the file end mean the ShopMill and ShopTurn programs
must be stored completely in the read-only memory.
A separate reload memory is required for external subprograms executed in parallel.
Reset / end of program / POWER ON
Reset and POWER ON cause external subprogram calls to be interrupted and the associated
load memory to be deleted.
A program selected for "Execution from external source" remains selected for "Execution from
external source" after a reset / end of program. The behavior does not differ from internally
selected programs, assuming that the external program memory is still available.
References
Further information on "Execution from external source" can be found in:
Function Manual, Basic Functions, Mode Group, Channel, Program Operation, Reset Behavior
(K1)
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
203
Flexible NC programming
2.24 Subprogram technique
2.24.3.11
Execute external subprogram (828D) (EXTCALL)
A part program can be loaded from an external memory and executed with the EXTCALL
command.
The following are available as external memory:
● User CF card
● Network drive
● USB drive
Note
As the interface for the execution of an external program located on a USB drive, only the
USB interface of the operator panel front (PPU) may be used.
NOTICE
Tool/workpiece damage when using a USB flash drive
It is recommended that a USB flash drive is not used to execute an external subprogram.
A communication interruption to the USB flash drive while executing the subprogram as
a result of contact problems, drop out, interruption through a knock or accidental
unplugging stops the machining immediately. The tool and/or workpiece could be
damaged.
Default setting of the external program path
The path for the external program directory can be preset with the setting data:
SD42700 $SC_EXT_PROG_PATH
Together with the program path and identifier specified with the EXTCALL call, this forms the
entire path for the subprogram to be called.
Note
If the program path is specified only via the EXTCALL call, then SD42700 must be empty.
Note
Parameters
When an external program is called, no parameters can be transferred to it.
Syntax
EXTCALL("<Path/><Program name>")
Job Planning
204
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
Meaning
EXTCALL:
Command for calling an external subprogram.
"<Path/><Program name>":
Constant/variable of type STRING
<Path/>:
Absolute or relative path specifica-
tion (optional)
<Program name>:
The program name is specified with-
out prefix "_N_".
The file extensions ("MPF", "SPF")
can be attached to program names
using the "_" or "." character (option-
al).
Example:
"SHAFT"
"SHAFT_SPF"
"SHAFT.SPF"
Path specification: Short designations
The following short designations can be used to specify the path:
● User CF card: "CF_CARD:"
● USB drive (operator panel front): "USB:"
Example
The "MAIN.MPF" main program is stored in the NC memory and is selected for execution.
Subprogram "SP_1"
The external subprogram "SP_1.SPF " or "SP_1.MPF " is on the user CF card in the "/WKS.DIR/
WST1.WPD" directory.
The path for the external program directory is set with:
SD42700 $SC_EXT_PROG_PATH = CF_CARD:WKS.DIR/WST1.WPD
Note
Specification of the path for calling the external subprogram:
● Without the default setting: "CF_CARD:WKS.DIR/WST1.WPD/SP_1"
● With the default setting: "SP_1"
Subprogram "SP_2"
The external subprogram "SP_2.SPF " or "SP_2.MPF " is in the WKS.DIR/WST1.WPD
directory of the USB drive. The default setting of the path to the external program directory is
used for the path of subprogram "SP_1" and is also not rewritten in the main program.
Therefore, the complete path has to be specified when subprogram "SP_2" is called.
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
205
Flexible NC programming
2.24 Subprogram technique
Main program "MAIN"
Program code
N010 PROC MAIN
N020 ...
N030 EXTCALL("SP_1")
N030 EXTCALL("USB:WKS.DIR/WST1.WPD/SP_2")
N050 ...
N060 M30
Additional information
EXTCALL call with absolute path name
If the subprogram exists under the specified path, it is executed with the EXTCALL call. If the
subprogram does not exist under the specified path, the program execution is aborted with the
EXTCALL call.
EXTCALL call with relative path name / without path name
In the event of an EXTCALL call with a relative path name or without a path name, the available
program memories are searched as follows:
1. If a path name is preset in SD42700 $SC_EXT_PROG_PATH, the data specified in the
EXTCALL call (program name or with relative path name) is searched for first, starting from
this path. The absolute path is obtained from linking the following characters:
- Default path specification in SD42700 $SC_EXT_PROG_PATH
- Separator "/"
- Path specification and subprogram name in the EXTCALL command
2. If the subprogram was not found under 1., the directories of the user memory are searched.
The search ends when the subprogram is found for the first time. If the subprogram is not
found, the program execution is aborted with the EXTCALL call.
Adjustable reload memory (FIFO buffer)
A reload memory is required for the execution of an external subprogram. The size of the
reload memory is preset (see MD18360 MM_EXT_PROG_BUFFER_SIZE).
Note
Subprograms with jump commands
For external subprograms that contain jump commands (GOTOF, GOTOB, CASE, FOR, LOOP,
WHILE, REPEAT, IF, ELSE, ENDIF etc.) the jump destinations must lie within the post loading
memory.
Job Planning
206
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.24 Subprogram technique
Note
ShopMill/ShopTurn programs
The contour descriptions added at the file end mean the ShopMill and ShopTurn programs
must be stored completely in the read-only memory.
A separate reload memory is required for external subprograms executed in parallel.
Reset / end of program / POWER ON
Reset and POWER ON cause external subprogram calls to be interrupted and the associated
load memory to be deleted.
A program selected for "Execution from external source" remains selected for "Execution from
external source" after a reset / end of program. The behavior does not differ from internally
selected programs, assuming that the external program memory is still available.
References
Further information on "Execution from external source" can be found in:
Function Manual, Basic Functions, Mode Group, Channel, Program Operation, Reset Behavior
(K1)
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
207
Flexible NC programming
2.25 Macro technique (DEFINE ... AS)
2.25
Macro technique (DEFINE ... AS)
NOTICE
Macro technology increases the complexity of the programming
Macros can significantly alter the control's programming language. Macro technology may
only be used with great care.
A macro is a sequence of individual statements which have together been assigned a name
of their own. When a macro is called during a program run, the statements programmed under
the program name are executed one after the other.
According to the range of validity (in other words, the range in which the macro definition is
active), there are the following macro categories:
● Local macros
Local macros are macros that are defined at the beginning of an NC program, which at the
time of execution is not the main program. They are created when the NC program is called,
and deleted with an end of program reset - or the next time that the control system powers
up. Local macros can only be accessed within the NC program in which they are defined.
● Program-global macros
Program-global macros are macros that are defined at the beginning of an NC program,
which is used as a main program. They are created when the NC program is called, and
deleted with an end of program reset - or the next time that the control system powers up.
Program-global macros can be accessed in the main program and in all subprograms.
Note
Availability of program-global macros
Program-global macros defined in the main program are only available in subprograms if
the following machine data is set:
MD11120 $MN_LUD_EXTENDED_SCOPE = 1
If MD11120 = 0, the program-global macros defined in the main program will only be
available in the main program.
● Global macros
Global macros are NC or channel-global macros, which are defined in a definition file
(macro file) - and are retained even after an end of program reset or the next time that the
control system powers up. Global macros can be called in any main program or subprogram
and executed.
Note
In order to use the macros of an external macro file in the NC program, the macro file must
be downloaded to the NC.
Job Planning
208
Programming Manual, 12/2018, A5E40869460B AB
Flexible NC programming
2.25 Macro technique (DEFINE ... AS)
Macros must be defined before they can be used. The following rules must be observed in this
context:
● Any identifier, G, M, H functions and L subprogram names can be defined in a macro.
● The macro can be defined at the beginning of the program or in a dedicated definition file
(macro file).
● Local and program-global macros are defined at the beginning of the program.
● Global macros must be defined in a macro file, e.g._N_DEF_DIR/_N_UMAC_DEF.
● G command macros can only be defined as global macros.
● H and L functions can be programmed with 2 digits.
● M and G commands can be programmed with 3 digits.
Note
Keywords and reserved names may not be overwritten with macros. This also applies to all
jump destinations within a GOTO command, and to the keywords in program loops, such as
FOR, WHILE, LOOP, REPEAT.
Syntax
Macro definition:
DEFINE <Macro_name> AS <Operation_1> <Operation_2> ...
Call in the NC program:
<Macro_name>
Meaning
DEFINE ... AS:
Keyword combination to define a macro
<Macro_name>:
Macro name
Only identifiers are permissible as macro names.
The macro is called from the NC program by the macro name.
<Operation_1>:
First programming instruction in the macro
<Operation_2>:
Second programming instruction in the macro
Examples
Example 1: Macro definition at the beginning of the program
Program code
Comment
DEFINE LINE AS G1 G94 F300
; Macro definition
N70 LINE X10 Y20
; Macro call
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
209
Flexible NC programming
2.25 Macro technique (DEFINE ... AS)
Example 2: Macro definitions in a macro file
Program code
Comment
DEFINE M6 AS L6
; A subprogram is called at tool change to handle
the necessary data transfer. The actual tool change
M function is output in the subprogram (e.g. M106).
DEFINE G81 AS DRILL(81)
; Emulation of the DIN-G command.
DEFINE G33 AS M333 G333
; During thread cutting, synchronization is reques-
ted with the PLC. The original G command G33 was
renamed to G333 by machine data so that the program-
ming remains identical for the user.
Example 3: External macro file
After reading the external macro file into the control, the macro file must be downloaded into
the NC. Only then can macros be used in the NC program.
Program code
Comment
%_N_UMAC_DEF
;$PATH=/_N_DEF_DIR
; Customer-specific macros
DEFINE PI AS 3.14
DEFINE TC1 AS M3 S1000
DEFINE M13 AS M3 M7
; Spindle clockwise, coolant on
DEFINE M14 AS M4 M7
; Spindle counter-clockwise, coolant on
DEFINE M15 AS M5 M9
; Spindle stop, coolant off
DEFINE M6 AS L6
; Call tool change program
DEFINE G80 AS MCALL
; Deselect drilling cycle
M30
Job Planning
210
Programming Manual, 12/2018, A5E40869460B AB
File and Program Management
3
3.1
Program memory
3.1.1
NC program memory
Files and programs (e.g. main programs and subprograms, macro definitions) are saved in
the non-volatile program memory (→ passive file system).
References:
Function Manual, Extended Functions; Memory Configuration (S7)
A number of file types are also stored here temporarily; these can be transferred to the work
memory as required (e.g. for initialization purposes when machining a specific workpiece).
3URJUDP PHPRU\ LQ WKH 1&.
B1B'()B',5
B1B&67B',5
B1B&0$B',5
B1B&86B',5
B1B63)B',5
B1B03)B',5
B1B:.6B',5
B1B&20B',5
B1B60$&B'()
B1B/
B63)
B1B*/2%B63)
B1B03) B03)
B1B00$&B'()
B1B B63)
B1B B63)
B1B029B03)
B1B80$&B'()
B1B B03)
B1B6*8'B'()
B1B
B1B0*8'B'()
B1B8*8'B'()
B1B*8' B'()
B1B*8' B'()
B1B32&.(7 B63)
B1B:(//(B:3'
B1B03)
B:3'
B1B B63)
B1B:(//(B03)
B1B03)
B03)
B1B3$57 B03)
B1B/ B63)
B1B3$57 B63)
B1B B
B1B3$57 B63)
B1B:(//(B,1,
B1B:(//(B6($
B1B3$57 B,1,
B1B3$57 B8)5
%ODFN QDPHV SHUPDQHQWO\ DYDLODEOH
B1B3$57 B&20
*UD\ QDPHV DOORFDWHG E\ WKH XVHU
B1B:(//(
Job Planning
Programming Manual, 12/2018, A5E40869460B AB
211
File and Program Management
3.1 Program memory
Standard directories
The following standard directories are available:
Directory
Content
_N_DEF_DIR
Data modules and macro modules
_N_CST_DIR
Standard cycles
_N_CMA_DIR
Manufacturer cycles
_N_CUS_DIR
User cycles
_N_WKS_DIR
Workpieces
_N_SPF_DIR
Global subprograms
_N_MPF_DIR
Main programs
_N_COM_DIR
Comments
File types
The following file types can be stored in the main memory:
File type
Description
<name>_MPF
Main program
<name>_SPF
Subprogram
<name>_TEA
Machine data
<name>_SEA
Setting data
<name>_TOA
Tool offsets
<name>_UFR
Zero offsets/frames
<name>_INI
Initialization files
<name>_GUD
Global user data
<name>_RPA
R-parameters
<name>_COM
Comment
<name>_DEF
Definitions for global user data and macros
Workpiece main directory (_N_WKS_DIR)
The workpiece main directory exists in the standard setup of the program memory under the
name _N_WKS_DIR. The workpiece main directory contains all the workpiece directories for
the workpieces that you have programmed.
Workpiece directories (..._WPD)
A workpiece directory contains all files required for machining a workpiece. These can be main
programs, subprograms, any initialization programs and comment files.
The first time a part program is started, initialization programs are executed once, depending
on the selected program (in accordance with machine data MD11280 $MN_WPD_INI_MODE).
Job Planning
212
Programming Manual, 12/2018, A5E40869460B AB

 

 

 

 

 

 

 

 

Content      ..     1      2      3      4      ..