This is one of the first projects I completed right after learning to use BASH, AWK and other GNU coreutils. It is a very basic linter type of program for CNC machine code. It is tailored for the specific wireless DNC system I use a Chesterton, so it may or may not be useful for anyone else. This was mostly just an exercise in creating a program. I got some help with the AWK part from a friend and former Linux system administrator.
I created this because so many of the NC program files my shop inherited were full of errors. I had operators approaching me several times a day saying they could not download a program to the machine or the program was setting off machine alarms. More often than not the cause was some missing or extra character and it was really irritating me. So I set out to create this little program that I could run periodically in order to fix any bad programs that were added to the library.
The AWK script in this program checks for and fixes the following errors:
- first char of first line is not transmission marker (
- program address is
- extraneous transmission markers
- leading/trailing whitespace on lines
- open comments
- double-decimals (
- missing address (value without a corresponding address, eg:
- decimal values exceeding 4 digits.
If any errors are found and fixed, the changes made are logged and the modified program files are written to a separate directory where they can be double-checked by a human before replacing the originals. The logs output for each file include a terse error description along with the line numbers where the error appeared. Some “errors”, like leading/trailing spaces, don’t cause any trouble at the machine but they are ugly. For these errors the total number of lines is output instead of unique line numbers.