Linking NC axes to I/O or a PLC

After being created, an NC axis must be linked to an I/O drive so that it can access process data. Two variants are available for this. Variant 1 passes the path to the I/O drive via ConsumeXml using an NcAxisDef element. TwinCAT automatically selects the appropriate PDO mappings. Variant 2 explicitly sets the links for individual process variables using ConsumeMappingInfo, which provides complete control over the mapping.

Requirements

Variant 1: Linking the axis to the I/O drive

get_Child(1) returns the first child of the TINC node – that is, the first NC task. The axis folder is then opened via LookupChild("Axes"). NcAxisDef XML specifies the path to the I/O drive and the channel.

// Look up NC axis
ITcSmTreeItem ncConfig = sysManager.LookupTreeItem("TINC");
// LookupChild("Axes") is more reliable than a path string with a potential SAF suffix
ITcSmTreeItem axesFolder = ncConfig.get_Child(1).LookupChild("Axes");
ITcSmTreeItem ncAxis = axesFolder.LookupChild("Axis 1");

// Variant 1: link axis with I/O drive (source-verified)
string linkXml = @"<TreeItem>
  <NcAxisDef>
    <AxisType>1</AxisType>
    <AxisIoType>CANopen-DS402</AxisIoType>
    <IoItem>
      <PathName>TIID^Device 1 (EtherCAT)^Term 1 (EK1100)^Drive 2 (AX8206-0000-0105)</PathName>
      <Channel>0</Channel>
    </IoItem>
  </NcAxisDef>
</TreeItem>";

ncAxis.ConsumeXml(linkXml);

Variant 2: Explicitly linking individual variables

ConsumeMappingInfo is available starting with ITcSysManager3. The interface is cast to the existing sysManager object. The XML format requires the full tree path to the axis and drive, as well as the variable names for both sides.

// Variant 2: manually link individual variables (ConsumeMappingInfo)
// OwnerA = NC axis, OwnerB = I/O drive
string mappingXml = @"<VarLinks>
  <OwnerA Name=""TICC^CNC^Axes^Axis_1"">
    <OwnerB Name=""TIID^Device 1 (EtherCAT)^Drive 1 (AX5125-0000-0203)"">
      <Link VarA=""Inputs^Drive status word"" VarB=""AT^Drive status word""/>
      <Link VarA=""Inputs^Position feedback 1 value"" VarB=""AT^Position feedback 1 value""/>
      <Link VarA=""Outputs^Master control word"" VarB=""MDT^Master control word""/>
      <Link VarA=""Outputs^Position command value"" VarB=""MDT^Position command value""/>
    </OwnerB>
  </OwnerA>
</VarLinks>";

ITcSysManager3 sysMan3 = (ITcSysManager3)sysManager;
sysMan3.ConsumeMappingInfo(mappingXml);