Creating NC axes
NC axes are created in a defined tree structure under the NC configuration node TINC. The set-up always follows the same pattern: First, an NC task is created; then, the axis node below the task is called. Axes can be created directly under the axis node or in a subfolder. Subfolders help organize the axes in more complex projects.
Requirements
- A TwinCAT solution is open and a DTE connection is active.
ITcSysManagerwas initialized as a COM object in an STA thread.- The NC/drive module is licensed and available in the solution (the
TINCnode is visible).
Creating an NC task and axes
The NC configuration node TINC is accessed via LookupTreeItem. The NC task is then created under this node. The task's axis folder can then be accessed via LookupChild("Axes"). Axes and subfolders are created using CreateChild.
C#:
// Look up NC configuration and create NC task
ITcSmTreeItem motion = sysManager.LookupTreeItem("TINC");
// " SAF" suffix is always appended to the name
ITcSmTreeItem nc = motion.CreateChild("NC-Task", 1, null, null);
ITcSmTreeItem cnc = motion.CreateChild("CNC", 400);
// Look up the axes folder of the NC task
ITcSmTreeItem axesFolder = nc.LookupChild("Axes");
// Create subfolder for axes (SubType -1)
ITcSmTreeItem folder1 = axesFolder.CreateChild("Folder1", -1);
// Create axis (SubType 1)
ITcSmTreeItem axisInFolder = axesFolder.CreateChild("Axis 2", 1, "Folder1/");PowerShell:
$ncConfig = $systemManager.LookupTreeItem("TINC")
$ncConfig.CreateChild("NC-Task", 1)
$axes = $systemManager.LookupTreeItem("TINC^NC-Task^Axes")
$axes.CreateChild("Axis 1", 1)bstrBefore rules for NC nodes
The third parameter of CreateChild is called bstrBefore and controls the position within a folder where the new element will be inserted. A trailing / in the path means “last item in the folder”.
bstrBefore | Meaning |
|---|---|
| Insert as the last item in Folder1. |
| Insert before Axis1 in Folder1. |
| Insert as the last item in Folder2. |
Parameterizing axes
Axis parameters are set via the axis's XML description. The recommended procedure is to first create an axis and then export its current configuration using ProduceXml. The returned XML description serves as a template that can be customized as needed and reimported via ConsumeXml.
C#:
ITcSmTreeItem axis = systemManager.LookupTreeItem("TINC^NC-Task^Axes^Axis 1");
string xmlDescription = axis.ProduceXml();After modifying the XML description, it is written back using ConsumeXml:
axis.ConsumeXml(xmlDescription);
PowerShell:
$axis = $systemManager.LookupTreeItem("TINC^NC-Task^Axes^Axis 1")
$xmlDescription = $axis.ProduceXml()
# Here configuration of the values in the xml needed
$axis.ConsumeXml($xmlDescription)