Hi Everyone,
I thought I'd post a little program I've written that I hope might be useful for people who like to write g-code manually in an environment (like Mach3) that doesn't support flow-of-control statements (other than cumbersome subroutine calls).
The basic idea is that it's a preprocessor that takes a file with a name like "CAM.txt" and converts it to a modified "CAM.out.txt" in the same directory. CAM.txt can contain standard g-code, enhanced with special for-loop statements. The output file CAM.out.txt will have these statements translated into an explicit form that Mach3 or any other standard interpreter can handle. Here's an example: If CAM.txt contains the following code:
for z, -.1, -.25, -.1
G1Z#z
G1X1
G0X0
end
then the output file will have these lines converted as follows:
G1Z-.1
G1X1
G0X0
G1Z-.2
G1X1
G0X0
The explicit rules:
1. The word "for" (lower-case) is followed first by a variable name, which must consist of lower-case letters and digits, starting with a lower-case letter. Within the loop, the variable is referred to by using #, followed by the name. The preprocessor replaces each such reference with a number.
2. The "for" is followed by a starting value, an end value, and a step, separated by commas. The loop progresses towards the end value, but does not include that value itself. Hence "for x, 1, 2, .5" will cover x=1 and x=1.5 only.
3. After the step value, one may optionally add an additional, final value, that gets included after all the other values are hit. Accordingly "for x, 1, 2, .5, 1.75" covers x=1, x=1.5, and x=1.75.
4. A line containing the word "end" brings the block of code to a close. These loops may nest.
5. The version of Visual Studio this was written with does not permit your original file name to contain spaces (sorry).
Hope a few people find this useful!
I thought I'd post a little program I've written that I hope might be useful for people who like to write g-code manually in an environment (like Mach3) that doesn't support flow-of-control statements (other than cumbersome subroutine calls).
The basic idea is that it's a preprocessor that takes a file with a name like "CAM.txt" and converts it to a modified "CAM.out.txt" in the same directory. CAM.txt can contain standard g-code, enhanced with special for-loop statements. The output file CAM.out.txt will have these statements translated into an explicit form that Mach3 or any other standard interpreter can handle. Here's an example: If CAM.txt contains the following code:
for z, -.1, -.25, -.1
G1Z#z
G1X1
G0X0
end
then the output file will have these lines converted as follows:
G1Z-.1
G1X1
G0X0
G1Z-.2
G1X1
G0X0
The explicit rules:
1. The word "for" (lower-case) is followed first by a variable name, which must consist of lower-case letters and digits, starting with a lower-case letter. Within the loop, the variable is referred to by using #, followed by the name. The preprocessor replaces each such reference with a number.
2. The "for" is followed by a starting value, an end value, and a step, separated by commas. The loop progresses towards the end value, but does not include that value itself. Hence "for x, 1, 2, .5" will cover x=1 and x=1.5 only.
3. After the step value, one may optionally add an additional, final value, that gets included after all the other values are hit. Accordingly "for x, 1, 2, .5, 1.75" covers x=1, x=1.5, and x=1.75.
4. A line containing the word "end" brings the block of code to a close. These loops may nest.
5. The version of Visual Studio this was written with does not permit your original file name to contain spaces (sorry).
Hope a few people find this useful!