Drive reference ST_DriveRef
The drive is accessed via a drive reference. Within the library, the ST_DriveRef structure from the Tc2_EtherCAT library is used for this with the NetID as a string. Since the NetID usually exists as a byte array at I/O level, a structure ST_PlcDriveRef, also from the Tc2_EtherCAT library, with the NetID as a byte array is additionally provided. The two structures must be transferred into each other.
Structure ST_PlcDriveRef
TYPE ST_PlcDriveRef :
STRUCT
aNetId : T_AmsNetIdArr; (* AmsNetId (array[0..5] of bytes) of the EtherCAT master device.*)
nSlaveAddr : UINT; (* Address of the slave device.*)
nDriveNo : BYTE; (* Drive number*)
nDriveType : BYTE; (* Drive type*)
END_STRUCT
END_TYPE
Structure ST_DriveRef
TYPE ST_DriveRef :
STRUCT
sNetId : T_AmsNetId; (* AmsNetId (string(23)) of the EtherCAT master device.*)
nSlaveAddr : UINT; (* Address of the slave device.*)
nDriveNo : BYTE; (* Drive number*)
nDriveType : BYTE; (* Drive type*)
END_STRUCT
END_TYPE
Mapping the drive reference to the PLC
The drive reference can be mapped to the PLC in the System Manager. To do this, allocate an instance of the structure ST_PlcDriveRef as AT %I*. Subsequently, link aNetID to netId, nSlaveAddr to port and nDriveNo to Chn0 (A) or Chn1 (B). In the case of multiple-channel drives both channels refer to the same netId and port number, since it is an EtherCAT slave.
Transfer of ST_PlcDriveRef and ST_DriveRef
The function blocks in the library Tc2_Drive use an instance of the structure ST_DriveRef. Unlike the structure ST_PlcDriveRef, NetID is expected to be T_AmsNetId (i.e. STRING(23)). To convert the byte array, use the F_CreateAmsNetId() function of the PLC Lib Tc2_System.
stDriveRef.sNetId := F_CreateAmsNetId(stPlcDriveRef.aNetId);
stDriveRef.nSlaveAddr := stPlcDriveRef.nSlaveAddr;
stDriveRef.nDriveNo := stPlcDriveRef.nDriveNo;
stDriveRef.nDriveType := stPlcDriveRef.nDriveType;