Accessing External Variables from G-Code Programs
- Compass NC can read some amount of data from the PLC using a pre-configured data struct. This data struct includes:
- Data for each axis (status, position, velocity, etc.)
- An array of 100 for DINT type data variables
- An array of 100 for LREAL type data variables
- An array of 100 for BYTE type data variables
- A struct for G31 Skip Move data.
- On the PLC, the global variable name of the struct is NcStateData and it is a retained variable.
- It includes the following members:
- The data accessed from G-Code file is in the PLC member:

-
Below is a an example of variable assignment done on the PLC. It is up to the user to do the assignment mapping.
This completes the variable assignment setup on the PLC side.
- To access the PLC variables in a G-Code file, use them in an assignment or comparison functions.
- Below are a few examples:
-
In the sample G-code tool changer file, at the start of the file the current machine position has to be recorded to command the motion back to the same position after the tool changing sequence was complete:
-
At the start of the file the current axes positions are being read from the PLC and saving them to a set of local variables:
-
At the end of the file, the motion back to the same positions is being commanded:
-
- During the cycle, the status of various sensors has to be checked. A Spindle Loaded sensor is used in this example:
-
Spindle Empty ( PLC.BYTES[0] ):
