Syntec Macro Development Tool Guide
Syntec Macro Development Tool Guide
匯出日期:2022-12-22
修改日期:2022-09-13
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
1 Preface
In order to increase the flexibility of the controller application, Syntec controller provides MACRO program editing
functions. When the processing program is declared in the MACRO format, specific mathematical functions are
applicable like other programming languages. In this way, in addition to the original movement and compensation
command functions, logical judgment and mathematical calculation functions are also included.
Preface – 2
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
2 File Format
The first line of the program should be declared as the title line with "%" and add the keyword "@MACRO".
Otherwise, the file will be regarded as a normal ISO format file, and user is not able to to use the full functionality of
the MACRO. In addition, each line of the program content must be followed by a semicolon ";", but there are
exceptions to some of the syntax, refer to the syntax description.
With or without 1. Except the special syntax, every line should end with semicolon.
semicolon at the end of 2. If the line does not end with semicolon, CNC combine it together with the next
line is acceptable. line when checking the syntax. If there is no alarm, the NC program run
normally; otherwise, there comes the alarm "COM-008," which is "line does not
end with semicolon."
Example:
While using "(...)", the ... While using "(*...*)", the ... is regarded as comment.
is regarded as comment.
Note:
File Format – 3
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
1. It is recommended that multi-path style(including $1 and $2) might not be used in NC Program which is
called as sub-program or a macro.
Should it be inevitable, the size of the program must be less than 60KB(60000bytes). Otherwise, there
comes the alarm COR-203 Illegal NC file format
2. Not support the sub-program, which is in MACRO format, using the multi-path style (including $1, $2).
3. If the size of file is larger than 60KB(60000bytes), it would not support the syntax like IF, CASE, REPEAT, FOR,
WHILE, which are longer than one line. If these syntax are used, there will be alarms.( COR-204 File size too
large )
4. Only ASCII characters are acceptable in NC files. Using non-ASCII characters is thus unacceptable and will
trigger COM-027 Invalid character.
Note: Listed below are the special cases in which non-ASCII characters are considered acceptable:
a. Comment.
b. Arguments of MACRO functions that are of string type.
5. Support CR ("\r")、LF ("\n")、CR LF ( "\r\n" ) line feed.
File Format – 4
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
3 Block Format
The writing format of the block (one line) is instructed as follows:
/ N G X Y Z A B C I J K F S T D M
N The block sequence No., which must be written at the head of a block, and the
MACRO command or variable designation cannot be written in the same line.
X The X axis movement command, or the expansion of the G code, must be written
after the G code.
Y The Y axis movement command, or the expansion of the G code, must be written
after the G code.
Z The Z axis movement command, or the expansion of the G code, must be written
after the G code.
A The A axis movement command, or the expansion of the G code, must be written
after the G code.
B The B axis movement command, or the expansion of the G code, must be written
after the G code.
C The C axis movement command, or the expansion of the G code, must be written
after the G code.
I The radius command in the X direction or the argument of the expansion G code,
must be written after the G code.
J The radius command in the Y direction or the argument of the expansion G code,
must be written after the G code.
K The radius command in the Z direction or the argument of the expansion G code,
must be written after the G code.
Block Format – 5
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Block Format – 6
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
4 Operator
Operator Sign Operating order
Brackets ()[] 1
Negative - 3
Complement NOT 3
Multiplication sign * 4
Divisor / 4
Plus + 5
Minus - 5
Comparison <,>,<=,>= 6
Equal = 7
Boolean “or” OR 11
Note 1:
When using the "/" component (division), be aware that if the numerator and denominator are integers, the result is
still an integer. The difference between an integer and a non-integer result is whether user adds the decimal point
or not.
example:
• The numerator is a non-integer: 1. / 2 = 0.5
• The denominator is a non-integer: 1 / 2.0 = 0.5
• The numerator and denominator are integers: 1/2 = 0
Operator – 7
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Operator – 8
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
5 Language Instructions
5.1 Variable Designation
Variable Designation
Example 1: @1 := 123;
Direct setting #1 := 456;
#10 := "12"; // The local variable #10 content is 12
@10 := "12"; // public variable @10 content is 12849
Remarks 1. The "12" in the first example is a string, indicating that the string is stored in
the variable. When the public variable is stored, the controller will translate the
string into ASCII. For the local variable, the translation will not be executed.
2. To correctly read the contents of the string stored in the public variable, use
the SCANTEXT function.
3. In the example 2, please notice that it's the "square bracket"
5.2 GOTO
GOTO
Syntax GOTO n;
Explanation The use of GOTO should be paired up with block sequence code(n). CNC would
jump to the specified N-number and execute from that line. If there are two same
N-numbers in the program, the first N-line number in the program will take
precedence than the second one.
Language Instructions – 9
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Examples %@MACRO
#1 := 1;
#2 := 10;
IF( #1 = 1 ) THEN
GOTO #2;
END_IF;
IF( #1 = 2 ) THEN
GOTO 100;
END_IF;
N10;
G01 G90 X50. Y0. F1000;
M30;
N100;
G01 G90 X0. Y50. F1000;
M30;
Remarks When using the loop function such as REPEAT/WHILE/FOR/GOTO, user should pay
attention to the problem of infinite loop. When this occurs, the human machine
interface, which is screen, may be locked or the machining program may crash.
It is recommended to add the SLEEP() function avoiding the crash resulting
from the infinite loop. With SLEEP() function, there is still chance to operate the
human-machine interface to stop the program execution.
5.3 CASE
CASE
Language Instructions – 10
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Examples %@MACRO
#1 := 1;
G01 G90 X0. Y0. F1000;
CASE #1 OF
1:
X(1.0*#1) Y(1.0*#1);
2:
X(2.0*#1) Y(2.0*#1);
3, 4, 5:
X(3.0*#1) Y(3.0*#1);
ELSE
X(4.0*#1) Y(4.0*#1);
END_CASE;
M30;
5.4 IF
IF
Language Instructions – 11
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Examples %@MACRO
#1 := 3.0;
G01 G90 X0. Y0. F1000;
IF #1 = 1 THEN
X(1.0*#1) Y(1.0*#1);
ELSEIF #1 = 2 THEN
X(2.0*#1) Y(2.0*#1);
ELSEIF #1 = 3 THEN
X(3.0*#1) Y(3.0*#1);
ELSE
X(4.0*#1) Y(4.0*#1);
END_IF;
M30;
5.5 Repeat
REPEAT
Syntax REPEAT
<statement List>
UNTIL <condition>
END_REPEAT;
Language Instructions – 12
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Examples %@MACRO
#10 := 30.;
#11 := 22.5.;
#12 := #10/2;
#13 := #11/2;
#14 := 2.0;
#15 := 1.5;
G01 G90 X#12 Y#13 F1000;
REPEAT
G00 X(#12+#14) Y(#13+#15);
G01 X(#12+#14) Y(#13-#15);
G01 X(#12-#14) Y(#13-#15);
G01 X(#12-#14) Y(#13+#15);
G01 X(#12+#14) Y(#13+#15);
#14 := #14 + 2.0;
#15 := #15 + 1.5;
UNTIL (#14 > #12) OR (#15 > #13) END_REPEAT;
M30;
Remarks When using the loop function such as REPEAT/WHILE/FOR/GOTO, user should pay
attention to the problem of infinite loop. When this occurs, the human machine
interface, which is screen, may be locked or the machining program may crash.
It is recommended to add the SLEEP() function avoiding the crash resulting
from the infinite loop. With SLEEP() function, there is still chance to operate the
human-machine interface to stop the program execution.
5.6 While
WHILE
Language Instructions – 13
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Examples %@MACRO
#10 := 30.;
#11 := 22.5.;
#12 := #10/2;
#13 := #11/2;
#14 := 2.0;
#15 := 1.5;
G01 G90 X#12 Y#13 F1000;
WHILE (#14 <= #12) AND (#15 <= #13) DO
G00 X(#12+#14) Y(#13+#15);
G01 X(#12+#14) Y(#13-#15);
G01 X(#12-#14) Y(#13-#15);
G01 X(#12-#14) Y(#13+#15);
G01 X(#12+#14) Y(#13+#15);
#14 := #14 + 2.0;
#15 := #15 + 1.5;
END_WHILE;
M30;
Remarks When using the loop function such as REPEAT/WHILE/FOR/GOTO, user should pay
attention to the problem of infinite loop. When this occurs, the human machine
interface, which is screen, may be locked or the machining program may crash.
It is recommended to add the SLEEP() function avoiding the crash resulting
from the infinite loop. With SLEEP() function, there is still chance to operate the
human-machine interface to stop the program execution.
5.7 For
FOR
Language Instructions – 14
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Syntax FOR <variable 1> := <Description 1> TO <Description 2> BY <Description 3> DO
<statement list>
END_FOR;
Variable 1: The variable that controls the number of loops
Description 1: The start number of the loop count, which can be a numerical value or
an arithmetic expression
Description 2: The terminated number of the loop count, which can be a numerical
value or an arithmetic expression.
Description 3: The added number to the current loop count after each loop, which
can be a numerical value or an arithmetic expression.
Statement list: execution in each loop
Examples %@MACRO
#10 := 30.;
#11 := 22.5.;
#12 := #10/2;
#13 := #11/2;
#14 := 2.0;
#15 := 1.5;
G01 G90 X#12 Y#13 F1000;
FOR #6 := 0 TO 3 BY 1.0 DO
G00 X(#12+#14) Y(#13+#15);
G01 X(#12+#14) Y(#13-#15);
G01 X(#12-#14) Y(#13-#15);
G01 X(#12-#14) Y(#13+#15); G01 X(#12+#14) Y(#13+#15);
#14 := #14 + 2.0;
#15 := #15 + 1.5;
END_FOR;
M30;
Language Instructions – 15
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Remarks 1. When using the loop function such as REPEAT/WHILE/FOR/GOTO, user should
pay attention to the problem of infinite loop. When this occurs, the human
machine interface, which is screen, may be locked or the machining program may
crash.
2. It is recommended to add the SLEEP() function avoiding the crash resulting
from the infinite loop. With SLEEP() function, there is still chance to operate the
human-machine interface to stop the program execution.
3. Do NOT use the command whitch will jump out and in FOR loop ( e.g: Complex
Canned Cycle (G72-G78), using GOTO jump out loop and jump in again ), 、M98
H_, it will cause the incorrect added number(<Description 3>).
example:
N12;
M00;
@1:=@1+5;
GOTO 13;
M99;
5.8 EXIT
EXIT
Syntax EXIT
Language Instructions – 16
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Examples %@MACRO
#10 := 30.;
#11 := 22.5.;
#12 := #10/2;
#13 := #11/2;
#14 := 2.0;
#15 := 1.5;
#16 := 1.0;
G01 G90 X#12 Y#13 F1000;
FOR #6 := 0 TO 3 BY 1.0 DO
IF((#14 = 4) & (#16 = 1)) THEN
EXIT;
END_IF;
G00 X(#12+#14) Y(#13+#15);
G01 X(#12+#14) Y(#13-#15);
G01 X(#12-#14) Y(#13-#15);
G01 X(#12-#14) Y(#13+#15);
G01 X(#12+#14) Y(#13+#15);
#14 := #14 + 2.0;
#15 := #15 + 1.5;
END_FOR;
M30;
Ex Program Annotation(comment)
Example 1 %@MACRO
Single line annotation G00 G90 X0. Y0.; // homing
M30;
Language Instructions – 17
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Example 2 %@MACRO
Block annotation (*
This block is the annotation area
Regardless of the content, it does not affect program execution.
*)
G00 G90 X0. Y0.;
G00 G90 X10. Y0.;
G00 G90 X10. Y10.;
G00 G90 X0. Y10.;
G00 G90 X0. Y0.;
M30;
Remark If a text that is an annotation is added to the statement list, system error may occur
due to the limitation while interpreting the code. This misuse is not under the
protection of the controller.
Syntax %
Execution Program
%
Explanation 1. While there is "%...%" in the program, the execution program between
two % will be executed by CNC. For those program prior to the first %
and after the second % will not be executed.
Language Instructions – 18
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Language Instructions – 19
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
A #1 J #5 T #20
B #2 K #6 U #21
C #3 L #12 V #22
D #7 M #13 W #23
E #8 P #16 X #24
F #9 Q #17 Y #25
I #4 S #19 X1 GETARG(X1)
• Modal Variables ( #2001 ~ #2100, #3001 ~ #3100) will return to the VACANT state when the system is reset, so
it can be applied to the timing of data exchange between multiple MACROs to save the use of variable
resources.
• If a default initial value is required for MACRO, Customer Parameter is recommneded(#4001 ~ #4100, #5001
~#5100).
• When the MACRO sub-routine (sub-program) is executed, if the mode G code is changed (G91/G90, G40/G41/
G42, ..., etc.), please back up the current state, and restore the original mode G state before leaving the
MACRO.
• If user want to keep the current MACRO interpolation mode (#1000) after leaving MACRO, it is recommended
to designate #1000 as the MACRO number before leaving MACRO. As long as there is single block of the axial
displacement, the system will automatically call this MACRO without specifying it again.
• The interpolation mode will be automatically rewritten when G00/G01/G02/G03/G31/G33 show up or
#1000 change.
• For length or angle arguments, use the STD function to normalize the unit before operation to match the
usage habits of machine tool.
• Change to the setting of coordinate system is strictly forbidden, such as G92/G54/G52 which are relevant to
coordinate system. Otherwise, the simulation would be useless.
• When machining, the core will pre-interpret the MACRO content, so the MACRO progress is ahead of the
practical G/M code. If the variable specification or the data reading needs to synchronize with the G/M code,
please add WAIT function before the variable specification or the data reading to ensure the movement is
correct.
Note: The WAIT function is used to prevent errors occur from the premature data reading or writing, which is
done by the pre-interpretation process, before the associated motion commands have been done by the
controller. Thus, the WAIT function only guarantees that the pre-interpretation process won't take place
until the previous G/M codes have already been done ( M98, M99, and M198 are the exceptions ), it is
ineffective against other commands.
• The MACRO program must be added with "M99;" to return to the main program (parent program).
• Develop good habits, add more comments to the program, this will increase program readability, and help
subsequent maintenance and troubleshooting.
0 none none
-1 G00 G0000
1 G01 G0001
2 G02 G0002
3 G03 G0003
4 G53 G0053
5 G40 G0040
6 G41 G0041
7 G42 G0042
8 G43 G0043
9 G44 G0044
10 G49 G0049
11 G04 G0004
• The following are the operating specifications for the G code macro
• Macro feature is treated as G code macro feature
• All G codes in the registered G code macro will be executed as the standard G codes.
• Inheritance property of interpolation G codes such as G00, G01, G02, G03 still persists after these
codes are registered as customized G codes.
• Example:
G00 X100.
Y100.
Where Y100. will also execute the G00 macro, and can read the occupied Y argument.
• If the user changes the interpolation mode in the customized G code macro, the interpolation
mode ( #1000 ) should be restored before leaving the customized G code macro.
• For example, the user sets G00 as the registered G code macro.
In the macro G0000, if the user changes the interpolation mode to G01, the user needs to
restore the interpolation mode to G00, #1000 should be 0 before leaving G0000, in order to
avoid the state disorder.
• The login G code macro will not work when it encounters the following instructions.
• Lathe G7.1
• Lathe G12.1
• Lathe, A
• Lathe, R
• Lathe, C
• Lathe All machining cycle instructions
• Mill All machining cycle instructions
• T code macro
• Version revision
Version Revision
8 Function List
Function Explanation
ATAN Calculate the atan of a value. The calculation result is between ±90°.
Example:
#10 := 1;
#1 := ATAN(#10); // #1 = 45
#2 := ATAN(-1); // #2 = -45
Function List – 24
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
ATAN2(Y, X) Calculate the four-quadrant atan value of Y/X. The calculation result is between
±180°.
Example:
#10 := 1;
#20 := -1
#1 := ATAN2(#10, #20); // #1 = 135
#2 := ATAN2(#20, #10); // #2 = -45
#3 := ATAN2(1, 0); // #3 = 90
Notes:
1. Valid version: 10.118.29W, 10.118.40C, 10.118.42
2. The argument X and Y must be numbers, or the alarm COR-023【Semantic
error】will be issued.
3. The argument X and Y can not be zero at the same time, or the alarm
COR-004【Operation domain error】will be issued.
Example of wrong cases:
@1 := ATAN2( "1", 1 ); // The first argument is not a number, issue COR-023
alarm.
@2 := ATAN2( 0, 0 ); // The arguments are both zero, issue COR-004
alarm.
AXID Inquire the axis number corresponding to the axis name. If the axis name does
not exist, the return value is blank (VACANT, #0)
Example:
Suppose the sixth axis name is Y2 (Pr326=202) and the second axis name
is Y (Pr322=200).
#1 := AXID(Y); // #1 = 2
#2 := AXID(Y2); // #2 = 6
CEIL Return the smallest integer greater than or equal to a certain value
Example:
#10 := 1.4;
#1 := CEIL(#10); // #1 = 2
#2 := CEIL(1.5); // #2 = 2
CLOSE Close the file opened by the OPEN function, and the file will be automatically
closed after the program ends. The PRINT function will fail if the file is already
closed.
Example:
CLOSE(); // close the file
Function List – 25
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
Function List – 26
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
0 Fail to open the target file. Please check if the target file
is in the assigned path.
Notes:
1. Wrong type of argument will trigger COR-023 Semantic error.
2. This MACRO syntax is not supported in graphic simulation. The return value
will be 0.
3. The assigned path will be modified be Customized Action
CUSTOMFILE_CYCLE1~5). Please refer to HMI Customization Manual.
4. There are only one cycle file can be opened at the same time. Both DBOPEN
and DBNEW can open cycle file.
If these MACRO syntec are called in sequence, the file will be specified
according to the last MACRO syntax.
Ex: Use DBOPEN("FileA"), then use DBNEW("FileB") in sequence. The "FileB"
will be the target file for following XMLDB MACROs.
5. If it is need to reload the file, please reset the system( when using BGnd
Running Component please execute BGnd Stop ) before execute DBOPEN
again.
EX:
1 // 1.
2 DBOPEN("Test.cyc");
3 // Load GNCFILES\\Test.cyc data file
4
5 // 2.
6 #1 := 51;
7 DBOPEN("FLAT\\\\AB#1[3]ZZ.cyc" );
Function List – 27
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
Function List – 28
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
1 Load successfully.
Notes:
1. Wrong type of argument will trigger COR-023 Semantic error.
2. This MACRO syntax is not supported in graphic simulation. The return value
will be 0.
3. This MACRO syntax will operate the opened cycle file. The cycle file can be
opened through DBOPEN and DBNEW.
4. There are only one cycle name can be specified at the same time. Both
DBLOAD and DBINSERT can specify cycle name.
If these MACRO syntec are called in sequence, the cycle name will be
specified according to the last MACRO syntax.
Ex: Use DBLOAD(0), then use DBINSERT("0,"Cyc1") in sequence. The
operation data format will be specified to "Cyc1".
Ex:
1 DBOPEN("FLAT\\TAB01");
2 // Load FLAT\\TAB01 data file
3 DBLOAD( 0 );
4 // read the 0th cycle
5 DBLOAD( 1 );
6 // read the 1st cycle
Function List – 29
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
1 Save successfully.
Notes:
1. Wrong type of argument will trigger COR-023 Semantic error.
2. This MACRO syntax is not supported in graphic simulation. The return value
will be 0.
3. This MACRO syntax will operate the opened cycle file. The cycle file can be
opened through DBOPEN and DBNEW.
4. This MACRO syntax will use spcified operation data format ( cycle name ) to
overwrite data.
The the operation data format ( cycle name ) can be specified by DBLOAD
and DBINSERT.
5. Version: This MACRO is supported in 10.118.39 and later versions.
EX:
Function List – 30
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
-2 Fail to create file. The file name Please confirm the "File
is already exist in the assigned name" is not exist in the
path. assigned path.
Notes:
1. Wrong type of argument will trigger COR-023 Semantic error.
2. This MACRO syntax is not supported in graphic simulation. The return value
will be 0.
3. The assigned path will be modified be Customized Action
CUSTOMFILE_CYCLE1~5). Please refer to HMI Customization Manual.
4. This MACRO syntax only create empty file. DBLOAD and DBSAVE can not be
used directly after DBNEW.
5. There are only one cycle file can be opened at the same time. Both DBOPEN
and DBNEW can open cycle file.
If these MACRO syntec are called in sequence, the file will be specified
according to the last MACRO syntax.
Ex: Use DBOPEN("FileA"), then use DBNEW("FileB") in sequence. The "FileB"
will be the target file for following XMLDB MACROs.
6. Version: This MACRO is supported in 10.118.56L, 10.118.60F, 10.118.66 and
later versions.
Ex:
Function List – 31
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
Function List – 32
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
Notes:
1. Wrong type of argument will trigger COR-023 Semantic error.
Function List – 33
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
2. This MACRO syntax is not supported in graphic simulation. The return value
will be 0.
3. This MACRO syntax will operate the opened cycle file. The cycle file can be
opened through DBOPEN and DBNEW.
4. There are only one cycle name can be specified at the same time. Both
DBLOAD and DBINSERT can specify cycle name.
If these MACRO syntec are called in sequence, the cycle name will be
specified according to the last MACRO syntax.
Ex: Use DBLOAD(0), then use DBINSERT("0,"Cyc1") in sequence. The
operation data format will be assigned to "Cyc1".
5. Version: This MACRO is supported in 10.118.56L, 10.118.60F, 10.118.66 and
later versions.
Ex:
Function List – 34
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
Notes:
1. Wrong type of argument will trigger COR-023 Semantic error.
2. This MACRO syntax is not supported in graphic simulation. The return value
will be 0.
3. This MACRO syntax will operate the opened cycle file. The cycle file can be
opened through DBOPEN and DBNEW.
4. Version: This MACRO is supported in 10.118.56L, 10.118.60F, 10.118.66 and
later versions.
Ex:
Function List – 35
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
3 DBDELETE(#30 -
1); // delete the last data
DRAWHOLE Draw a circle based on the tool radius and the color defined by the SETDRAW
function at the current position (only valid in the simulation, system will not add
a circle in the actual path)
EXP Calculate the exponential value with natural number as the base
Example:
#1:=EXP(1); // e^1 = 2.71828
Valid version: 10.116.16
FLOOR Return the largest integer less than or equal to a certain value
Example:
#10 := 1.4;
#1 := FLOOR(#10); // #1 = 1
#2 := FLOOR(1.5); // #2 = 1
Function List – 36
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
GETTRAPARG Read the argument content in Trap Block. Trap Block is the blocks between G66/
G66.1 and G67.
Example:
Assume that the main program content of O0001 is
G66 P100 X100. Y100. // P100 means call sub-program O0100.
G01 X20. // O0100 sub-program uses GETTRAPARG to read the argument
content
#1 := GETARG(X);
// Save the X argument 100. to #1
#2 := GETTRAPARG(X);
// Save the X argument in the Trap block, 20. to #2
Please refer to G66/G67:Call Modal Macro.
Function List – 37
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
MSG Customize the message, please refer to the "MACRO Customized Message" for
details.
Example:
MSG(100); // message ID
MSG("bit lost"); // display message content
MSG(100, "bit lost"); // hint ID + displaye message content
Remark: There is limit of string length in a message. For Mandarin, it's 19
words;For English, it's 39 alphabets.
Function List – 38
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
OPEN ("file name") or Open a text file name of which user specify, which is in the NcFiles folder ( Folder
path please refer the Pr3219 ). The PRINT function is valid only after the file is
OPEN ("file name", "writing
opened.
mode")
If the file name is "COM", it means that the port RS232/RS485 is turned on, and
its setting is determined by Pr3905.
Example:
OPEN("COM"); // Open port RS232
PRINT("\\p"); // Output '%' character
FOR #1 = 1 TO 5000 DO
#30 := #1 * 10.;
PRINT("G01 X#30"); // Output G01 X10.0
END_FOR;
PRINT("\\p"); // Output '%' character
CLOSE(); // Close port
The "writing mode" determines, when the file is opened, whether the original
file content is retained or cleared. (valid version: 10.116.36I)
(i) "a": Keep the original text and the text newly-output follows the original one.
Example:
OPEN("PROBE.NC", "a");
// Open PROBE.NC and keep the text, and be ready for text output
(ii) "w"/nothing: Clear the original text and output the new text in the file.
Example:
OPEN("PROBE.NC");
// Open PROBE.NC and clear the text, and be ready for text output
OPEN("PROBE.NC", "w");
// Open PROBE.NC and clear the text, and be ready for text output
(iii) Wrong writing mode: system issues alarm, COR-301 OPEN command format
error.
Example:
OPEN("PROBE.NC", "abc");
// Wrong writing mode, issues alarm, COR-301, so PROBE.NC is not
opened for text output.
(iv) Convert # or @ variable into a string, and the decimal digits is determined by
Pr17 (valid version: 10.118.12C)
Function List – 39
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
(v) Convert # or @ variable into a string with [*] in the end, and the decimal digits
is determined by this variable.
POP Taking the data in STACK from top layer to bottom layer in sequence. User must
pay attention to the total data in the stack. If there are 5 data, the maximum
times to use POP is 5.
Example:
PUSH(5); // Insert the number 5 into the stack
#1 := POP(); // Remove the topmost value in the stack (#1 = 5)
Function List – 40
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
PRINT This function is used to output a string, and the variable in the output string will
be replaced by the content of it.
The character "\" is an escape character, and the related special characters are
defined as follows:
\\ indicates \ character
\@ indicates @ character
\# indicates # character
\p indicates % character
\" indicates " character
Convert # or @ variable into a string, and the decimal digits is determined by
Pr17 (valid version: 10.118.12C)
Convert # or @ variable into a string with [*] in the end, and the decimal digits is
determined by this variable.
Example:
Assume that Pr17=2 in metric unit
@53 = 20 ;
#3 = 23.1234 ;
PRINT("G01 X#3 Y@53 Z20.0") ;
The output is G01 X23.123 Y20 Z20.0 ; // Display to thousandths place
Example:
@53 = 20 ;
#3 = 23.1234 ;
PRINT("G01 X#3[2] Y@53 Z20.0") ; // #3[2] means display to hundredths
place
The output is G01 X23.12 Y20 Z20.0 ; // Display to hundredths place
PUSH Stuff data into the STACK, the data PUSH into the controller first will be stacked
on the bottom layer, and the last data on the top one.
Example:
PUSH(#1); // Put variable #1 into the STACK
Function List – 41
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
READDI The value of variable derives from the I/O point number in the parentheses
READDI/READDO.
(I point number)
Example:
READDO
@52 := READDI(31); // Read the value of I31 and put it in @52
(O point number)
#88 := READDO(11); // Read the value of O11 and put it in #88
G90 G10 L1000 P4000 R READDI(15); // Read the value of I15 and put it in
R4000
Notes:
1. Valid version: 10.116.23
2. The I/O point is read during pre-interpreting, but it is processed when
READDI / READDO is executed in order to avoid the error resulting from pre-
interpreting I/O point. Because system await until READDI / READDO is
executed, machine will decelerate to zero.
3. The range of I/O point number is 0~511. If the number is out of the range,
system issues alarm, COR-138 Read/write command format error at the I/O/
A point.
READABIT The value of variable derives from the A point number in the parentheses of
READBIT.
(A point number)
Example:
@52 := READABIT(31); // Read the value of A31 and put it in @52
#88 := READABIT(11); // Read the value of A11 and put it in #88
Notes:
1. Valid version: 10.116.44
2. The A point is read during pre-interpreting, but it is processed when
READBIT is executed in order to avoid the error resulting from pre-
interpreting A point. Because system await until READBIT is executed,
machine will decelerate to zero.
3. The range of A point number is 0~511. If the number is out of the range,
system issues alarm, COR-138 Read/write command format error at the I/O/
A point.
Function List – 42
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
READRREGBIT The value of variable derives from the register number and specified bit in the
parenthesis of the READRREGBIT.
(Register number, specified
Bit) Example:
@52 := READRREGBIT(31,3); // Read the value of the third bit of R31 and
put it in @52
Notes:
1. Valid version: 10.116.39
2. The register is read during pre-interpreting, but it is processed when
READRREGBIT is executed in order to avoid the error resulting from pre-
interpreting Register. Because system await until READBIT is executed,
machine will decelerate to zero.
3. If register is less than 0 or greater than 65535, the system issues alarm,
COR-135 Read/write command format error for R value.
4. If register is an incorrect character, system issues alarms, COR-5 Program
loading failure and COM-8 absent statement ending character ';'.
5. If specified bit is less than 0 or greater than 31, system issues alarm,
COR-135 Read/write command format error for R value.
6. If specified bit or both of register and specified bit is incorrect characters,
system issues alarm, COR-5 Program loading failure and COM-9 wrong
assignment character ':='.
Function List – 43
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
SCANTEXT This function is used to read the contents of the string stored in global variable.
When the string is stored in global variable, the controller translate it into ASCII
first and save. User get wrong string if they output the value directly. To get the
correct string, please make good use of this function.
Example:
%@MACRO
@1:="12"; // 16 carry HEX=3231, 10 carry DEC=12849
#1:=SCANTEXT(1);
OPEN("NC");
PRINT("@1");
PRINT("#1");
CLOSE();
M30;
The result is @1 = 12849
#1 = 12
SETDO Determine O point number and the state (1: On, 0: Off) with 2 numbers in the
parenthesis of SETDO.
(O point number,
Example:
O point on or off)
SETDO(3, 1); // Set O3 on
SETDO(8, 0); // Set O8 off
Notes:
1. Valid version: 10.116.23
2. The writing of point O is in the interpolation stage, so it is not necessary to
decelerate to 0 during execution. However, in the MACRO processing in pre-
interpreting stage, the developer should decide whether to use WAIT, which
makes machine decelerate to 0.
3. Mixed use of PLC and SETDO should be avoided. For example, O1 is on by
SETDO in MACRO, but off in PLC. Even though the previous order is
overridden by the next one, it is common to confuse while using both, so it is
recommended that use one of them at a time.
4. The range of O point number is limited to 0~511. If the range is wrong, the
system issues alarm, COR-138 Read/write command format error at the I/O/
A point.
Function List – 44
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
SETABIT Determine A point number and the state (1: On, 0: Off) with 2 numbers in the
parenthesis of SETDO.
(point A, point A on or off)
Example:
SETABIT(3, 1); // Set A3 on
SETABIT(8, 0); // Set A8 off
Notes:
1. Valid version: 10.116.44
2. The writing of point A is in the interpolation stage, so it is not necessary to
decelerate to 0 during execution. However, in the MACRO processing in pre-
interpreting stage, the developer should decide whether to use WAIT, which
makes machine decelerate to 0.
3. Mixed use of PLC and SETABIT should be avoided. For example, A1 is on by
SETABIT in MACRO, but off in PLC. Even though the previous order is
overridden by the next one, it is common to confuse while using both, so it is
recommended that use one of them at a time.
4. The range of A point number is limited to 0~511. If the range is wrong, the
system issues alarm, COR-138 Read/write command format error at the I/O/
A point.
SETRREGBIT Determine Register number, Bit number, and the state (1: On, 0: Off) with the 3
digits in the parenthesis of SETRREGBIT.
(Register number, Bit
number, on or off) Example:
SETRREGBIT(50,3,1); // Set the third R50 Bit on
SETRREGBIT(50,4,0); // Set the fourth R50 Bit off
Notes:
1. Valid version: 10.116.39
2. The writing of Register is in the interpolation stage, so it is not necessary to
decelerate to 0 during execution. However, in the MACRO processing in pre-
interpreting stage, the developer should decide whether to use WAIT, which
makes machine decelerate to 0.
3. Mixed use of PLC and SETRREGBIT should be avoided. For example, first Bit
of R50 is on by SETRREGBIT in MACRO, but is off in PLC off. Even though the
previous order is overridden by the next one, it is common to confuse while
using both, so it is recommended that use one of them at a time.
4. If Register number is less than 0 or greater than 65535, the system issue
alarm, COR-135 Read/write command format error for R value.
5. If Bit number is less than 0 or greater than 31, system issues alarm,
COR-135 Read/write command format error for R value.
6. If the state is not 0 (off) or 1 (on), system issues alarm, COR-135 Read/write
command format error for R value.
7. If any argument is incorrect character, system issues alarms, COR-5 Program
loading failure and COM-3 Syntax error.
Function List – 45
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
0 0 8 8421504
1 8388608 9 16711680
2 32768 10 65280
3 8421376 11 16776960
4 128 12 255
5 8388736 13 16711935
6 32896 14 65535
7 12632256 15 16777215
Note:
• BGR code is the same as RGB code, but with different endianness for B(Blue)
and R(Red) value.
e.g.
Red color in RGB code is 0xFF0000. Converting it into BGR code will be 0x0000FF
= 255. (as described in color code 12)
• SETDRAW sets path color and filled color at the same time. If user would like
to make path color and filled color different, remember to change the path
color with SETDRAW after DRAWHOLE is executed.
Function List – 46
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
e.g.
%@MACRO
#3:=SETDRAW(#1,#2,#18);
// #3 records the original path color, #2 defines the filled color, #18
defines the circle radius
DRAWHOLE();
SETDRAW(#3);
// Change the path color after drawing the circle
M99;
SIGN Return the sign of a value, the negative number is -1, the positive number is 1,
and 0 is 0.
Example:
#10 := 4;
#1 := SIGN(#10); // #1 = 1
#2 := SIGN(-4); // #2 = -1
#3 := SIGN(0); // #3 = 0
SLEEP Temporarily abandon the execution right of this macro loop, generally used in
conjunction with the loop (FOR, WHILE..., etc.) to avoid entering the infinite loop,
which causes the human-machine to crash.
Example:
SLEEP();
Function List – 47
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
STD (argument1, argument According to Pr17, the value is converted into the input unit (Input Unit, IU) set
2) by the system at that time.
1. The argument 1 is the value the unit of which is about to be changed.
2. The argument 2 is a standard unit. Generally, it is #1600, and value of #1600
is from Pr17.
Metric Unit:
Example 1:
When Pr17=2, #1600 corresponds to LIU = 0.001mm
#9 := 100;
#10 := STD(#9,#1600); // #9 is 100 BLU, so #10 is 0.1mm (100*0.001)
Example 2:
When Pr17=3, #1600 corresponds to LIU = 0.0001mm
#9 := 100;
#10 := STD(#9,#1600); // #9 is 100 BLU, so #10 is 0.01mm (100*0.0001)
Imperial:
Example 3:
When Pr17=2, #1600 corresponds to LIU = 0.0001inch
#9 := 100;
#10 := STD(#9,#1600); // #9 is 100 BLU, so #10 is 0.01inch (100*0.0001)
STDAX (argument 1, Converts the value to the standard unit of the corresponding axis.
argument 2)
The argument 1 is a variable, and the argument 2 is the name of the
corresponding axis.
Example:
#24 := STDAX(#24,X);
#3 := STDAX(#3,A);
Function List – 48
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
WAIT The system stops pre-interpreting until the instruction before WAIT is finished.
Example:
%@MACRO
@50 := 1; // @50 equals to 1
G90 G01 X100. F1000; // Assume to system is Reset at this time
WAIT();
@50 := 0; // @50 equals to 0
M30;
Assume that the system is reset when G01 is in execution. Since the block
before WAIT is not finished, @50 equals to 1 after Reset.
Function List – 49
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
CHKMN ("machinery code") Check machinery code. 1: consistent, 0: does not match
Example:
%@MACRO
#51 := CHKMN("5566"); //The value of #51 is the checking result .
IF #51=0 THEN
ALARM(501, "The manufacturer code is invalid."); //If machinery
code does not match, system issues an alarm
END_IF;
Target version: 10.116.6A
CHKSN ("Serial No.") Check Serial Number. 1: consistent, 0: does not match
Example:
%@MACRO
#52 := CHKSN("M9A0001"); //The value of #52 is the checking result
IF #52=0 THEN
ALARM(502, "The serial number is invalid."); //If the serial
number does not match, system issues the alarm
END_IF;
Target version: 10.116.6A
CHKMT ("Machine Type") Check machine type. 1: consistent, 0: does not match
Example:
%@MACRO
#53 := CHKMT("MILL"); //The value of #53 is the check result
IF #53=0 THEN
ALARM(503, "The machine type is invalid."); //If machine type does
not match, system issues the alarm
END_IF ;
Target version: 10.116.6A
Function List – 50
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
CHKMI ("Model") Check the controller model, 1: consistent, 0: does not match
For SUPER series, please input 'S'. For other models, please input value
according to the actual model. For example, 10B =>10B, 11A, => 11A.
Example:
%@MACRO
#54 := CHKMI("S"); //#54 is the checking result
IF #54=0 THEN
ALARM(504, "The hardware type is invalid."); //If the model does not
match, system issues the alarm
END_IF;
Target version: 10.116.6A
Function List – 51
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
CHKINF( category number, Check if the code corresponds to the category number. 1: consistent, 0: does not
"code") match
The range of category numbers is 1~5, each corresponding code is:
1. Machinery code
2. Serial No.
3. Machine Type
4. Model
5. Industrial machine ID
For SUPER series, please input 's'. For other models, please input value
according to the actual model. For example, 10B =>10B, 11A, => 11A.
Example:
%@MACRO
#51 := CHKINF(1, "5566"); // #51 is the checking result
IF #51=0 THEN // If the machineny code does not match, system issues an
alarm
ALARM(501, "The manufacturer code is invalid.");
END_IF;
#52 := CHKINF(2, "M9A0001"); // #52 is the checking result
IF #52=0 THEN // If the serial No. does not match, system issues the alarm
ALARM(502, "The serial number is invalid.");
END_IF;
#53 := CHKINF(3, "MILL"); // #53 is the checking[ result
IF #53=0 THEN // If the machine type does not match, system issue the
alarm
ALARM(503, "The machine type is invalid.");
END_IF;
#54 := CHKINF(4, "S"); // #54 is the checking result
IF #54=0 THEN // If the model does not match, system issues
the alarm
ALARM(504, "The hardware type is invalid.");
END_IF;
#55 := CHKINF(5, "10"); // #55 is the checking result
IF #55=0 THEN // If the Industrial machine ID does not match, system
issues the alarm
ALARM(505, "The industrial machine ID is invalid.");
END_IF;
If argument is incorrect, or the category number is out of the range, system
issues the alarm, COR-353 【Invalid argument of CHKINF】
Example:
Function List – 52
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
%@MACRO
#51 := CHKINF(60, "Mill"); // category number is out of range
#51 := CHKINF("2", "Mill"); // argument 1 is incorrect
#53 := CHKINF(5, 12345); // argument 2 is incorrect
Target version: 10.118.22M、10.118.28B、10.118.30
Function List – 53
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
Function List – 54
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
e.g:
// assume want to get
// speed command( Pn-D26 ) of first axis ( station_number=1000 )
// Enc Internal Temperature( Pn-D61 ) of first spindle
( station_number=1003 )
WAIT(); // To get newest value, block Pre-Interpretation
#1 := DRVDATA(1000, 3366); // speed command of first axis ( Pn-D26,D26
convert to decimal format is 3366 )
#2 := DRVDATA(1003, "D61h"); // Enc Internal Temperature of first
spindle( Pn-D61,D61 convert to hexadecimal format is "D61h" )
OPEN("DbgData.txt", "a"); // open file DbgData.txt
PRINT("Pn-D26: #1, Pn-D26: #2"); // print value
CLOSE(); // close file
The file DbgData.txt content may be below.
Pn-D26: 150, Pn-D26: 430
Note:
1. Valid version: 10.118.23U, 10.118.28.I, 10.118.34.
2. For getting newest value, it is recommended to use WAIT() function blocking
the pre-interpretation before using DRVDATA().
3. The execution time of each function is 0.1~0.2s.
4. First argument must be integer, system will issues the alarm COR-023
【Semantic error】.
5. If second argument is string type, must be hexadecimal format ("xxxh",
x=0~F), system will issues the alarm COR-023【Semantic error】.
6. second argument must be string or integer value, system will issues the
alarm COM-003【Syntax error】.
7. If either the drive or the controller does not support the specified status
variable, the system will issue the alarm COR-016【Illegal variable
access】.
8. Visit the "Controllor Axis Info." page to check status variable accessibility.
Only those shown are accessibile.
9. If the controller supports specified status variable and the drive does not
support, 0 will be returned.
10. If no drive corresponding to station number or using non Syntec M3 drive,
return VACANT.
Function List – 55
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Function Explanation
11. Since it will take some time to read the status variable after system be
powered on, it is recommended to call this function one minute after
powering on, or it might cause system issue the alarm COR-016【Illegal
variable access】due to the variable are not read finish.
Example of wrong case:
// alarm COM-3
DRVDATA( 1003, D61h ); // second argument must be string or integer
value
// alarm COR-023
DRVDATA( "1003", 3425 ); // first argument must be integer
DRVDATA( 1003, "G21h" ); // if second argument is string type, must be
hexadecimal format ("xxxh", x=0~F)
DRVDATA( 1003, "3425" ); // if second argument is string type, must be
hexadecimal format ("xxxh", x=0~F)
DRVDATA( 1003, "0D61h" ); // if second argument is string type, must be
hexadecimal format ("xxxh", x=0~F)
// alarm COR-016
DRVDATA( 1003, "DFFh" ); // drive is not suupot this status No.
// return VACANT
DRVDATA( 9999, "D61h" ); // no drive corresponding to station number
DRVDATA( 9999, "DFFh" ); // if no drive corresponding to station number,
will not check the status variables No.
Function List – 56
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
9 Call sub-Program
9.1 Calling Methods
Syntax Explanation Calling Local Variable Example
Type
M98 P_ H_ Call sub-program Sub- Inherit the local variables #1~#400 M98 P10 L2;
L_ program from main/parent program
P_Sub-program Explanation:
Name
Call O0010 twice
H_Starting of block
sequence No.
L_Repeated
Counts
M198 P_ H_ Call sub-program Sub- Inherit the local variables #1~#400 M198 P10 L2;
L_ program from main/parent program
P_Sub-program Explanation:
( If M198 is Name
Call O0010 twice
not logged
H_Starting of
in Pr3601~)
block sequence
No.
L_Repeated
Counts
G65 P_L_ Call Single Macro Macro Create new local variables G65 P10 Lw X10.0
#1~#400, and #1~#26 records the Y10.0
P_Subroutine
corresponding argument in the
Name Explanation:
calling block
L_Repeated Call O0010 twice, and
Counts input argument
Call sub-Program – 57
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
G66 P_L_ Use movement Mode Create an independent section of G66 P10 X10.0 Y10.0;
instruction to call Macro #1~#400 each time G66 is called.
X20.
mode macro Local variables in this section will
be shared until executing G67. Y20.
P_Subroutine
After executing G67, local variables
Name Explanation:
in this section will be retrieved and
L_Repeated cleared. Moving instructions
Counts X20. and Y20. call
Note:
O0010, and input
The local variables in the section arguments X10.0,
are shared with sub-program Y10.0.
called by P argument (G66 P) only.
They are different from the local
variables in the program where
G66/G66.1 is called.
G66.1 P_ L_ Each block calls Mode The same as G66. G66.1 P10 X10.0
mode macro Macro
X20.
P_Sub-program
G04 X2.
Name
M30
L_Repeated
Counts Explanation:
Each block calls
O0010 and input
argument X10.0.
G_L_ Call expansion G Macro Create a new section of local G128 L3 X1.0
Code. variables #1~#400 each calling,
Explanation:
and restore local variables in main
L_Repeated
program when the Macro is Call G0128 three
Counts
finished. times.
Call sub-Program – 58
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Notes:
• If L argument above isn’t assigned, the default value is 1.
• The life cycle of local vaiables (#1~#400) in above form, please refer to Macro Variable Specification.
Example of Variable Life Cycle:
Call sub-Program – 59
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Call sub-Program – 60
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
10 Variable Specification
• For the explanation of # and @ variable, please refer to Macro Variable Specification.
• Perform four arithmetic operations on variables of different types(Long and Double), it would be forced to
convert to Double and then do the calculation. For example
Variable Specification – 61
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
13 Appendix
13.1 Macro User Guide
13.1.1 Preface
• The built-in G, T, M code may not satisfy demand from all walks of life, so Syntec Corp. provides
"customizing macro" for customer.
Developer is able to, according to the machine properties, develop macros with special actions, which
greatly promotes the machine value.
• Before introduction, the methods of calling other programs in main program are as below:
• Call sub-program: execute sub-program, while reading or occupying argument is forbidden.
• Call macro: execute macro, while reading and occupying argument is allowed.
• For argument definition please refer to Argument Explanation.
• The following sections introduces related specification of macro, and the specification of calling sub-
program will be skipped.
Appendix – 65
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
G200.010
G200.100 G200100
Appendix – 66
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Appendix – 67
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Appendix – 68
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T Effe
y ct
p
e
G Call
6 assi
6 gne
. d
1 pro
gra
m
thro
ugh
mac
ro
whe
n ev
ery
bloc
k is
finis
hed
.
● Must
be the last
G code in
that row.
Appendix – 69
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T Call T1000 Pr3215 Enable T • File name can only be T0000, other file names are not T0000
Co file through code call mode allowed.
de macro. must be 2. • No file extension.
Ma
cr Pr Type
o 3
2
1
5
0 • T
cod
e
sup
ple
men
tary
cod
e
• doe
s
not
call
T00
00
1 • Call
T00
00
thro
ugh
sub-
pro
gra
m.
• Doe
s
not
read
and
occ
upy
any
argu
men
t
Appendix – 70
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Pr Type
3
2
1
5
2 • Call
T00
00
thro
ugh
mac
ro.
• Rea
d
and
occ
upy
any
argu
men
t
M Different • M code must • The beginning of file name must be letter M. • M00
co from M be logged in • No file extension. 00~
de code, M Pr3601~3610 • The file name must be "M+4 digit number". The 4 digit M99
Ma code macro "M code number corresponds to M code macro instruction. 99
cr calls MACRO call • Example • If
o correspondi registry". the
ng M code • Following M File Name Pr 3601 Calling Instruction nu
macro file code is mb
through standard M er is
macro. code and M0123 123 • M123 out
can’t be • M0123 of
logged as M the
code macro. ran
ge,
M M M file
00 30 98 is
not
gua
M M M ran
01 96 99 tee
d to
M M wor
02 97 k
nor
mal
ly.
Appendix – 71
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Example_Main
1 // Main
2 G90;
3 G01 X10. F100.; // X Axis moving by G01 result X=10.
4 G200; // X Axis moving by G200 result X=20.
5 X-20.; // X Axis moving by G01 result X=-20.
6 M30;
Example_G0200
1 // G0200
2 %@MACRO
3 #101 := #1000; // Backup #1000, G00/G01/G02/G03/G33/G34/G35
4 #102 := #1004; // Backup #1004, G90/G91
5 G91 G00 X10.; // X coordinate increase in increment of 10 by
G00. result X=20.;
6 G#101; // Restore #1000, G00/G01/G02/G03/G33/G34/G35
7 G#102; // Restore #1004, G90/G91
8 M99; // Return to main program
Appendix – 72
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
• Example:
• In main program, system executes G201 to cut a 10*10 cm square.
• In main program, system executes G201 to cut a 20*20 cm square.
• In main program, system executes G202 to cut a square, length of edge of which is decided by
argument.
Example_Main
1 // Example002_Main
2 G90 G00 X0. Y0.;
3 G200;
4 G201;
5 G202 X30.;
6 M30;
Example_G0200
1 // G0200
2 %@MACRO
3 #101:=#1000;
4 #102:=#1004;
5 G91 G01 X10.;
6 G91 G01 Y10.;
7 G91 G01 X-10.;
8 G91 G01 Y-10.;
9 G#101;
10 G#102;
11 M99;
Example_G0201
1 // G0201
2 %@MACRO
3 #101:=#1000;
4 #102:=#1004;
5 G91 G01 X20.;
6 G91 G01 Y20.;
7 G91 G01 X-20.;
8 G91 G01 Y-20.;
9 G#101;
10 G#102;
11 M99;
Appendix – 73
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Example_G0202
1 // G0202
2 %@MACRO
3 #101:=#1000;
4 #102:=#1004;
5 #103:=#24;
6 G91 G01 X#103;
7 G91 G01 Y#103;
8 G91 G01 X-#103;
9 G91 G01 Y-#103;
10 G#101;
11 G#102;
12 M99;
A #1 J #5 S #19
B #2 K #6 T #20
C #3 L #12 U #21
D #7 M #13 V #22
E #8 N W #23
F #9 O X #24
G P #16 Y #25
I #4 R #18
Instruction
Appendix – 74
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Axis XYZ As long as one of the arguments is • B code is defined by Pr3806 Second
Argume occupied by a macro, other axis auxiliary code
ABC
nt arguments are also occupied by that
IJK macro. Pr380 Type Explanation
6
UVW
0 Axis
Argument
Appendix – 75
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Conditio FSTDE Compared to axis argument, condition • T code is defined by Pr3215 Enable T
n HPQR argument is independent from each code call mode.
Argume MB other. If one of the condition argument is
nt occupied, only that one is occupied Pr32 Type Explanation
instead of all condition arguments. 15
Appendix – 76
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
0 Axis
Argument
Special L L argument is setting up macro repeated T code macro do not read L code.
Argume counts.
As a result, no matter what L code value is,
nt
• For example: G200 L10, it means G200 T code macro always execute once.
will continuously execute ten times.
• Even if the user doesn’t input L
argument when calling the macro, the
system will automatically fill in L=1 to
let macro execute once.
Appendix – 77
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T code macro
3 S code
4 F code
5 H code
6 D code
7 T code
8 M code
9 B code
Appendix – 78
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
• Normally, the interpreting order also represents the order of occupying argument, which means "the macro
interpreted first occupies the arguments first."
Nonetheless, this is not absolutely right, because the occupying order also depends on macro
characteristics.
Some macros are interpreted first but executed last. Hence, this situation does not comply to the rule,
"earlier interpreted, earlier occupying."
• Example:
a. Function G code is interpreted earlier than interpolation G code is, so function G code occupies axis
argument first.
Even though interpolation G code is on the left to the function G code in the same block, function G
code still occupies axis argument earlier.
b. In table above, interpreting order of both M code macro and T code macro are level 2,
which means if if T code and M code are in the same row,
interpreting order depends on the sequence, the code on the left is interpreted first.
Condition Character Argument reading and occupation Multi same code instruction in a row
T code macro • Pr3215 Enable T code call mode. This parameter is set up as
2. After rebooting, system regard T code as T code macro.
• If T code is considered T code macro, it only executes T code
macro if T argument (#20) is not occupied.
Appendix – 79
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Condition Character Argument reading and occupation Multi same code instruction in a row
Category Character
T code macro • T code updates different variables according to the type of T code. Following are
corresponding updating rules.
T code condition update #1036 #20 R value
Macro O X X
Sub-program O X X
Auxiliary Code O X O
Argument X O X
• If user want to capture T code value in a T code macro, please use T code
variable (#1036).
• If user want to capture T code value in other macros, please use T argument
(#20).
• Only when T code is auxiliary code, the corresponding R value of T code will be
updated. If T code is used as macro or argument, the corresponding R value of T
code is not updated.
Appendix – 80
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Category Character
M code macro • M code updates different variable according to the type of M code. Following are
corresponding updating rules.
T code condition update #13 R value
Macro O X
Auxiliary Code X O
Argument O X
• #13 is updated in M code macro or argument. Please note that this is different
from specification of T code.
• Only when M code is auxiliary code, the corresponding R value of M code will be
updated. If M code is used as macro or argument, the corresponding R value of M
code is not updated.
Condition Character Argument reading and occupation Multi same code instruction in a row
G code and G • While executing G code macro, argument read by G code macro is occupied.
code macro • If axis argument is read, all axis arguments are occupied simultaneously.
T code macro • While executing T code macro, system read arguments which are needed to. No
matter whether argument is occupied or not.
• After executing T code macro, all arguments read by T code macro are occupied. If
axis argument is read, all axis arguments are occupied simultaneously.
• Repeated count of T code macro is not defined by L code, and T code macro always
executes only one time.
• The L code argument (#12) is not read by system, even if there is one in T code macro.
System just puts 1 into #12.
Appendix – 81
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
M code macro • After executing M code macro, system occupies all arguments which are read by M
code macro.
• If M code macro doesn’t read T argument, then after finishes executing M code
macro, T argument is not occupied.
• If M code macro reads T argument, then after finishes executing M code macro,
T argument is occupied.
Condition Character Argument reading and occupation Multi same code instruction in a row
Appendix – 82
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T • If multi T code macros are in the same row. Each T code is interpreted sequentially and each T code macro can read ar
c
o
d
e
m
a
cr
o
M • If multi M code macro are in the same row, only the first M code macro is interpreted.
c • Pr3810 Parallel executing multiple M code in one block is for auxiliary M code not M code macro. Hence, even if Pr3810
o
d
e
m
a
cr
o
Condition Character Argument reading and occupation Multi same code instruction in a row
Appendix – 83
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Main
1 // Main
2 G200 A1 B2 C3 D7 E8 F9 H11 I4 J5 K6 L12 M13 P16 Q17 R18 S19 T20 U21
V22 W23 X24 Y25 Z26;
3 M30;
G0200
1 // G0200
2 %@MACRO
3
4 //Axis Argument
5 @101 := #1; // A
6 @102 := #2; // B
7 @103 := #3; // C
8 @104 := #4; // I
9 @105 := #5; // J
10 @106 := #6; // K
11 @121 := #21; // U
12 @122 := #22; // V
13 @123 := #23; // W
14 @124 := #24; // X
15 @125 := #25; // Y
16 @126 := #26; // Z
17
18 //Condition Argument
19 @107 := #7; // D
20 @108 := #8; // E
Appendix – 84
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
21 @109 := #9; // F
22 @111 := #11; // H
23 @113 := #13; // M
24 @116 := #16; // P
25 @117 := #17; // Q
26 @118 := #18; // R
27 @119 := #19; // S
28 @120 := #20; // T
29
30 //Special Argument
31 @112 := #12; // L
32
33 M00; // Switch the screen to [Diag.] →
[Display Global] and [Display Coord.]
34 WAIT();
35 M99;
02_Repeated argument
• Only the last repeated argument is read.
• Because same argument put value into the same # variable, the last one overrides the previous one.
Main
1 // Main
2 G01 X0.;
3 G200 X10. X-10.; // X argument has been written twice, only X-10
is read by G200
4 // #24 is input 10 by X10 first
5 // then input -10 by X-10.
6 // G01 will be executed after completing G200,
7 // because G01 can't read any argument X which
is occupied by G200
8 M30;
G0200
1 // G0200
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // The #24 is -10.
5 G01 X#101; // Move to X-10.
6 M00;
7 WAIT();
8 G#100; // Restore to interpolation mode
9 M99;
Appendix – 85
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 X10. Y20. Z30.; // Though G200 only reads X
argument
4 // Y, Z arguments are also
occupied
5 // G01 will be executed after
completing G200
6 // because G01 can't read any
argument which is occupied by G200
7 G01 X0. Y0. Z0. F100.;
8 G201 P20. X10. Y20. Z30. F200.; // Since G201 only reads P
argument
9 // X, Y, Z, F arguments are not
occupied
10 // G01 will be executed after
completing G201 and
11 // read X10. Y20. Z30. F200.
12 // , and then execute the
corresponding actions
13 M30;
G0200
1 // G0200
2 %@MACRO
3 @1:=#24; // Only reads X argument
4 M00;
5 WAIT();
6 M99;
G0201
1 // G0201
2 %@MACRO
3 @1:=#16; // Only reads P argument
4 M00;
5 WAIT();
6 M99;
Appendix – 86
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 X10. Y20. Z30. H40.; // G200 only reads H argument
4 // H argument is a condition
argument
5 // G01 will be executed after
completing G200.
6 // G01 read and occupy X10. Y20.
Z30.
7 // and then execute the
corresponding actions
8 M30;
G0200
1 // G0200
2 %@MACRO
3 #101 := #11; // Only reads H argument
4 M00;
5 WAIT();
6 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 X10. Y20. Z30. H40.; // G200 only reads H argument
4 // Since Pr3809=1, the H
argument is regarded as both axis argument and condition argument
5 // However, it is occupied as a
condition argument in MACRO
6 // G01 is executed after
completing G200
Appendix – 87
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
G0200
1 // G0200
2 %@MACRO
3 #101 := #11; // only reads H argument
4 M00;
5 WAIT();
6 M99;
• When reading axis arguments in MACRO, all the axis arguments will be occupied if one of them is occupied.
• As a result, the axis argument of H argument is occupied as well.
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 X10. Y20. Z30. H40.; // G200 only reads X argument
4 // Since Pr3809=1, the H
argument is regarded as both axis argument and condition argument
5 // The axis argument of H
argument is also occupied
6 // G01 will be executed after
completing G200
7 // G01 can't read any argument
since the axis arguments are all occupied by G200.
8 // The axis argument of the H
argument is also included and won't be read.
9 M30;
G0200
1 // G0200
2 %@MACRO
3 #101 := #24; // Only reads X argument
4 M00;
5 WAIT();
Appendix – 88
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
6 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 X10. Y20. Z30. B40.; // G200 only reads B argument
4 // Since Pr3806=0, B argument is
regarded as an axis argument
5 // X, Y, Z arguments is occupied
by G200
6 // G01 is executed after
completing G200
7 // and G01 can't read any
argument since all arguments are occupied by G200
8 M30;
G0200
1 // G0200
2 %@MACRO
3 #101 := #2; // Only reads B argument
4 M00;
5 WAIT();
6 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 X10. Y20. Z30. B40.; // G200 only reads B argument
4 // Since Pr3806=1, B argument is
seen as a condition argument
5 // X, Y, Z arguments are not
occupied by G200
6 // G01 is executed after
completing G200
Appendix – 89
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
G0200
1 // G0200
2 %@MACRO
3 #101 := #2; // Only reads B argument
4 M00;
5 WAIT();
6 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 G201 X10. P20.; // Since 2 G code macros are written in
the same line
4 // only the last G code macro is able to
read the argument
5 // Though G201 didn't read the X
argument
6 // G200 still can't read the X argument,
because X argument is axis argument
7 // G201 is executed after completing
G200, and
8 // G01 is be executed after G201 read
and occupied P argument
9 // G01 reads and occupies X10., and
10 // then executes the corresponding
actions
11 M30;
Appendix – 90
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
G200
1 // G0200
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101:=#24; // Read X argument which is unable to be
read
5 G01 X#101; // Since #101 has no value, this line
won't be executed
6 G01 X0.; // This line will be executed
7 M00;
8 WAIT();
9 G#100; // Restore interpolation mode
10 M99;
G201
1 // G0201
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101:=#16; // Read P argument which is able to be
read
5 G01 X#101; // This line will be executed
6 G01 X0.;
7 M00;
8 WAIT();
9 G#100; // Restore interpolation mode
10 M99;
Main
1 // Main
2 G90;
3 G00 X0. Y0. Z0.; // G00, spindle moves to X0 Y0 Z0
4 G200 G01 X10. F100.; // Since 2 G codes are in the same line.
5 // only the last G code can read the
argument
6 // G200 is executed but no arguments are
read
Appendix – 91
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
G200
1 // G0200
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Read X argument but it's unable to
read
5 G#100 X#101 F#9; // This line is not executed since #101
has no value. However, since #100=0, the interpolation mode changes
to G00.
6 M00;
7 WAIT();
8 M99;
G201
1 // G0201
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Read X argument and read X=10.
5 G#100 X#101 F#9; // Because #100 = 1, system executes
G01.
Appendix – 92
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
6 M00;
7 WAIT();
8 M99;
G202
1 // G0202
2 %@MACRO
3 M00;
4 WAIT();
5 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 T01 X10. Y20. Z30.; // T argument is not occupied and Pr3215=2,
so
4 // system executes T code macro
5 // With X argument being read in T code
macro,
6 // Y, Z arguments are occupied by T code
macro because all of them are axis arguments.
7 // G01 is executed after completing T01
8 // G01 can't read any argument since the
arguments in the line are all occupied by T coda macro.
9 M30;
T0000
1 // T0000
2 %@MACRO
3 #101 := #24; // only reads X argument
4 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
5 // Observe #20/#1036/#101
6 WAIT();
7 M99;
Appendix – 93
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 T01 G200 X10. Y20. Z30. F1000; // According to the
interpretation order, G code macro is interpreted first.
4 // There is a T argument read in
G code macro (G0200), so
5 // T argument is occupied and T
code macro is not executed.
6 // G01 is executed after
completing G code macro (G0200).
7 // G01 reads and occupies X10.
Y20. Z30. F1000, and
8 // executes the corresponding
actions
9
10 T02 G201 X10. Y20. Z30. F1000.; // According to the
interpretation order, G code macro is interpreted first.
11 // There is no T argument read
in G code macro (G0201), so
12 // T argument is not occupied,
and
13 // T code macro is executed
after G code macro (G0201) is completed
14 // Because T02 reads all
arguments, G01 can't read any argument
15 M30;
G0200
1 // G0200
2 %@MACRO
3 #101 := #20; // Only reads T argument
4 M00;
5 WAIT();
6 M99;
Appendix – 94
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T0000_01
G0201
1 // G0201
2 %@MACRO
3 #101 := #24; // Only reads X argument
4 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
5 WAIT();
6 M99;
T0000_02
1 // T0000
2 %@MACRO
3 #201 := #1000;
4 #202 := #1004;
5 #101 := #24;
6 #102 := #25;
7 #103 := #26;
8 #104 := #9;
9 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
10 WAIT();
11 G91 G01 X#101 Y#102 Z#103 F#104; // T code macro can still read
the arguments and execute the corresponding actions
12
Appendix – 95
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
13 G#201;
14 G#202
15 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 T01 L2; // Though T0000 reads #12,
4 // #12 is equal to "1", not "2" given by L argument
5 // Execute G01 after completed T01
6 // G01 reads and occupies L2, and
7 // executes the corresponding actions (G01 L2 is
meaningless)
8 M30;
T0000
1 // T0000
2 %@MACRO
3 #101 := #12; // Only reads L argument
4 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
5 WAIT();
6 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 T01 T02 X10. Y20. Z30.; // This line is executed twice
4 // T01 is executed first then T02
Appendix – 96
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T0000_T01
1 // T0000_T01
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Read X argument
5 #102 := #25; // Read Y argument
6 #103 := #26; // Read Z argument
7 IF #1036 = 1 THEN // T01 → #1036=1
8 G01 X#101; // X axis moving
9 G01 X0.;
10 END_IF;
11
12 IF #1036 = 2 THEN // The section is not executed
13 G01 Y#102;
14 G01 Y0.;
15 END_IF;
16
17 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
18 WAIT();
19 G#100; // Restore interpolation mode
20 M99;
T0000_T02
1 // T0000_T02
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Read X argument
5 #102 := #25; // Read Y argument
6 #103 := #26; // Read Z argument
7 IF #1036 = 1 THEN // The section is not executed
8 G01 X#101;
9 G01 X0.;
10 END_IF;
11
12 IF #1036 = 2 THEN // T02 → #1036=2
Appendix – 97
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Main
1 // Main
2 G01 X0. Y0. Z0. F100.;
3 M123 X10. Y20. Z30. F300.; // No M argument and no axis argument is
occupied, so
4 // M code macro M0123 is executed.
5 // While M code macro is executed, aside
from the arguments read by the M code macro,
6 // all other arguments are occupied as
well except T argument.
7 // Though the F argument is not read by
M0123, it is occupied, then the feedrate is not updated.
8 // G01, executed after completing M123,
9 // can't read any argument since the
arguments are all occupied.
10
11 G01 X0. Y0. Z0.; // The F in this line is F100, since the
argument in previous line is occupied by M code macro
12 M30;
M0123
1 // M0123
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Read X argument
5 #102 := #25; // Read Y argument
Appendix – 98
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G1301 M1301 X10. Y20. Z30. P2 F1000.; // G code macro is
interpreted first.
4 // The M argument is read by
G code macro (G1301)
5 // The M argument is
regarded occupied, M code macro is executed.
6 // Since the X, Y, Z
arguments is not occupied by G code macro (G1301).
7 // G01 is executed after
completing the G code macro (G1301).
8 // G01 reads and occupies
X10. Y20. Z30. P2 F1000., and
9 // then executes the
corresponding instructions.
10
11 G1302 M1301 X10. Y20. Z30. F1000.; // G code macro is
interpreted first
12 // Only P argument is read
by G code macro (G1302)
13 // The M argument is
regarded unoccupied, and
14 // no other axis arguments
are occupied
15 // The M code macro is
executed after completing the G code macro (G1302)
Appendix – 99
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
G1301
1 // G1301
2 %@MACRO
3 #101 := #13; // Only reads M argument
4 M00;
5 WAIT();
6 M99;
M1301_01
G1302
1 // G1302
2 %@MACRO
3 #101 := #16; // Only reads P argument
4 M00;
5 WAIT();
6 M99;
M1301_02
1 // M1301
2 %@MACRO
3 M00;
4 WAIT(); // The program does not read any argument
Appendix – 100
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
16_G code macro and M code macro are in the same line, and G code macro reads and
occupies axis argument.
• If Pr3601~3610 M code Macro call registry is set to 123, M0123 is registered as M code macro.
• When G code macro and M code macro are written in the same line, G code macro is interpreted before M
code macro.
• If axis arguments are occupied by G code macro, M code macro is not executed.
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 M123 X10. Y20. Z30.; // G code macro is interpreted first
4 // Because X argument is read by G code
macro (G0200),
5 // all axis arguments are occupied by
G200.
6 // M code macro therefore is executed
since axis arguments are occupied.
7 // G01, executed after completing G code
macro (G0200),
8 // can't read any argument since the
arguments in the line are all occupied
9 M30;
G0200
1 // G0200
2 %@MACRO
3 #101 := #24; // Only reads X argument
4 M00;
5 WAIT();
6 M99;
M0123
Appendix – 101
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
7 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 M123 M124 X10. Y20. Z30.; // M123 is interpreted first, and only
M123 is executed.
4 // X10. Y20. Z30. are read by M code
macro (M0123)
5 // All arguments except T are occupied
after executing the M code macro.
6 // G01, executed after completing M code
macro,
7 // can't read any argument since the
arguments are all occupied.
8 M30;
M0123
1 // M0123
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Read X argument
5 #102 := #25; // Read Y argument
6 #103 := #26; // Read Z argument
7 G00 X#101 Y#102 Z#103; // G00 moving along X, Y, Z axis
8 M00;
9 WAIT(); // Switch the screen to [Diag.] →
[Display Global] and [Display Coord.]
10 // User should found #13=124
11 // Since M124 is regarded as an
argument, which overwrote #13
12 G#100; // Restore interpolation mode
13 M99;
M0124
Appendix – 102
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
2 // M0124
3 %@MACRO
4 #101 := #24;
5 M00;
6 WAIT();
7 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 T01 M1601 X10. Y20. Z30.; // According to the interpreting order,
T01 is interpreted first, then M1601.
4 // No argument is occupied by T code
macro, so M code macro (M1601) executes X=10.
5 // Although M code macro (M1601) does
not read any argument,
6 // all the arguments except T are
occupied
7 // G01, executed after completing M code
macro (M1601),
8 // can't read any argument since the
arguments are all occupied.
9
10 M1602 T02 X10. Y20. Z30.; // According to the interpreting order,
M1602 is interpreted first.
11 // M code macro (M1602) does not reading
any argument.
12 // Because M code macro (M1602) occupies
all arguments except T,
13 // T code macro (T0000_02) is able to be
executed since T argument is not occupied by M code macro.
14 // G01, executed after completing T code
macro,
15 // can't read any argument since the
arguments in the line are all occupied
16
17 M1603 T03 X10. Y20. Z30.; // According to the interpreting order,
M1603 is interpreted first.
18 // M code macro (M1603) only reads the T
argument
Appendix – 103
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T0000_01
1 // T0000
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #1004; // Backup absolute/increment command mode
5
6 G91 G00 X10.; // X axis moving in increment of 10.
7
8 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
9 WAIT();
10 G#100; // Restore the interpolation mode
11 G#101; // Restore the absolute/increment command mode
12 M99;
M1601
1 // M1601
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #1004; // Backup absolute/increment command mode
5
6 G91 G00 Y10.; // Y axis moving in increment of 10.
7
8 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
9 WAIT();
10 G#100; // Restore the interpolation mode
11 G#101; // Restore the absolute/increment command mode
12 M99;
M1602
1 // M1602
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
Appendix – 104
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T0000_02
1 // T0000
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #1004; // Backup absolute/increment command mode
5
6 G91 G00 X10.; // X axis moving in increment of 10.
7
8 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
9 WAIT();
10 G#100; // Restore the interpolation mode
11 G#101; // Restore the absolute/increment command mode
12 M99;
M1603
1 // M1603
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #1004; // Backup absolute/increment command mode
5 #102 := #20; // Read data of #20, the line will occupy the T
argument
6
7 G91 G00 Y10.; // Y axis moving in increment of 10.
8
9 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
10 WAIT();
11 G#100; // Restore the interpolation mode
12 G#101; // Restore the absolute/increment command mode
13 M99;
Appendix – 105
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T0000_03
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G65 P1 X10. Y20. Z30.; // Execute O0001
4 M30;
O0001
1 // O0001
2 %@MACRO
3 #101 := #24;
4 #102 := #25;
5 #103 := #26;
6 M00;
7 WAIT();
8 M99;
Appendix – 106
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Main
1 // Main
2 G01 X-5. Y-5. Z-5.;
3 G200 G66 P1 X10. Y20. Z30. ; // G200 in this line can't read X
argument
4 G200 X10.; // G200 in this line can read X
argument
5 // There are 2 lines of G01 movement
blocks in G200
6 // G66 P1 X10. Y20. Z30. is executed
every time G01 movement block is finished.
7 G67;
8 M30;
G0200_01
1 // G0200_01
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Executing G200 for the first time, G200 can't
read X argument, so
5 G01 X#101; // this line is not executed.
6 G01 X0.;
7 M00;
8 WAIT();
9 G#100; // Restore the interpolation mode
10 M99;
G0200_02
1 // G0200_02
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Executing G200 for the second time, G200 is
able to read X argument, so
5 G01 X#101; // this line is executed
6 // This line is a movement block, after
finished, G66 P1 X10. Y20. Z30. is executed.
7 G01 X0.; // This line is a movement block, after
finished, G66 P1 X10. Y20. Z30. is executed.
8 M00;
9 WAIT();
10 G#100; // Restore the interpolation mode
11 M99;
Appendix – 107
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
O0001
1 // O0001
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24;
5 #102 := #25;
6 #103 := #26;
7 G91 G01 X#101 Y#102 Z#103;
8 M00;
9 WAIT();
10 G#100; // Restore the interpolation mode
11 M99;
Main
1 // Main
2 G01 X-5. Y-5. Z-5.;
3 G66.1 P1 X10. Y20. Z30. ;
4 G200 X10.; // G200 in this line can read the X
argument
5 // G66.1 P1 X10. Y20. Z30. is executed
every time the block in G200 is executed.
6 G67; // G66 P1 X10. Y20. Z30. is executed
after this block is executed
7 M30;
G0200
1 // G0200
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Executing G200 for the second time, G200 is
able to read X argument
5 G01 X#101; // This line is executed
6 // G66 P1 X10. Y20. Z30. is executed after this
block is executed
7 G01 X0.; // G66 P1 X10. Y20. Z30. is executed after this
block is executed
8 M00; // G66 P1 X10. Y20. Z30. is executed after this
block is executed
9 WAIT(); // This line is not a block
Appendix – 108
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
O0001
1 // O0001
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #1004; // Backup absolute/increment command mode
5 #111 := #24;
6 #112 := #25;
7 #113 := #26;
8 G91 G01 X#111 Y#112 Z#113;
9 M00;
10 WAIT();
11 G#100; // Restore the interpolation mode
12 G#101; // Restore the absolute/increment command mode
13 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G65 P1 X10. Y20. Z30. G200; // Alarm COR-013 shows up owing to wrong
syntax in this line, because
4 // G65 and G200 are in the same line
5 // but G65 is not the last G code.
6 M30;
G0200
1 // G0200
2 %@MACRO
3 #101 := #24;
4 M00;
5 WAIT();
Appendix – 109
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
6 M99;
O0001
1 // O0001
2 %@MACRO
3 #101 := #24;
4 #102 := #25;
5 #103 := #26;
6 M00;
7 WAIT();
8 M99;
-> The customized HMI first outputs the the user-defined contents to an xml file, and save the xml file to
the GNCFILES file path of which is assigned by user (refer to Pr3219).
The syntax format is defined as below,:
<?xml version="1.0" encoding="UTF-16"?>
<CycleFile>
<Cycle Name="Cycle_HerdonProg"> ← The beginning of first data
<Field Name="Col_Y" Value="17.63"/>
<Field Name="Col_Z" Value="12.98"/>
<Field Name="Col_X" Value="0.00"/>
<Field Name="Col_A" Value="267.54"/>
Appendix – 110
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
-> User have to write the configuration file of XML file by their own.
Configuration file( schema file ) defines the data to be read and the variable where data is put while
DBLOAD is used.
The syntax format is defined as below, and the configuration file should be saved in OCRes\\Common\
\Schema\\
If Dipole is enable, the schema file should be in the folder OCRes\\Common\\Schema\\ in controller.
Appendix – 111
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
<Name>Col_Y</Name>
<InputStorage>@1201</InputStorage> ←The variable Col_Y saves in
<InputFormat>Variant</InputFormat>
<DefaultValue></DefaultValue>
</Field>
<Field>
<Name>Col_Z</Name>
<InputStorage>@1202</InputStorage> ←The variable Col_Z saves in
<InputFormat>Variant</InputFormat>
<DefaultValue></DefaultValue>
</Field>
<Field>
<Name>Col_A</Name>
<InputStorage>@1203</InputStorage> ←The variable Col_A saves in
<InputFormat>Variant</InputFormat>
<DefaultValue></DefaultValue>
</Field>
<Field>
<Name>Col_B</Name>
<InputStorage>@1204</InputStorage> ←The variable Col_B saves in
<InputFormat>Variant</InputFormat>
<DefaultValue></DefaultValue>
</Field>
<Field>
<Name>Col_C</Name>
<InputStorage>@1205</InputStorage> ←The variable Col_C saves in
<InputFormat>Variant</InputFormat>
<DefaultValue></DefaultValue>
</Field>
</Cycle>
</Schema>
Appendix – 112
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
14 Preface
In order to increase the flexibility of the controller application, Syntec controller provides MACRO program editing
functions. When the processing program is declared in the MACRO format, specific mathematical functions are
applicable like other programming languages. In this way, in addition to the original movement and compensation
command functions, logical judgment and mathematical calculation functions are also included.
Preface – 113
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
15 File Format
The first line of the program should be declared as the title line with "%" and add the keyword "@MACRO".
Otherwise, the file will be regarded as a normal ISO format file, and user is not able to to use the full functionality of
the MACRO. In addition, each line of the program content must be followed by a semicolon ";", but there are
exceptions to some of the syntax, refer to the syntax description.
With or without 1. Except the special syntax, every line should end with semicolon.
semicolon at the end of 2. If the line does not end with semicolon, CNC combine it together with the next
line is acceptable. line when checking the syntax. If there is no alarm, the NC program run
normally; otherwise, there comes the alarm "COM-008," which is "line does not
end with semicolon."
Example:
While using "(...)", the ... While using "(*...*)", the ... is regarded as comment.
is regarded as comment.
Note:
1. It is recommended that multi-path style(including $1 and $2) might not be used in NC Program which is
called as sub-program or a macro.
Should it be inevitable, the size of the program must be less than 60KB(60000bytes). Otherwise, there
comes the alarm COR-203 Illegal NC file format
2. Not support the sub-program, which is in MACRO format, using the multi-path style (including $1, $2).
3. If the size of file is larger than 60KB(60000bytes), it would not support the syntax like IF, CASE, REPEAT, FOR,
WHILE, which are longer than one line. If these syntax are used, there will be alarms.( COR-204 File size too
large )
4. Only ASCII characters are acceptable in NC files. Using non-ASCII characters is thus unacceptable and will
trigger COM-027 Invalid character.
Note: Listed below are the special cases in which non-ASCII characters are considered acceptable:
a. Comment.
b. Arguments of MACRO functions that are of string type.
16 Block Format
The writing format of the block (one line) is instructed as follows:
/ N G X Y Z A B C I J K F S T D M
N The block sequence No., which must be written at the head of a block, and the
MACRO command or variable designation cannot be written in the same line.
X The X axis movement command, or the expansion of the G code, must be written
after the G code.
Y The Y axis movement command, or the expansion of the G code, must be written
after the G code.
Z The Z axis movement command, or the expansion of the G code, must be written
after the G code.
A The A axis movement command, or the expansion of the G code, must be written
after the G code.
B The B axis movement command, or the expansion of the G code, must be written
after the G code.
C The C axis movement command, or the expansion of the G code, must be written
after the G code.
I The radius command in the X direction or the argument of the expansion G code,
must be written after the G code.
J The radius command in the Y direction or the argument of the expansion G code,
must be written after the G code.
K The radius command in the Z direction or the argument of the expansion G code,
must be written after the G code.
17 Operator
Operator Sign Operating order
Brackets ()[] 1
Negative - 3
Complement NOT 3
Multiplication sign * 4
Divisor / 4
Plus + 5
Minus - 5
Comparison <,>,<=,>= 6
Equal = 7
Boolean “or” OR 11
Note 1:
When using the "/" component (division), be aware that if the numerator and denominator are integers, the result is
still an integer. The difference between an integer and a non-integer result is whether user adds the decimal point
or not.
example:
• The numerator is a non-integer: 1. / 2 = 0.5
• The denominator is a non-integer: 1 / 2.0 = 0.5
• The numerator and denominator are integers: 1/2 = 0
Operator – 118
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Operator – 119
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
18 Language Instructions
18.1 Variable Designation
Variable Designation
Example 1: @1 := 123;
Direct setting #1 := 456;
#10 := "12"; // The local variable #10 content is 12
@10 := "12"; // public variable @10 content is 12849
Remarks 1. The "12" in the first example is a string, indicating that the string is stored in
the variable. When the public variable is stored, the controller will translate the
string into ASCII. For the local variable, the translation will not be executed.
2. To correctly read the contents of the string stored in the public variable, use
the SCANTEXT function.
3. In the example 2, please notice that it's the "square bracket"
18.2 GOTO
GOTO
Syntax GOTO n;
Explanation The use of GOTO should be paired up with block sequence code(n). CNC would
jump to the specified N-number and execute from that line. If there are two same
N-numbers in the program, the first N-line number in the program will take
precedence than the second one.
Examples %@MACRO
#1 := 1;
#2 := 10;
IF( #1 = 1 ) THEN
GOTO #2;
END_IF;
IF( #1 = 2 ) THEN
GOTO 100;
END_IF;
N10;
G01 G90 X50. Y0. F1000;
M30;
N100;
G01 G90 X0. Y50. F1000;
M30;
Remarks When using the loop function such as REPEAT/WHILE/FOR/GOTO, user should pay
attention to the problem of infinite loop. When this occurs, the human machine
interface, which is screen, may be locked or the machining program may crash.
It is recommended to add the SLEEP() function avoiding the crash resulting
from the infinite loop. With SLEEP() function, there is still chance to operate the
human-machine interface to stop the program execution.
18.3 CASE
CASE
Examples %@MACRO
#1 := 1;
G01 G90 X0. Y0. F1000;
CASE #1 OF
1:
X(1.0*#1) Y(1.0*#1);
2:
X(2.0*#1) Y(2.0*#1);
3, 4, 5:
X(3.0*#1) Y(3.0*#1);
ELSE
X(4.0*#1) Y(4.0*#1);
END_CASE;
M30;
18.4 IF
IF
Examples %@MACRO
#1 := 3.0;
G01 G90 X0. Y0. F1000;
IF #1 = 1 THEN
X(1.0*#1) Y(1.0*#1);
ELSEIF #1 = 2 THEN
X(2.0*#1) Y(2.0*#1);
ELSEIF #1 = 3 THEN
X(3.0*#1) Y(3.0*#1);
ELSE
X(4.0*#1) Y(4.0*#1);
END_IF;
M30;
18.5 Repeat
REPEAT
Syntax REPEAT
<statement List>
UNTIL <condition>
END_REPEAT;
Examples %@MACRO
#10 := 30.;
#11 := 22.5.;
#12 := #10/2;
#13 := #11/2;
#14 := 2.0;
#15 := 1.5;
G01 G90 X#12 Y#13 F1000;
REPEAT
G00 X(#12+#14) Y(#13+#15);
G01 X(#12+#14) Y(#13-#15);
G01 X(#12-#14) Y(#13-#15);
G01 X(#12-#14) Y(#13+#15);
G01 X(#12+#14) Y(#13+#15);
#14 := #14 + 2.0;
#15 := #15 + 1.5;
UNTIL (#14 > #12) OR (#15 > #13) END_REPEAT;
M30;
Remarks When using the loop function such as REPEAT/WHILE/FOR/GOTO, user should pay
attention to the problem of infinite loop. When this occurs, the human machine
interface, which is screen, may be locked or the machining program may crash.
It is recommended to add the SLEEP() function avoiding the crash resulting
from the infinite loop. With SLEEP() function, there is still chance to operate the
human-machine interface to stop the program execution.
18.6 While
WHILE
Examples %@MACRO
#10 := 30.;
#11 := 22.5.;
#12 := #10/2;
#13 := #11/2;
#14 := 2.0;
#15 := 1.5;
G01 G90 X#12 Y#13 F1000;
WHILE (#14 <= #12) AND (#15 <= #13) DO
G00 X(#12+#14) Y(#13+#15);
G01 X(#12+#14) Y(#13-#15);
G01 X(#12-#14) Y(#13-#15);
G01 X(#12-#14) Y(#13+#15);
G01 X(#12+#14) Y(#13+#15);
#14 := #14 + 2.0;
#15 := #15 + 1.5;
END_WHILE;
M30;
Remarks When using the loop function such as REPEAT/WHILE/FOR/GOTO, user should pay
attention to the problem of infinite loop. When this occurs, the human machine
interface, which is screen, may be locked or the machining program may crash.
It is recommended to add the SLEEP() function avoiding the crash resulting
from the infinite loop. With SLEEP() function, there is still chance to operate the
human-machine interface to stop the program execution.
18.7 For
FOR
Syntax FOR <variable 1> := <Description 1> TO <Description 2> BY <Description 3> DO
<statement list>
END_FOR;
Variable 1: The variable that controls the number of loops
Description 1: The start number of the loop count, which can be a numerical value or
an arithmetic expression
Description 2: The terminated number of the loop count, which can be a numerical
value or an arithmetic expression.
Description 3: The added number to the current loop count after each loop, which
can be a numerical value or an arithmetic expression.
Statement list: execution in each loop
Examples %@MACRO
#10 := 30.;
#11 := 22.5.;
#12 := #10/2;
#13 := #11/2;
#14 := 2.0;
#15 := 1.5;
G01 G90 X#12 Y#13 F1000;
FOR #6 := 0 TO 3 BY 1.0 DO
G00 X(#12+#14) Y(#13+#15);
G01 X(#12+#14) Y(#13-#15);
G01 X(#12-#14) Y(#13-#15);
G01 X(#12-#14) Y(#13+#15); G01 X(#12+#14) Y(#13+#15);
#14 := #14 + 2.0;
#15 := #15 + 1.5;
END_FOR;
M30;
Remarks 1. When using the loop function such as REPEAT/WHILE/FOR/GOTO, user should
pay attention to the problem of infinite loop. When this occurs, the human
machine interface, which is screen, may be locked or the machining program may
crash.
2. It is recommended to add the SLEEP() function avoiding the crash resulting
from the infinite loop. With SLEEP() function, there is still chance to operate the
human-machine interface to stop the program execution.
3. Do NOT use the command whitch will jump out and in FOR loop ( e.g: Complex
Canned Cycle (G72-G78), using GOTO jump out loop and jump in again ), 、M98
H_, it will cause the incorrect added number(<Description 3>).
example:
N12;
M00;
@1:=@1+5;
GOTO 13;
M99;
18.8 EXIT
EXIT
Syntax EXIT
Examples %@MACRO
#10 := 30.;
#11 := 22.5.;
#12 := #10/2;
#13 := #11/2;
#14 := 2.0;
#15 := 1.5;
#16 := 1.0;
G01 G90 X#12 Y#13 F1000;
FOR #6 := 0 TO 3 BY 1.0 DO
IF((#14 = 4) & (#16 = 1)) THEN
EXIT;
END_IF;
G00 X(#12+#14) Y(#13+#15);
G01 X(#12+#14) Y(#13-#15);
G01 X(#12-#14) Y(#13-#15);
G01 X(#12-#14) Y(#13+#15);
G01 X(#12+#14) Y(#13+#15);
#14 := #14 + 2.0;
#15 := #15 + 1.5;
END_FOR;
M30;
Ex Program Annotation(comment)
Example 1 %@MACRO
Single line annotation G00 G90 X0. Y0.; // homing
M30;
Example 2 %@MACRO
Block annotation (*
This block is the annotation area
Regardless of the content, it does not affect program execution.
*)
G00 G90 X0. Y0.;
G00 G90 X10. Y0.;
G00 G90 X10. Y10.;
G00 G90 X0. Y10.;
G00 G90 X0. Y0.;
M30;
Remark If a text that is an annotation is added to the statement list, system error may occur
due to the limitation while interpreting the code. This misuse is not under the
protection of the controller.
Syntax %
Execution Program
%
Explanation 1. While there is "%...%" in the program, the execution program between
two % will be executed by CNC. For those program prior to the first %
and after the second % will not be executed.
A #1 J #5 T #20
B #2 K #6 U #21
C #3 L #12 V #22
D #7 M #13 W #23
E #8 P #16 X #24
F #9 Q #17 Y #25
I #4 S #19 X1 GETARG(X1)
• Modal Variables ( #2001 ~ #2100, #3001 ~ #3100) will return to the VACANT state when the system is reset, so
it can be applied to the timing of data exchange between multiple MACROs to save the use of variable
resources.
• If a default initial value is required for MACRO, Customer Parameter is recommneded(#4001 ~ #4100, #5001
~#5100).
• When the MACRO sub-routine (sub-program) is executed, if the mode G code is changed (G91/G90, G40/G41/
G42, ..., etc.), please back up the current state, and restore the original mode G state before leaving the
MACRO.
• If user want to keep the current MACRO interpolation mode (#1000) after leaving MACRO, it is recommended
to designate #1000 as the MACRO number before leaving MACRO. As long as there is single block of the axial
displacement, the system will automatically call this MACRO without specifying it again.
• The interpolation mode will be automatically rewritten when G00/G01/G02/G03/G31/G33 show up or
#1000 change.
• For length or angle arguments, use the STD function to normalize the unit before operation to match the
usage habits of machine tool.
• Change to the setting of coordinate system is strictly forbidden, such as G92/G54/G52 which are relevant to
coordinate system. Otherwise, the simulation would be useless.
• When machining, the core will pre-interpret the MACRO content, so the MACRO progress is ahead of the
practical G/M code. If the variable specification or the data reading needs to synchronize with the G/M code,
please add WAIT function before the variable specification or the data reading to ensure the movement is
correct.
• The MACRO program must be added with "M99;" to return to the main program (parent program).
• Develop good habits, add more comments to the program, this will increase program readability, and help
subsequent maintenance and troubleshooting.
0 none none
-1 G00 G0000
1 G01 G0001
2 G02 G0002
3 G03 G0003
4 G53 G0053
5 G40 G0040
6 G41 G0041
7 G42 G0042
8 G43 G0043
9 G44 G0044
10 G49 G0049
11 G04 G0004
• The following are the operating specifications for the G code macro
• Version revision
Version Revision
21 Function List
Function Explanation
ATAN Calculate the atan of a value. The calculation result is between ±90°.
Example:
#10 := 1;
#1 := ATAN(#10); // #1 = 45
#2 := ATAN(-1); // #2 = -45
Function Explanation
ATAN2(Y, X) Calculate the four-quadrant atan value of Y/X. The calculation result is between
±180°.
Example:
#10 := 1;
#20 := -1
#1 := ATAN2(#10, #20); // #1 = 135
#2 := ATAN2(#20, #10); // #2 = -45
#3 := ATAN2(1, 0); // #3 = 90
Notes:
1. Valid version: 10.118.29W, 10.118.40C, 10.118.42
2. The argument X and Y must be numbers, or the alarm COR-023【Semantic
error】will be issued.
3. The argument X and Y can not be zero at the same time, or the alarm
COR-004【Operation domain error】will be issued.
Example of wrong cases:
@1 := ATAN2( "1", 1 ); // The first argument is not a number, issue
COR-023 alarm.
@2 := ATAN2( 0, 0 ); // The arguments are both zero, issue COR-004
alarm.
AXID Inquire the axis number corresponding to the axis name. If the axis name does
not exist, the return value is blank (VACANT, #0)
Example:
Suppose the sixth axis name is Y2 (Pr326=202) and the second axis name
is Y (Pr322=200).
#1 := AXID(Y); // #1 = 2
#2 := AXID(Y2); // #2 = 6
CEIL Return the smallest integer greater than or equal to a certain value
Example:
#10 := 1.4;
#1 := CEIL(#10); // #1 = 2
#2 := CEIL(1.5); // #2 = 2
CLOSE Close the file opened by the OPEN function, and the file will be automatically
closed after the program ends. The PRINT function will fail if the file is already
closed.
Example:
CLOSE(); // close the file
Function Explanation
DBLOAD Read the data of specified index from the currently loaded XML. For related
applications, please refer to the appendix.
Example:
DBOPEN("FLAT\\TAB01");
// Load FLAT\\TAB01 data file
DBLOAD( 0 );
// read the 0th cycle
DBLOAD( 1 );
// read the 1st cycle
Note: The file path to the XMLDB may be influenced by customized Action
(CUSTOMFILE_CYCLE1~5), please refer to CE人机客制应用文件.
Function Explanation
DBSAVE Save the data of specified index from the currently loaded XML. For related
applications, please refer to the appendix.
EX:
Notes:
1. The file path for XMLDB can be changed by Customized Actions
(CUSTOMFILE_CYCLE1~5). Fore more info, refer to CE人机客制应用文件-開放使
用的Action列表 。
2. Opening (DBOPEN) and loading (DBLOAD) must be done before saving
(DBSAVE). If the user uses DBSAVE without using DBPEN and DBLOAD
beforehand, the saving process will NOT be executed.
3. Even if the Field Value is the same as the default value defined in the Schema,
the data will still be written into the CYC data file.
4. Versions: 10.118.39 and later.
DBOPEN Load the specified XML. The XML should be in the GNCFILES specified by the
user. For related applications, please refer to the appendix.
Example:
DBOPEN("Test.cyc");
// Load GNCFILES\\Test.cyc
Example:
#1 = 51;
DBOPEN("FLAT\\\\AB#1[3]ZZ.cyc" );
// Load FLAT\\\\AB051ZZ.cyc, [3] indicates that the file name is in
three valid digits
Note1: The file path to the XMLDB may be influenced by customized action
(CUSTOMFILE_CYCLE1~5), please refer to CE人机客制应用文件.
Note2: For the requirement of reloading file, please reset system ( or run BGnd
Stop in Background Running Objects ) before re-execute DBOPEN.
Function Explanation
DRAWHOLE Draw a circle based on the tool radius and the color defined by the SETDRAW
function at the current position (only valid in the simulation, system will not add
a circle in the actual path)
EXP Calculate the exponential value with natural number as the base
Example:
#1:=EXP(1); // e^1 = 2.71828
Valid version: 10.116.16
FLOOR Return the largest integer less than or equal to a certain value
Example:
#10 := 1.4;
#1 := FLOOR(#10); // #1 = 1
#2 := FLOOR(1.5); // #2 = 1
Function Explanation
GETTRAPARG Read the argument content in Trap Block. Trap Block is the blocks between G66/
G66.1 and G67.
Example:
Assume that the main program content of O0001 is
G66 P100 X100. Y100. // P100 means call sub-program O0100.
G01 X20. // O0100 sub-program uses GETTRAPARG to read the argument
content
#1 := GETARG(X);
// Save the X argument 100. to #1
#2 := GETTRAPARG(X);
// Save the X argument in the Trap block, 20. to #2
Please refer to G66/G67:Call Modal Macro.
Function Explanation
MSG Customize the message, please refer to the "MACRO Customized Message" for
details.
Example:
MSG(100); // message ID
MSG("bit lost"); // display message content
MSG(100, "bit lost"); // hint ID + displaye message content
Remark: There is limit of string length in a message. For Mandarin, it's 19
words;For English, it's 39 alphabets.
Function Explanation
OPEN ("file name") or Open a text file name of which user specify, which is in the NcFiles folder ( Folder
path please refer the Pr3219 ). The PRINT function is valid only after the file is
OPEN ("file name", "writing
opened.
mode")
If the file name is "COM", it means that the port RS232/RS485 is turned on, and
its setting is determined by Pr3905.
Example:
OPEN("COM"); // Open port RS232
PRINT("\\p"); // Output '%' character
FOR #1 = 1 TO 5000 DO
#30 := #1 * 10.;
PRINT("G01 X#30"); // Output G01 X10.0
END_FOR;
PRINT("\\p"); // Output '%' character
CLOSE(); // Close port
The "writing mode" determines, when the file is opened, whether the original
file content is retained or cleared. (valid version: 10.116.36I)
(i) "a": Keep the original text and the text newly-output follows the original one.
Example:
OPEN("PROBE.NC", "a");
// Open PROBE.NC and keep the text, and be ready for text output
(ii) "w"/nothing: Clear the original text and output the new text in the file.
Example:
OPEN("PROBE.NC");
// Open PROBE.NC and clear the text, and be ready for text output
OPEN("PROBE.NC", "w");
// Open PROBE.NC and clear the text, and be ready for text output
(iii) Wrong writing mode: system issues alarm, COR-301 OPEN command format
error.
Example:
OPEN("PROBE.NC", "abc");
// Wrong writing mode, issues alarm, COR-301, so PROBE.NC is not
opened for text output.
(iv) Convert # or @ variable into a string, and the decimal digits is determined by
Pr17 (valid version: 10.118.12C)
Function Explanation
(v) Convert # or @ variable into a string with [*] in the end, and the decimal digits
is determined by this variable.
POP Taking the data in STACK from top layer to bottom layer in sequence. User must
pay attention to the total data in the stack. If there are 5 data, the maximum
times to use POP is 5.
Example:
PUSH(5); // Insert the number 5 into the stack
#1 := POP(); // Remove the topmost value in the stack (#1 = 5)
Function Explanation
PRINT This function is used to output a string, and the variable in the output string will
be replaced by the content of it.
The character "\" is an escape character, and the related special characters are
defined as follows:
"\\": indicates "\" character
"\@": indicates "@" character
"\#": indicates "#" character
"\p": indicates"%" character
Convert # or @ variable into a string, and the decimal digits is determined by
Pr17 (valid version: 10.118.12C)
Convert # or @ variable into a string with [*] in the end, and the decimal digits is
determined by this variable.
Example:
Assume that Pr17=2 in metric unit
@53 = 20 ;
#3 = 23.1234 ;
PRINT("G01 X#3 Y@53 Z20.0") ;
The output is G01 X23.123 Y20 Z20.0 ; // Display to thousandths place
Example:
@53 = 20 ;
#3 = 23.1234 ;
PRINT("G01 X#3[2] Y@53 Z20.0") ; // #3[2] means display to hundredths
place
The output is G01 X23.12 Y20 Z20.0 ; // Display to hundredths place
PUSH Stuff data into the STACK, the data PUSH into the controller first will be stacked
on the bottom layer, and the last data on the top one.
Example:
PUSH(#1); // Put variable #1 into the STACK
Function Explanation
READDI The value of variable derives from the I/O point number in the parentheses
READDI/READDO.
(I point number)
Example:
READDO
@52 := READDI(31); // Read the value of I31 and put it in @52
(O point number)
#88 := READDO(11); // Read the value of O11 and put it in #88
G90 G10 L1000 P4000 R READDI(15); // Read the value of I15 and put it in
R4000
Notes:
1. Valid version: 10.116.23
2. The I/O point is read during pre-interpreting, but it is processed when
READDI / READDO is executed in order to avoid the error resulting from pre-
interpreting I/O point. Because system await until READDI / READDO is
executed, machine will decelerate to zero.
3. The range of I/O point number is 0~511. If the number is out of the range,
system issues alarm, COR-138 Read/write command format error at the I/O/
A point.
READABIT The value of variable derives from the A point number in the parentheses of
READBIT.
(A point number)
Example:
@52 := READABIT(31); // Read the value of A31 and put it in @52
#88 := READABIT(11); // Read the value of A11 and put it in #88
Notes:
1. Valid version: 10.116.44
2. The A point is read during pre-interpreting, but it is processed when
READBIT is executed in order to avoid the error resulting from pre-
interpreting A point. Because system await until READBIT is executed,
machine will decelerate to zero.
3. The range of A point number is 0~511. If the number is out of the range,
system issues alarm, COR-138 Read/write command format error at the I/O/
A point.
Function Explanation
READRREGBIT The value of variable derives from the register number and specified bit in the
parenthesis of the READRREGBIT.
(Register number, specified
Bit) Example:
@52 := READRREGBIT(31,3); // Read the value of the third bit of R31 and
put it in @52
Notes:
1. Valid version: 10.116.39
2. The register is read during pre-interpreting, but it is processed when
READRREGBIT is executed in order to avoid the error resulting from pre-
interpreting Register. Because system await until READBIT is executed,
machine will decelerate to zero.
3. If register is less than 0 or greater than 65535, the system issues alarm,
COR-135 Read/write command format error for R value.
4. If register is an incorrect character, system issues alarms, COR-5 Program
loading failure and COM-8 absent statement ending character ';'.
5. If specified bit is less than 0 or greater than 31, system issues alarm,
COR-135 Read/write command format error for R value.
6. If specified bit or both of register and specified bit is incorrect characters,
system issues alarm, COR-5 Program loading failure and COM-9 wrong
assignment character ':='.
Function Explanation
SCANTEXT This function is used to read the contents of the string stored in global variable.
When the string is stored in global variable, the controller translate it into ASCII
first and save. User get wrong string if they output the value directly. To get the
correct string, please make good use of this function.
Example:
%@MACRO
@1:="12"; // 16 carry HEX=3231, 10 carry DEC=12849
#1:=SCANTEXT(1);
OPEN("NC");
PRINT("@1");
PRINT("#1");
CLOSE();
M30;
The result is @1 = 12849
#1 = 12
SETDO Determine O point number and the state (1: On, 0: Off) with 2 numbers in the
parenthesis of SETDO.
(O point number,
Example:
O point on or off)
SETDO(3, 1); // Set O3 on
SETDO(8, 0); // Set O8 off
Notes:
1. Valid version: 10.116.23
2. The writing of point O is in the interpolation stage, so it is not necessary to
decelerate to 0 during execution. However, in the MACRO processing in pre-
interpreting stage, the developer should decide whether to use WAIT, which
makes machine decelerate to 0.
3. Mixed use of PLC and SETDO should be avoided. For example, O1 is on by
SETDO in MACRO, but off in PLC. Even though the previous order is
overridden by the next one, it is common to confuse while using both, so it is
recommended that use one of them at a time.
4. The range of O point number is limited to 0~511. If the range is wrong, the
system issues alarm, COR-138 Read/write command format error at the I/O/
A point.
Function Explanation
SETABIT Determine A point number and the state (1: On, 0: Off) with 2 numbers in the
parenthesis of SETDO.
(point A, point A on or off)
Example:
SETABIT(3, 1); // Set A3 on
SETABIT(8, 0); // Set A8 off
Notes:
1. Valid version: 10.116.44
2. The writing of point A is in the interpolation stage, so it is not necessary to
decelerate to 0 during execution. However, in the MACRO processing in pre-
interpreting stage, the developer should decide whether to use WAIT, which
makes machine decelerate to 0.
3. Mixed use of PLC and SETABIT should be avoided. For example, A1 is on by
SETABIT in MACRO, but off in PLC. Even though the previous order is
overridden by the next one, it is common to confuse while using both, so it is
recommended that use one of them at a time.
4. The range of A point number is limited to 0~511. If the range is wrong, the
system issues alarm, COR-138 Read/write command format error at the I/O/
A point.
SETRREGBIT Determine Register number, Bit number, and the state (1: On, 0: Off) with the 3
digits in the parenthesis of SETRREGBIT.
(Register number, Bit
number, on or off) Example:
SETRREGBIT(50,3,1); // Set the third R50 Bit on
SETRREGBIT(50,4,0); // Set the fourth R50 Bit off
Notes:
1. Valid version: 10.116.39
2. The writing of Register is in the interpolation stage, so it is not necessary to
decelerate to 0 during execution. However, in the MACRO processing in pre-
interpreting stage, the developer should decide whether to use WAIT, which
makes machine decelerate to 0.
3. Mixed use of PLC and SETRREGBIT should be avoided. For example, first Bit
of R50 is on by SETRREGBIT in MACRO, but is off in PLC off. Even though the
previous order is overridden by the next one, it is common to confuse while
using both, so it is recommended that use one of them at a time.
4. If Register number is less than 0 or greater than 65535, the system issue
alarm, COR-135 Read/write command format error for R value.
5. If Bit number is less than 0 or greater than 31, system issues alarm,
COR-135 Read/write command format error for R value.
6. If the state is not 0 (off) or 1 (on), system issues alarm, COR-135 Read/write
command format error for R value.
7. If any argument is incorrect character, system issues alarms, COR-5 Program
loading failure and COM-3 Syntax error.
Function Explanation
0 0 8 8421504
1 8388608 9 16711680
2 32768 10 65280
3 8421376 11 16776960
4 128 12 255
5 8388736 13 16711935
6 32896 14 65535
7 12632256 15 16777215
Note:
• BGR code is the same as RGB code, but with different endianness for B(Blue)
and R(Red) value.
e.g.
Red color in RGB code is 0xFF0000. Converting it into BGR code will be 0x0000FF
= 255. (as described in color code 12)
• SETDRAW sets path color and filled color at the same time. If user would like
to make path color and filled color different, remember to change the path
color with SETDRAW after DRAWHOLE is executed.
Function Explanation
e.g.
%@MACRO
#3:=SETDRAW(#1,#2,#18);
// #3 records the original path color, #2 defines the filled color, #18
defines the circle radius
DRAWHOLE();
SETDRAW(#3);
// Change the path color after drawing the circle
M99;
SIGN Return the sign of a value, the negative number is -1, the positive number is 1,
and 0 is 0.
Example:
#10 := 4;
#1 := SIGN(#10); // #1 = 1
#2 := SIGN(-4); // #2 = -1
#3 := SIGN(0); // #3 = 0
SLEEP Temporarily abandon the execution right of this macro loop, generally used in
conjunction with the loop (FOR, WHILE..., etc.) to avoid entering the infinite
loop, which causes the human-machine to crash.
Example:
SLEEP();
Function Explanation
STD (argument1, argument According to Pr17, the value is converted into the input unit (Input Unit, IU) set
2) by the system at that time.
1. The argument 1 is the value the unit of which is about to be changed.
2. The argument 2 is a standard unit. Generally, it is #1600, and value of #1600
is from Pr17.
Metric Unit:
Example 1:
When Pr17=2, #1600 corresponds to LIU = 0.001mm
#9 := 100;
#10 := STD(#9,#1600); // #9 is 100 BLU, so #10 is 0.1mm (100*0.001)
Example 2:
When Pr17=3, #1600 corresponds to LIU = 0.0001mm
#9 := 100;
#10 := STD(#9,#1600); // #9 is 100 BLU, so #10 is 0.01mm (100*0.0001)
Imperial:
Example 3:
When Pr17=2, #1600 corresponds to LIU = 0.0001inch
#9 := 100;
#10 := STD(#9,#1600); // #9 is 100 BLU, so #10 is 0.01inch (100*0.0001)
STDAX (argument 1, Converts the value to the standard unit of the corresponding axis.
argument 2)
The argument 1 is a variable, and the argument 2 is the name of the
corresponding axis.
Example:
#24 := STDAX(#24,X);
#3 := STDAX(#3,A);
Function Explanation
WAIT The system stops pre-interpreting until the instruction before WAIT is finished.
Example:
%@MACRO
@50 := 1; // @50 equals to 1
G90 G01 X100. F1000; // Assume to system is Reset at this time
WAIT();
@50 := 0; // @50 equals to 0
M30;
Assume that the system is reset when G01 is in execution. Since the block
before WAIT is not finished, @50 equals to 1 after Reset.
Function Explanation
CHKMN ("machinery code") Check machinery code. 1: consistent, 0: does not match
Example:
%@MACRO
#51 := CHKMN("5566"); //The value of #51 is the checking result .
IF #51=0 THEN
ALARM(501, "The manufacturer code is invalid."); //If machinery
code does not match, system issues an alarm
END_IF;
Target version: 10.116.6A
CHKSN ("Serial No.") Check Serial Number. 1: consistent, 0: does not match
Example:
%@MACRO
#52 := CHKSN("M9A0001"); //The value of #52 is the checking result
IF #52=0 THEN
ALARM(502, "The serial number is invalid."); //If the serial
number does not match, system issues the alarm
END_IF;
Target version: 10.116.6A
CHKMT ("Machine Type") Check machine type. 1: consistent, 0: does not match
Example:
%@MACRO
#53 := CHKMT("MILL"); //The value of #53 is the check result
IF #53=0 THEN
ALARM(503, "The machine type is invalid."); //If machine type does
not match, system issues the alarm
END_IF ;
Target version: 10.116.6A
Function Explanation
CHKMI ("Model") Check the controller model, 1: consistent, 0: does not match
For SUPER series, please input 'S'. For other models, please input value
according to the actual model. For example, 10B =>10B, 11A, => 11A.
Example:
%@MACRO
#54 := CHKMI("S"); //#54 is the checking result
IF #54=0 THEN
ALARM(504, "The hardware type is invalid."); //If the model does not
match, system issues the alarm
END_IF;
Target version: 10.116.6A
Function Explanation
CHKINF( category number, Check if the code corresponds to the category number. 1: consistent, 0: does not
"code") match
The range of category numbers is 1~5, each corresponding code is:
1. Machinery code
2. Serial No.
3. Machine Type
4. Model
5. Industrial machine ID
For SUPER series, please input 's'. For other models, please input value
according to the actual model. For example, 10B =>10B, 11A, => 11A.
Example:
%@MACRO
#51 := CHKINF(1, "5566"); // #51 is the checking result
IF #51=0 THEN // If the machineny code does not match, system issues an
alarm
ALARM(501, "The manufacturer code is invalid.");
END_IF;
#52 := CHKINF(2, "M9A0001"); // #52 is the checking result
IF #52=0 THEN // If the serial No. does not match, system issues the alarm
ALARM(502, "The serial number is invalid.");
END_IF;
#53 := CHKINF(3, "MILL"); // #53 is the checking[ result
IF #53=0 THEN // If the machine type does not match, system issue the
alarm
ALARM(503, "The machine type is invalid.");
END_IF;
#54 := CHKINF(4, "S"); // #54 is the checking result
IF #54=0 THEN // If the model does not match, system issues
the alarm
ALARM(504, "The hardware type is invalid.");
END_IF;
#55 := CHKINF(5, "10"); // #55 is the checking result
IF #55=0 THEN // If the Industrial machine ID does not match, system
issues the alarm
ALARM(505, "The industrial machine ID is invalid.");
END_IF;
If argument is incorrect, or the category number is out of the range, system
issues the alarm, COR-353 【Invalid argument of CHKINF】
Example:
Function Explanation
%@MACRO
#51 := CHKINF(60, "Mill"); // category number is out of range
#51 := CHKINF("2", "Mill"); // argument 1 is incorrect
#53 := CHKINF(5, 12345); // argument 2 is incorrect
Target version: 10.118.22M、10.118.28B、10.118.30
Function Explanation
Function Explanation
e.g:
// assume want to get
// speed command( Pn-D26 ) of first axis ( station_number=1000 )
// Enc Internal Temperature( Pn-D61 ) of first spindle
( station_number=1003 )
WAIT(); // To get newest value, block Pre-Interpretation
#1 := DRVDATA(1000, 3366); // speed command of first axis ( Pn-D26,D26
convert to decimal format is 3366 )
#2 := DRVDATA(1003, "D61h"); // Enc Internal Temperature of first
spindle( Pn-D61,D61 convert to hexadecimal format is "D61h" )
OPEN("DbgData.txt", "a"); // open file DbgData.txt
PRINT("Pn-D26: #1, Pn-D26: #2"); // print value
CLOSE(); // close file
The file DbgData.txt content may be below.
Pn-D26: 150, Pn-D26: 430
Note:
1. Valid version: 10.118.23U, 10.118.28.I, 10.118.34.
2. For getting newest value, it is recommended to use WAIT() function blocking
the pre-interpretation before using DRVDATA().
3. The execution time of each function is 0.1~0.2s.
4. First argument must be integer, system will issues the alarm COR-023
【Semantic error】.
5. If second argument is string type, must be hexadecimal format ("xxxh",
x=0~F), system will issues the alarm COR-023【Semantic error】.
6. second argument must be string or integer value, system will issues the
alarm COM-003【Syntax error】.
7. If either the drive or the controller does not support the specified status
variable, the system will issue the alarm COR-016【Illegal variable
access】.
8. Visit the "Controllor Axis Info." page to check status variable accessibility.
Only those shown are accessibile.
9. If the controller supports specified status variable and the drive does not
support, 0 will be returned.
10. If no drive corresponding to station number or using non Syntec M3 drive,
return VACANT.
Function Explanation
11. Since it will take some time to read the status variable after system be
powered on, it is recommended to call this function one minute after
powering on, or it might cause system issue the alarm COR-016【Illegal
variable access】due to the variable are not read finish.
Example of wrong case:
// alarm COM-3
DRVDATA( 1003, D61h ); // second argument must be string or integer
value
// alarm COR-023
DRVDATA( "1003", 3425 ); // first argument must be integer
DRVDATA( 1003, "G21h" ); // if second argument is string type, must be
hexadecimal format ("xxxh", x=0~F)
DRVDATA( 1003, "3425" ); // if second argument is string type, must be
hexadecimal format ("xxxh", x=0~F)
DRVDATA( 1003, "0D61h" ); // if second argument is string type, must be
hexadecimal format ("xxxh", x=0~F)
// alarm COR-016
DRVDATA( 1003, "DFFh" ); // drive is not suupot this status No.
// return VACANT
DRVDATA( 9999, "D61h" ); // no drive corresponding to station number
DRVDATA( 9999, "DFFh" ); // if no drive corresponding to station number,
will not check the status variables No.
22 Call sub-Program
22.1 Calling Methods
Syntax Explanation Calling Local Variable Example
Type
M98 P_ H_ Call sub-program Sub- Inherit the local variables #1~#400 M98 P10 L2;
L_ program from main/parent program
P_Sub-program Explanation:
Name
Call O0010 twice
H_Starting of block
sequence No.
L_Repeated
Counts
M198 P_ H_ Call sub-program Sub- Inherit the local variables #1~#400 M198 P10 L2;
L_ program from main/parent program
P_Sub-program Explanation:
( If M198 is Name
Call O0010 twice
not logged
H_Starting of
in Pr3601~)
block sequence
No.
L_Repeated
Counts
G65 P_L_ Call Single Macro Macro Create new local variables G65 P10 Lw X10.0
#1~#400, and #1~#26 records the Y10.0
P_Subroutine
corresponding argument in the
Name Explanation:
calling block
L_Repeated Call O0010 twice, and
Counts input argument
G66 P_L_ Use movement Mode Create an independent section of G66 P10 X10.0 Y10.0;
instruction to call Macro #1~#400 each time G66 is called.
X20.
mode macro Local variables in this section will
be shared until executing G67. Y20.
P_Subroutine
After executing G67, local variables
Name Explanation:
in this section will be retrieved and
L_Repeated cleared. Moving instructions
Counts X20. and Y20. call
Note:
O0010, and input
The local variables in the section arguments X10.0,
are shared with sub-program Y10.0.
called by P argument (G66 P) only.
They are different from the local
variables in the program where
G66/G66.1 is called.
G66.1 P_ L_ Each block calls Mode The same as G66. G66.1 P10 X10.0
mode macro Macro
X20.
P_Sub-program
G04 X2.
Name
M30
L_Repeated
Counts Explanation:
Each block calls
O0010 and input
argument X10.0.
G_L_ Call expansion G Macro Create a new section of local G128 L3 X1.0
Code. variables #1~#400 each calling,
Explanation:
and restore local variables in main
L_Repeated
program when the Macro is Call G0128 three
Counts
finished. times.
Notes:
• If L argument above isn’t assigned, the default value is 1.
• The life cycle of local vaiables (#1~#400) in above form, please refer to Macro Variable Specification.
Example of Variable Life Cycle:
23 Variable Specification
For the explanation of # and @ variable, please refer to Macro Variable Specification.
26 Appendix
26.1 Macro User Guide
26.1.1 Preface
• The built-in G, T, M code may not satisfy demand from all walks of life, so Syntec Corp. provides
"customizing macro" for customer.
Developer is able to, according to the machine properties, develop macros with special actions, which
greatly promotes the machine value.
• Before introduction, the methods of calling other programs in main program are as below:
• Call sub-program: execute sub-program, while reading or occupying argument is forbidden.
• Call macro: execute macro, while reading and occupying argument is allowed.
• For argument definition please refer to Argument Explanation.
• The following sections introduces related specification of macro, and the specification of calling sub-
program will be skipped.
Appendix – 168
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
G200.010
G200.100 G200100
Appendix – 169
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Appendix – 170
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Appendix – 171
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T Effe
y ct
p
e
G Call
6 assi
6 gne
. d
1 pro
gra
m
thro
ugh
mac
ro
whe
n ev
ery
bloc
k is
finis
hed
.
● Must
be the last
G code in
that row.
Appendix – 172
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T Call T1000 Pr3215 Enable T • File name can only be T0000, other file names are not T0000
Co file through code call mode allowed.
de macro. must be 2. • No file extension.
Ma
cr Pr Type
o 3
2
1
5
0 • T
cod
e
sup
ple
men
tary
cod
e
• doe
s
not
call
T00
00
1 • Call
T00
00
thro
ugh
sub-
pro
gra
m.
• Doe
s
not
read
and
occ
upy
any
argu
men
t
Appendix – 173
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Pr Type
3
2
1
5
2 • Call
T00
00
thro
ugh
mac
ro.
• Rea
d
and
occ
upy
any
argu
men
t
M Different • M code must • The beginning of file name must be letter M. • M00
co from M be logged in • No file extension. 00~
de code, M Pr3601~3610 • The file name must be "M+4 digit number". The 4 digit M99
Ma code macro "M code number corresponds to M code macro instruction. 99
cr calls MACRO call • Example • If
o correspondi registry". the
ng M code • Following M File Name Pr 3601 Calling Instruction nu
macro file code is mb
through standard M er is
macro. code and M0123 123 • M123 out
can’t be • M0123 of
logged as M the
code macro. ran
ge,
M M M file
00 30 98 is
not
gua
M M M ran
01 96 99 tee
d to
M M wor
02 97 k
nor
mal
ly.
Appendix – 174
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Example_Main
1 // Main
2 G90;
3 G01 X10. F100.; // X Axis moving by G01 result X=10.
4 G200; // X Axis moving by G200 result X=20.
5 X-20.; // X Axis moving by G01 result X=-20.
6 M30;
Example_G0200
1 // G0200
2 %@MACRO
3 #101 := #1000; // Backup #1000, G00/G01/G02/G03/G33/G34/G35
4 #102 := #1004; // Backup #1004, G90/G91
5 G91 G00 X10.; // X coordinate increase in increment of 10 by
G00. result X=20.;
6 G#101; // Restore #1000, G00/G01/G02/G03/G33/G34/G35
7 G#102; // Restore #1004, G90/G91
8 M99; // Return to main program
Appendix – 175
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
• Example:
• In main program, system executes G201 to cut a 10*10 cm square.
• In main program, system executes G201 to cut a 20*20 cm square.
• In main program, system executes G202 to cut a square, length of edge of which is decided by
argument.
Example_Main
1 // Example002_Main
2 G90 G00 X0. Y0.;
3 G200;
4 G201;
5 G202 X30.;
6 M30;
Example_G0200
1 // G0200
2 %@MACRO
3 #101:=#1000;
4 #102:=#1004;
5 G91 G01 X10.;
6 G91 G01 Y10.;
7 G91 G01 X-10.;
8 G91 G01 Y-10.;
9 G#101;
10 G#102;
11 M99;
Example_G0201
1 // G0201
2 %@MACRO
3 #101:=#1000;
4 #102:=#1004;
5 G91 G01 X20.;
6 G91 G01 Y20.;
7 G91 G01 X-20.;
8 G91 G01 Y-20.;
9 G#101;
10 G#102;
11 M99;
Appendix – 176
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Example_G0202
1 // G0202
2 %@MACRO
3 #101:=#1000;
4 #102:=#1004;
5 #103:=#24;
6 G91 G01 X#103;
7 G91 G01 Y#103;
8 G91 G01 X-#103;
9 G91 G01 Y-#103;
10 G#101;
11 G#102;
12 M99;
A #1 J #5 S #19
B #2 K #6 T #20
C #3 L #12 U #21
D #7 M #13 V #22
E #8 N W #23
F #9 O X #24
G P #16 Y #25
I #4 R #18
Instruction
Appendix – 177
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Axis XYZ As long as one of the arguments is • B code is defined by Pr3806 Second
Argume occupied by a macro, other axis auxiliary code
ABC
nt arguments are also occupied by that
IJK macro. Pr380 Type Explanation
6
UVW
0 Axis
Argument
Appendix – 178
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Conditio FSTDE Compared to axis argument, condition • T code is defined by Pr3215 Enable T
n HPQR argument is independent from each code call mode.
Argume MB other. If one of the condition argument is
nt occupied, only that one is occupied Pr32 Type Explanation
instead of all condition arguments. 15
Appendix – 179
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
0 Axis
Argument
Special L L argument is setting up macro repeated T code macro do not read L code.
Argume counts.
As a result, no matter what L code value is,
nt
• For example: G200 L10, it means G200 T code macro always execute once.
will continuously execute ten times.
• Even if the user doesn’t input L
argument when calling the macro, the
system will automatically fill in L=1 to
let macro execute once.
Appendix – 180
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T code macro
3 S code
4 F code
5 H code
6 D code
7 T code
8 M code
9 B code
Appendix – 181
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
• Normally, the interpreting order also represents the order of occupying argument, which means "the macro
interpreted first occupies the arguments first."
Nonetheless, this is not absolutely right, because the occupying order also depends on macro
characteristics.
Some macros are interpreted first but executed last. Hence, this situation does not comply to the rule,
"earlier interpreted, earlier occupying."
• Example:
a. Function G code is interpreted earlier than interpolation G code is, so function G code occupies axis
argument first.
Even though interpolation G code is on the left to the function G code in the same block, function G
code still occupies axis argument earlier.
b. In table above, interpreting order of both M code macro and T code macro are level 2,
which means if if T code and M code are in the same row,
interpreting order depends on the sequence, the code on the left is interpreted first.
Condition Character Argument reading and occupation Multi same code instruction in a row
T code macro • Pr3215 Enable T code call mode. This parameter is set up as
2. After rebooting, system regard T code as T code macro.
• If T code is considered T code macro, it only executes T code
macro if T argument (#20) is not occupied.
Appendix – 182
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Condition Character Argument reading and occupation Multi same code instruction in a row
Category Character
T code macro • T code updates different variables according to the type of T code. Following are
corresponding updating rules.
T code condition update #1036 #20 R value
Macro O X X
Sub-program O X X
Auxiliary Code O X O
Argument X O X
• If user want to capture T code value in a T code macro, please use T code
variable (#1036).
• If user want to capture T code value in other macros, please use T argument
(#20).
• Only when T code is auxiliary code, the corresponding R value of T code will be
updated. If T code is used as macro or argument, the corresponding R value of T
code is not updated.
Appendix – 183
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Category Character
M code macro • M code updates different variable according to the type of M code. Following are
corresponding updating rules.
T code condition update #13 R value
Macro O X
Auxiliary Code X O
Argument O X
• #13 is updated in M code macro or argument. Please note that this is different
from specification of T code.
• Only when M code is auxiliary code, the corresponding R value of M code will be
updated. If M code is used as macro or argument, the corresponding R value of M
code is not updated.
Condition Character Argument reading and occupation Multi same code instruction in a row
G code and G • While executing G code macro, argument read by G code macro is occupied.
code macro • If axis argument is read, all axis arguments are occupied simultaneously.
T code macro • While executing T code macro, system read arguments which are needed to. No
matter whether argument is occupied or not.
• After executing T code macro, all arguments read by T code macro are occupied. If
axis argument is read, all axis arguments are occupied simultaneously.
• Repeated count of T code macro is not defined by L code, and T code macro always
executes only one time.
• The L code argument (#12) is not read by system, even if there is one in T code macro.
System just puts 1 into #12.
Appendix – 184
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
M code macro • After executing M code macro, system occupies all arguments which are read by M
code macro.
• If M code macro doesn’t read T argument, then after finishes executing M code
macro, T argument is not occupied.
• If M code macro reads T argument, then after finishes executing M code macro,
T argument is occupied.
Condition Character Argument reading and occupation Multi same code instruction in a row
Appendix – 185
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T • If multi T code macros are in the same row. Each T code is interpreted sequentially and each T code macro can read ar
c
o
d
e
m
a
cr
o
M • If multi M code macro are in the same row, only the first M code macro is interpreted.
c • Pr3810 Parallel executing multiple M code in one block is for auxiliary M code not M code macro. Hence, even if Pr3810
o
d
e
m
a
cr
o
Condition Character Argument reading and occupation Multi same code instruction in a row
Appendix – 186
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Main
1 // Main
2 G200 A1 B2 C3 D7 E8 F9 H11 I4 J5 K6 L12 M13 P16 Q17 R18 S19 T20 U21
V22 W23 X24 Y25 Z26;
3 M30;
G0200
1 // G0200
2 %@MACRO
3
4 //Axis Argument
5 @101 := #1; // A
6 @102 := #2; // B
7 @103 := #3; // C
8 @104 := #4; // I
9 @105 := #5; // J
10 @106 := #6; // K
11 @121 := #21; // U
12 @122 := #22; // V
13 @123 := #23; // W
14 @124 := #24; // X
15 @125 := #25; // Y
16 @126 := #26; // Z
17
18 //Condition Argument
19 @107 := #7; // D
20 @108 := #8; // E
Appendix – 187
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
21 @109 := #9; // F
22 @111 := #11; // H
23 @113 := #13; // M
24 @116 := #16; // P
25 @117 := #17; // Q
26 @118 := #18; // R
27 @119 := #19; // S
28 @120 := #20; // T
29
30 //Special Argument
31 @112 := #12; // L
32
33 M00; // Switch the screen to [Diag.] →
[Display Global] and [Display Coord.]
34 WAIT();
35 M99;
02_Repeated argument
• Only the last repeated argument is read.
• Because same argument put value into the same # variable, the last one overrides the previous one.
Main
1 // Main
2 G01 X0.;
3 G200 X10. X-10.; // X argument has been written twice, only X-10
is read by G200
4 // #24 is input 10 by X10 first
5 // then input -10 by X-10.
6 // G01 will be executed after completing G200,
7 // because G01 can't read any argument X which
is occupied by G200
8 M30;
G0200
1 // G0200
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // The #24 is -10.
5 G01 X#101; // Move to X-10.
6 M00;
7 WAIT();
8 G#100; // Restore to interpolation mode
9 M99;
Appendix – 188
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 X10. Y20. Z30.; // Though G200 only reads X
argument
4 // Y, Z arguments are also
occupied
5 // G01 will be executed after
completing G200
6 // because G01 can't read any
argument which is occupied by G200
7 G01 X0. Y0. Z0. F100.;
8 G201 P20. X10. Y20. Z30. F200.; // Since G201 only reads P
argument
9 // X, Y, Z, F arguments are not
occupied
10 // G01 will be executed after
completing G201 and
11 // read X10. Y20. Z30. F200.
12 // , and then execute the
corresponding actions
13 M30;
G0200
1 // G0200
2 %@MACRO
3 @1:=#24; // Only reads X argument
4 M00;
5 WAIT();
6 M99;
G0201
1 // G0201
2 %@MACRO
3 @1:=#16; // Only reads P argument
4 M00;
5 WAIT();
6 M99;
Appendix – 189
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 X10. Y20. Z30. H40.; // G200 only reads H argument
4 // H argument is a condition
argument
5 // G01 will be executed after
completing G200.
6 // G01 read and occupy X10. Y20.
Z30.
7 // and then execute the
corresponding actions
8 M30;
G0200
1 // G0200
2 %@MACRO
3 #101 := #11; // Only reads H argument
4 M00;
5 WAIT();
6 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 X10. Y20. Z30. H40.; // G200 only reads H argument
4 // Since Pr3809=1, the H
argument is regarded as both axis argument and condition argument
5 // However, it is occupied as a
condition argument in MACRO
6 // G01 is executed after
completing G200
Appendix – 190
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
G0200
1 // G0200
2 %@MACRO
3 #101 := #11; // only reads H argument
4 M00;
5 WAIT();
6 M99;
• When reading axis arguments in MACRO, all the axis arguments will be occupied if one of them is occupied.
• As a result, the axis argument of H argument is occupied as well.
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 X10. Y20. Z30. H40.; // G200 only reads X argument
4 // Since Pr3809=1, the H
argument is regarded as both axis argument and condition argument
5 // The axis argument of H
argument is also occupied
6 // G01 will be executed after
completing G200
7 // G01 can't read any argument
since the axis arguments are all occupied by G200.
8 // The axis argument of the H
argument is also included and won't be read.
9 M30;
G0200
1 // G0200
2 %@MACRO
3 #101 := #24; // Only reads X argument
4 M00;
5 WAIT();
Appendix – 191
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
6 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 X10. Y20. Z30. B40.; // G200 only reads B argument
4 // Since Pr3806=0, B argument is
regarded as an axis argument
5 // X, Y, Z arguments is occupied
by G200
6 // G01 is executed after
completing G200
7 // and G01 can't read any
argument since all arguments are occupied by G200
8 M30;
G0200
1 // G0200
2 %@MACRO
3 #101 := #2; // Only reads B argument
4 M00;
5 WAIT();
6 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 X10. Y20. Z30. B40.; // G200 only reads B argument
4 // Since Pr3806=1, B argument is
seen as a condition argument
5 // X, Y, Z arguments are not
occupied by G200
6 // G01 is executed after
completing G200
Appendix – 192
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
G0200
1 // G0200
2 %@MACRO
3 #101 := #2; // Only reads B argument
4 M00;
5 WAIT();
6 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 G201 X10. P20.; // Since 2 G code macros are written in
the same line
4 // only the last G code macro is able to
read the argument
5 // Though G201 didn't read the X
argument
6 // G200 still can't read the X argument,
because X argument is axis argument
7 // G201 is executed after completing
G200, and
8 // G01 is be executed after G201 read
and occupied P argument
9 // G01 reads and occupies X10., and
10 // then executes the corresponding
actions
11 M30;
Appendix – 193
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
G200
1 // G0200
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101:=#24; // Read X argument which is unable to be
read
5 G01 X#101; // Since #101 has no value, this line
won't be executed
6 G01 X0.; // This line will be executed
7 M00;
8 WAIT();
9 G#100; // Restore interpolation mode
10 M99;
G201
1 // G0201
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101:=#16; // Read P argument which is able to be
read
5 G01 X#101; // This line will be executed
6 G01 X0.;
7 M00;
8 WAIT();
9 G#100; // Restore interpolation mode
10 M99;
Main
1 // Main
2 G90;
3 G00 X0. Y0. Z0.; // G00, spindle moves to X0 Y0 Z0
4 G200 G01 X10. F100.; // Since 2 G codes are in the same line.
5 // only the last G code can read the
argument
6 // G200 is executed but no arguments are
read
Appendix – 194
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
G200
1 // G0200
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Read X argument but it's unable to
read
5 G#100 X#101 F#9; // This line is not executed since #101
has no value. However, since #100=0, the interpolation mode changes
to G00.
6 M00;
7 WAIT();
8 M99;
G201
1 // G0201
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Read X argument and read X=10.
5 G#100 X#101 F#9; // Because #100 = 1, system executes
G01.
Appendix – 195
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
6 M00;
7 WAIT();
8 M99;
G202
1 // G0202
2 %@MACRO
3 M00;
4 WAIT();
5 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 T01 X10. Y20. Z30.; // T argument is not occupied and Pr3215=2,
so
4 // system executes T code macro
5 // With X argument being read in T code
macro,
6 // Y, Z arguments are occupied by T code
macro because all of them are axis arguments.
7 // G01 is executed after completing T01
8 // G01 can't read any argument since the
arguments in the line are all occupied by T coda macro.
9 M30;
T0000
1 // T0000
2 %@MACRO
3 #101 := #24; // only reads X argument
4 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
5 // Observe #20/#1036/#101
6 WAIT();
7 M99;
Appendix – 196
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 T01 G200 X10. Y20. Z30. F1000; // According to the
interpretation order, G code macro is interpreted first.
4 // There is a T argument read in
G code macro (G0200), so
5 // T argument is occupied and T
code macro is not executed.
6 // G01 is executed after
completing G code macro (G0200).
7 // G01 reads and occupies X10.
Y20. Z30. F1000, and
8 // executes the corresponding
actions
9
10 T02 G201 X10. Y20. Z30. F1000.; // According to the
interpretation order, G code macro is interpreted first.
11 // There is no T argument read
in G code macro (G0201), so
12 // T argument is not occupied,
and
13 // T code macro is executed
after G code macro (G0201) is completed
14 // Because T02 reads all
arguments, G01 can't read any argument
15 M30;
G0200
1 // G0200
2 %@MACRO
3 #101 := #20; // Only reads T argument
4 M00;
5 WAIT();
6 M99;
Appendix – 197
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T0000_01
G0201
1 // G0201
2 %@MACRO
3 #101 := #24; // Only reads X argument
4 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
5 WAIT();
6 M99;
T0000_02
1 // T0000
2 %@MACRO
3 #201 := #1000;
4 #202 := #1004;
5 #101 := #24;
6 #102 := #25;
7 #103 := #26;
8 #104 := #9;
9 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
10 WAIT();
11 G91 G01 X#101 Y#102 Z#103 F#104; // T code macro can still read
the arguments and execute the corresponding actions
12
Appendix – 198
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
13 G#201;
14 G#202
15 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 T01 L2; // Though T0000 reads #12,
4 // #12 is equal to "1", not "2" given by L argument
5 // Execute G01 after completed T01
6 // G01 reads and occupies L2, and
7 // executes the corresponding actions (G01 L2 is
meaningless)
8 M30;
T0000
1 // T0000
2 %@MACRO
3 #101 := #12; // Only reads L argument
4 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
5 WAIT();
6 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 T01 T02 X10. Y20. Z30.; // This line is executed twice
4 // T01 is executed first then T02
Appendix – 199
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T0000_T01
1 // T0000_T01
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Read X argument
5 #102 := #25; // Read Y argument
6 #103 := #26; // Read Z argument
7 IF #1036 = 1 THEN // T01 → #1036=1
8 G01 X#101; // X axis moving
9 G01 X0.;
10 END_IF;
11
12 IF #1036 = 2 THEN // The section is not executed
13 G01 Y#102;
14 G01 Y0.;
15 END_IF;
16
17 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
18 WAIT();
19 G#100; // Restore interpolation mode
20 M99;
T0000_T02
1 // T0000_T02
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Read X argument
5 #102 := #25; // Read Y argument
6 #103 := #26; // Read Z argument
7 IF #1036 = 1 THEN // The section is not executed
8 G01 X#101;
9 G01 X0.;
10 END_IF;
11
12 IF #1036 = 2 THEN // T02 → #1036=2
Appendix – 200
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Main
1 // Main
2 G01 X0. Y0. Z0. F100.;
3 M123 X10. Y20. Z30. F300.; // No M argument and no axis argument is
occupied, so
4 // M code macro M0123 is executed.
5 // While M code macro is executed, aside
from the arguments read by the M code macro,
6 // all other arguments are occupied as
well except T argument.
7 // Though the F argument is not read by
M0123, it is occupied, then the feedrate is not updated.
8 // G01, executed after completing M123,
9 // can't read any argument since the
arguments are all occupied.
10
11 G01 X0. Y0. Z0.; // The F in this line is F100, since the
argument in previous line is occupied by M code macro
12 M30;
M0123
1 // M0123
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Read X argument
5 #102 := #25; // Read Y argument
Appendix – 201
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G1301 M1301 X10. Y20. Z30. P2 F1000.; // G code macro is
interpreted first.
4 // The M argument is read by
G code macro (G1301)
5 // The M argument is
regarded occupied, M code macro is executed.
6 // Since the X, Y, Z
arguments is not occupied by G code macro (G1301).
7 // G01 is executed after
completing the G code macro (G1301).
8 // G01 reads and occupies
X10. Y20. Z30. P2 F1000., and
9 // then executes the
corresponding instructions.
10
11 G1302 M1301 X10. Y20. Z30. F1000.; // G code macro is
interpreted first
12 // Only P argument is read
by G code macro (G1302)
13 // The M argument is
regarded unoccupied, and
14 // no other axis arguments
are occupied
15 // The M code macro is
executed after completing the G code macro (G1302)
Appendix – 202
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
G1301
1 // G1301
2 %@MACRO
3 #101 := #13; // Only reads M argument
4 M00;
5 WAIT();
6 M99;
M1301_01
G1302
1 // G1302
2 %@MACRO
3 #101 := #16; // Only reads P argument
4 M00;
5 WAIT();
6 M99;
M1301_02
1 // M1301
2 %@MACRO
3 M00;
4 WAIT(); // The program does not read any argument
Appendix – 203
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
16_G code macro and M code macro are in the same line, and G code macro reads and
occupies axis argument.
• If Pr3601~3610 M code Macro call registry is set to 123, M0123 is registered as M code macro.
• When G code macro and M code macro are written in the same line, G code macro is interpreted before M
code macro.
• If axis arguments are occupied by G code macro, M code macro is not executed.
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G200 M123 X10. Y20. Z30.; // G code macro is interpreted first
4 // Because X argument is read by G code
macro (G0200),
5 // all axis arguments are occupied by
G200.
6 // M code macro therefore is executed
since axis arguments are occupied.
7 // G01, executed after completing G code
macro (G0200),
8 // can't read any argument since the
arguments in the line are all occupied
9 M30;
G0200
1 // G0200
2 %@MACRO
3 #101 := #24; // Only reads X argument
4 M00;
5 WAIT();
6 M99;
M0123
Appendix – 204
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
7 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 M123 M124 X10. Y20. Z30.; // M123 is interpreted first, and only
M123 is executed.
4 // X10. Y20. Z30. are read by M code
macro (M0123)
5 // All arguments except T are occupied
after executing the M code macro.
6 // G01, executed after completing M code
macro,
7 // can't read any argument since the
arguments are all occupied.
8 M30;
M0123
1 // M0123
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Read X argument
5 #102 := #25; // Read Y argument
6 #103 := #26; // Read Z argument
7 G00 X#101 Y#102 Z#103; // G00 moving along X, Y, Z axis
8 M00;
9 WAIT(); // Switch the screen to [Diag.] →
[Display Global] and [Display Coord.]
10 // User should found #13=124
11 // Since M124 is regarded as an
argument, which overwrote #13
12 G#100; // Restore interpolation mode
13 M99;
M0124
Appendix – 205
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
2 // M0124
3 %@MACRO
4 #101 := #24;
5 M00;
6 WAIT();
7 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 T01 M1601 X10. Y20. Z30.; // According to the interpreting order,
T01 is interpreted first, then M1601.
4 // No argument is occupied by T code
macro, so M code macro (M1601) executes X=10.
5 // Although M code macro (M1601) does
not read any argument,
6 // all the arguments except T are
occupied
7 // G01, executed after completing M code
macro (M1601),
8 // can't read any argument since the
arguments are all occupied.
9
10 M1602 T02 X10. Y20. Z30.; // According to the interpreting order,
M1602 is interpreted first.
11 // M code macro (M1602) does not reading
any argument.
12 // Because M code macro (M1602) occupies
all arguments except T,
13 // T code macro (T0000_02) is able to be
executed since T argument is not occupied by M code macro.
14 // G01, executed after completing T code
macro,
15 // can't read any argument since the
arguments in the line are all occupied
16
17 M1603 T03 X10. Y20. Z30.; // According to the interpreting order,
M1603 is interpreted first.
18 // M code macro (M1603) only reads the T
argument
Appendix – 206
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T0000_01
1 // T0000
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #1004; // Backup absolute/increment command mode
5
6 G91 G00 X10.; // X axis moving in increment of 10.
7
8 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
9 WAIT();
10 G#100; // Restore the interpolation mode
11 G#101; // Restore the absolute/increment command mode
12 M99;
M1601
1 // M1601
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #1004; // Backup absolute/increment command mode
5
6 G91 G00 Y10.; // Y axis moving in increment of 10.
7
8 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
9 WAIT();
10 G#100; // Restore the interpolation mode
11 G#101; // Restore the absolute/increment command mode
12 M99;
M1602
1 // M1602
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
Appendix – 207
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T0000_02
1 // T0000
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #1004; // Backup absolute/increment command mode
5
6 G91 G00 X10.; // X axis moving in increment of 10.
7
8 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
9 WAIT();
10 G#100; // Restore the interpolation mode
11 G#101; // Restore the absolute/increment command mode
12 M99;
M1603
1 // M1603
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #1004; // Backup absolute/increment command mode
5 #102 := #20; // Read data of #20, the line will occupy the T
argument
6
7 G91 G00 Y10.; // Y axis moving in increment of 10.
8
9 M00; // Switch the screen to [Diag.] → [Display
Global] and [Display Coord.]
10 WAIT();
11 G#100; // Restore the interpolation mode
12 G#101; // Restore the absolute/increment command mode
13 M99;
Appendix – 208
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
T0000_03
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G65 P1 X10. Y20. Z30.; // Execute O0001
4 M30;
O0001
1 // O0001
2 %@MACRO
3 #101 := #24;
4 #102 := #25;
5 #103 := #26;
6 M00;
7 WAIT();
8 M99;
Appendix – 209
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
Main
1 // Main
2 G01 X-5. Y-5. Z-5.;
3 G200 G66 P1 X10. Y20. Z30. ; // G200 in this line can't read X
argument
4 G200 X10.; // G200 in this line can read X
argument
5 // There are 2 lines of G01 movement
blocks in G200
6 // G66 P1 X10. Y20. Z30. is executed
every time G01 movement block is finished.
7 G67;
8 M30;
G0200_01
1 // G0200_01
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Executing G200 for the first time, G200 can't
read X argument, so
5 G01 X#101; // this line is not executed.
6 G01 X0.;
7 M00;
8 WAIT();
9 G#100; // Restore the interpolation mode
10 M99;
G0200_02
1 // G0200_02
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Executing G200 for the second time, G200 is
able to read X argument, so
5 G01 X#101; // this line is executed
6 // This line is a movement block, after
finished, G66 P1 X10. Y20. Z30. is executed.
7 G01 X0.; // This line is a movement block, after
finished, G66 P1 X10. Y20. Z30. is executed.
8 M00;
9 WAIT();
10 G#100; // Restore the interpolation mode
11 M99;
Appendix – 210
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
O0001
1 // O0001
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24;
5 #102 := #25;
6 #103 := #26;
7 G91 G01 X#101 Y#102 Z#103;
8 M00;
9 WAIT();
10 G#100; // Restore the interpolation mode
11 M99;
Main
1 // Main
2 G01 X-5. Y-5. Z-5.;
3 G66.1 P1 X10. Y20. Z30. ;
4 G200 X10.; // G200 in this line can read the X
argument
5 // G66.1 P1 X10. Y20. Z30. is executed
every time the block in G200 is executed.
6 G67; // G66 P1 X10. Y20. Z30. is executed
after this block is executed
7 M30;
G0200
1 // G0200
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #24; // Executing G200 for the second time, G200 is
able to read X argument
5 G01 X#101; // This line is executed
6 // G66 P1 X10. Y20. Z30. is executed after this
block is executed
7 G01 X0.; // G66 P1 X10. Y20. Z30. is executed after this
block is executed
8 M00; // G66 P1 X10. Y20. Z30. is executed after this
block is executed
9 WAIT(); // This line is not a block
Appendix – 211
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
O0001
1 // O0001
2 %@MACRO
3 #100 := #1000; // Backup interpolation mode
4 #101 := #1004; // Backup absolute/increment command mode
5 #111 := #24;
6 #112 := #25;
7 #113 := #26;
8 G91 G01 X#111 Y#112 Z#113;
9 M00;
10 WAIT();
11 G#100; // Restore the interpolation mode
12 G#101; // Restore the absolute/increment command mode
13 M99;
Main
1 // Main
2 G01 X0. Y0. Z0.;
3 G65 P1 X10. Y20. Z30. G200; // Alarm COR-013 shows up owing to wrong
syntax in this line, because
4 // G65 and G200 are in the same line
5 // but G65 is not the last G code.
6 M30;
G0200
1 // G0200
2 %@MACRO
3 #101 := #24;
4 M00;
5 WAIT();
Appendix – 212
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
6 M99;
O0001
1 // O0001
2 %@MACRO
3 #101 := #24;
4 #102 := #25;
5 #103 := #26;
6 M00;
7 WAIT();
8 M99;
-> The customized HMI first outputs the the user-defined contents to an xml file, and save the xml file to
the GNCFILES file path of which is assigned by user (refer to Pr3219).
The syntax format is defined as below,:
<?xml version="1.0" encoding="UTF-16"?>
<CycleFile>
<Cycle Name="Cycle_HerdonProg"> ← The beginning of first data
<Field Name="Col_Y" Value="17.63"/>
<Field Name="Col_Z" Value="12.98"/>
<Field Name="Col_X" Value="0.00"/>
<Field Name="Col_A" Value="267.54"/>
Appendix – 213
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
-> User have to write the configuration file of XML file by their own.
Configuration file( schema file ) defines the data to be read and the variable where data is put while
DBLOAD is used.
The syntax format is defined as below, and the configuration file should be saved in OCRes\\Common\
\Schema\\
If Dipole is enable, the schema file should be in the folder OCRes\\Common\\Schema\\ in controller.
Appendix – 214
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
<Name>Col_Y</Name>
<InputStorage>@1201</InputStorage> ←The variable Col_Y saves in
<InputFormat>Variant</InputFormat>
<DefaultValue></DefaultValue>
</Field>
<Field>
<Name>Col_Z</Name>
<InputStorage>@1202</InputStorage> ←The variable Col_Z saves in
<InputFormat>Variant</InputFormat>
<DefaultValue></DefaultValue>
</Field>
<Field>
<Name>Col_A</Name>
<InputStorage>@1203</InputStorage> ←The variable Col_A saves in
<InputFormat>Variant</InputFormat>
<DefaultValue></DefaultValue>
</Field>
<Field>
<Name>Col_B</Name>
<InputStorage>@1204</InputStorage> ←The variable Col_B saves in
<InputFormat>Variant</InputFormat>
<DefaultValue></DefaultValue>
</Field>
<Field>
<Name>Col_C</Name>
<InputStorage>@1205</InputStorage> ←The variable Col_C saves in
<InputFormat>Variant</InputFormat>
<DefaultValue></DefaultValue>
</Field>
</Cycle>
</Schema>
Appendix – 215
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
( blank,
grey selection )
full-width spaces No
( blank, ( blank,
grey selection ) grey selection )
Appendix – 216
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
full-width No
semicolons
( grey ( blank,
selection ) grey selection )
full-width spaces No
( blank, ( grey
grey selection ) selection )
full-width No
semicolons
( grey ( grey
selection ) selection )
ii. Check for unsupported characters
• Full-width space/semicolon suggested troubleshooting method
a. Click Search → Find
b. Enter full-width space/semicolon in Find what
c. Click Find All in Current Document
d. If found, it will appear in the search results
e. Modified to support characters
Appendix – 217
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
N 1 2 3 4 5 6 7 8 9 0
u
P m
r b
e
i r
n
t E A B C D E F G H I J K L M N O P Q R S T U V W X Y
n
a gl a b c d e f g h i j k l m n o p q r s t u v w x y
b is
l h
al
e p
c h
a
h b
a e
r t
O
a
c O ( ! " # $ % & ' ( ) * + , - . / :
t s
t h p
e e a
r r c
( e
s h )
al
f- ; < > = ? @ [ ] \ ^ _ ` { } | ~
w
id
t
h
)
Appendix – 218
机床产品/Machine Tool Products
–
OpenCNC_Macro Development Manual.
U N S S E E E A B B H L V F C S S D
ni U O T T O N C E S T F T F R O I L
C c L H X X T Q K L E
o o
d D D D D N S E C E S E F G R U D
n e C C C C A Y T A M U S S S S S E
t C 1 2 3 4 K N B N B C L
r o
n
o tr
l ol
c
o
d
e
c
h
a
r
t
For details of ASCII characters, please refer to:ASCII
Appendix – 219