40
Manual PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date:

Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Embed Size (px)

Citation preview

Page 1: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Manual

PLC Lib: Tc2_MC2_Drive

TwinCAT

1.02016-05-30

Version:Date:

Page 2: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4
Page 3: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Table of contents

Table of contents1 Foreword .................................................................................................................................................... 4

1.1 Notes on the documentation.............................................................................................................  41.2 Safety instructions ............................................................................................................................  5

2 Overview..................................................................................................................................................... 6

3 Function blocks ......................................................................................................................................... 83.1 AX5000 specific FB ..........................................................................................................................  8

3.1.1 FB_SoEAX5000ReadActMainVoltage ..................................................................................  83.1.2 FB_SoEAX5000SetMotorCtrlWord ....................................................................................... 93.1.3 FB_SoEAX5000FirmwareUpdate ....................................................................................... 103.1.4 FB_SoEAX5000SetPositionOffset ...................................................................................... 13

3.2 General CoE FBs............................................................................................................................  143.2.1 FBs for current values......................................................................................................... 14

3.3 General SoE FB..............................................................................................................................  173.3.1 FB_SoEReset ..................................................................................................................... 173.3.2 FB_SoEWritePassword ...................................................................................................... 193.3.3 Command FB...................................................................................................................... 203.3.4 Diagnosis FB....................................................................................................................... 243.3.5 FB for current values........................................................................................................... 29

3.4 F_GetVersionTcMc2Drive ..............................................................................................................  37

4 Data types ................................................................................................................................................ 384.1 E_FwUpdateState...........................................................................................................................  384.2 E_PositionOffsetMemory ................................................................................................................  394.3 E_PositionOffsetFeedback .............................................................................................................  40

PLC Lib: Tc2_MC2_Drive 3Version: 1.0

Page 4: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Foreword

1 Foreword

1.1 Notes on the documentationThis description is only intended for the use of trained specialists in control and automation engineering whoare familiar with the applicable national standards.It is essential that the following notes and explanations are followed when installing and commissioningthese components.

The responsible staff must ensure that the application or use of the products described satisfy all therequirements for safety, including all the relevant laws, regulations, guidelines and standards.

DisclaimerThe documentation has been prepared with care. The products described are, however, constantly underdevelopment.For that reason the documentation is not in every case checked for consistency with performance data,standards or other characteristics.In the event that it contains technical or editorial errors, we retain the right to make alterations at any timeand without warning.No claims for the modification of products that have already been supplied may be made on the basis of thedata, diagrams and descriptions in this documentation.

TrademarksBeckhoff®, TwinCAT®, EtherCAT®, Safety over EtherCAT®, TwinSAFE®, XFC®and XTS® are registeredtrademarks of and licensed by Beckhoff Automation GmbH.Other designations used in this publication may be trademarks whose use by third parties for their ownpurposes could violate the rights of the owners.

Patent PendingThe EtherCAT Technology is covered, including but not limited to the following patent applications andpatents:EP1590927, EP1789857, DE102004044764, DE102007017835with corresponding applications or registrations in various other countries.

The TwinCAT Technology is covered, including but not limited to the following patent applications andpatents:EP0851348, US6167425 with corresponding applications or registrations in various other countries.

EtherCAT® is registered trademark and patented technology, licensed by Beckhoff Automation GmbH,Germany

Copyright© Beckhoff Automation GmbH & Co. KG, Germany.The reproduction, distribution and utilization of this document as well as the communication of its contents toothers without express authorization are prohibited.Offenders will be held liable for the payment of damages. All rights reserved in the event of the grant of apatent, utility model or design.

PLC Lib: Tc2_MC2_Drive4 Version: 1.0

Page 5: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Foreword

1.2 Safety instructions

Safety regulationsPlease note the following safety instructions and explanations!Product-specific safety instructions can be found on following pages or in the areas mounting, wiring,commissioning etc.

Exclusion of liabilityAll the components are supplied in particular hardware and software configurations appropriate for theapplication. Modifications to hardware or software configurations other than those described in thedocumentation are not permitted, and nullify the liability of Beckhoff Automation GmbH & Co. KG.

Personnel qualificationThis description is only intended for trained specialists in control, automation and drive engineering who arefamiliar with the applicable national standards.

Description of symbolsIn this documentation the following symbols are used with an accompanying safety instruction or note. Thesafety instructions must be read carefully and followed without fail!

DANGER

Serious risk of injury!Failure to follow the safety instructions associated with this symbol directly endangers thelife and health of persons.

WARNING

Risk of injury!Failure to follow the safety instructions associated with this symbol endangers the life andhealth of persons.

CAUTION

Personal injuries!Failure to follow the safety instructions associated with this symbol can lead to injuries topersons.

Attention

Damage to the environment or devicesFailure to follow the instructions associated with this symbol can lead to damage to the en-vironment or equipment.

Note

Tip or pointerThis symbol indicates information that contributes to better understanding.

PLC Lib: Tc2_MC2_Drive 5Version: 1.0

Page 6: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Overview

2 OverviewThis library contains functions and function blocks for SoE drives, which access the drive by MC2 axisstructure (AXIS_REF).

There are three libraries Tc2_Drive, Tc2_NcDrive and Tc2_MC2_Drive. Each of these libraries has itspurpose. The range of functions of the libraries is practically identical. The Tc2_NcDrive and TheTc_MC2_Drive are wrapper function blocks around the function blocks of the Tc2_Drive.

Differences in the use of the Drive libraries with AX5000 and Bosch Rexroth IndraDriveCS should be takeninto consideration. See example below.

Tc2_DriveThe Tc2_Drive should be used when the drive is used completely from the SPS (that is, without NC). To thisend the drive is accessed via a drive reference. See documentation Tc2_Drive. Within the library theST_DriveRef is used with the NetID as a string. However, for linking purposes an ST_PlcDriveRef with theNetID as ByteArray is also provided. See also example with the respective function blocks.

Note: To access parameters in the drive, for which no special function block has been implemented, theFB_SoERead_ByDriveRef and FB_SoEWrite_ByDriveRef function blocks can be used.

Note: The FB_SoERead_ByDriveRef and FB_SoEWrite_ByDriveRef function blocks are, in derogation,implemented in the Tc2_EtherCAT in the SoE-Interface folder, since the general function blocks for CoE andFoE are implemented in Tc2_EtherCAT.

Tc2_NcDriveThe Tc2_NcDrive should be used whenever the drive is used via the NC with the Tc2_Nc libraries. To thisend the drive is accessed via the NC axis structure (NC_TO_PLC), which is also accessed in the functionblocks of Tc2_Nc. The function blocks in the Tc2_NcDrive independently determine the access data to thedrive (NetID, address and channel number) via the NC axis ID from the NC_TO_PLC structure. See examplefor the respective function blocks in the documentation of the Tc2_NcDrive.

Note: To access parameters in the drive, for which no special function block has been implemented, theFB_SoERead and FB_SoEWrite function blocks can be used.

Tc2_MC2_DriveThe Tc2_MC2_Drive should be used whenever the drive is used via NC with the Library Tc2_MC2. To thisend the drive is accessed via the MC2 axis reference (AXIS_REF). The function blocks in theTc2_MC2_Drive independently determine the access data to the drive (NetID, address and channel number)via the NC axis ID from the MC2-Axis reference. See example for the respective function blocks in thedocumentation of the Tc2_MC2_Drive.

Note: To access parameters in the drive, for which no special function block has been implemented, theFB_SoERead and FB_SoEWrite function blocks can be used.

Functions

Name DescriptionF_GetVersionTcMc2Drive [} 37] This function can be used to read PLC library version

information. The function has been replaced by theglobal structure stLibVersion_Tc2_MC2_Drive.

F_ConvWordToSTAX5000C1D See TwinCAT3 PLC Lib:Tc2_Drive documentation.Converts the C1D word (S-0-0011) of the AX5000 toan ST_AX5000_C1D structure.

PLC Lib: Tc2_MC2_Drive6 Version: 1.0

Page 7: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Overview

Function blocks

Name DescriptionFB_SoEReset [} 17] Execute drive reset (S-0-0099)

FB_SoEWritePassword [} 19] Setting drive password (S-0-0267)

FB_SoEReadDiagMessage [} 24] Reading the diagnosis message (S-0-0095)

FB_SoEReadDiagNumber [} 25] Reading the diagnosis number (S-0-0390)

FB_SoEReadDiagNumberList [} 26] Reading the diagnosis number list (up to 30 entries)(S-0-0375)

FB_SoEReadClassXDiag [} 28] Reading the Class 1 diagnosis (S-0-0011) ... Class 3diagnosis (S-0-0013)

FB_SoEExecuteCommand [} 20] Executing a command

FB_SoEWriteCommandControl [} 21] Setting Command Control

FB_SoEReadCommandState [} 22] Checking command status

FB_SoERead [} 29] Reading a parameter

FB_SoEWrite [} 31] Writing a parameter

FB_SoEReadAmplifierTemperature [} 32] Reading the drive temperature (S-0-0384)

FB_SoEReadMotorTemperature [} 34] Reading the motor temperature (S-0-0383)

FB_SoEReadDcBusCurrent [} 35] Reading the Dc-Bus current (S-0-0381)

FB_SoEReadDcBusVoltage [} 36] Reading the Dc-Bus voltage (S-0-0380)

FB_SoEAX5000ReadActMainVoltage [} 8] Reading the mains voltage (P-0-0200)

FB_SoEAX5000SetMotorCtrlWord [} 9] Setting Motor Control Words (P-0-0096)

FB_SoEAX5000FirmwareUpdate [} 10] Automatic firmware update of the AX5000

FB_SoEAX5000SetPositionOffset [} 13] Saving a Positions-Offset

FB_CoERead [} 14] Reading a parameter

FB_CoEWrite [} 16] Writing a parameter

Sample project and sample configuration for AX5000 diagnosisSee http://infosys.beckhoff.com/content/1033/TcPlcLib_Tc2_MC2_Drive/Resources/zip/2327326731.zip

Sample project and sample configuration for IndraDriveCS diagnosisSee http://infosys.beckhoff.com/content/1033/TcPlcLib_Tc2_MC2_Drive/Resources/zip/2327323403.zip

Requests

Component VersionTwinCAT on the development computer 3.1 Build 4016 or higherTwinCAT on the Windows CE-Image 3.1 Build 4016 or higherTwinCAT on the Windows XP-Image 3.1 Build 4016 or higher

PLC Lib: Tc2_MC2_Drive 7Version: 1.0

Page 8: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

3 Function blocks

3.1 AX5000 specific FB

3.1.1 FB_SoEAX5000ReadActMainVoltage

With the FB_SoEAX5000ReadActMainVoltage function block the current peak value of the mains voltage ofthe AX5000 (P-0-0200) can be read.

VAR_INPUTVAR_INPUT    NetId   : T_AmsNetId := '';    Execute : BOOL;    Timeout : TIME := DEFAULT_ADS_TIMEOUT;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT    Busy              : BOOL;    Error             : BOOL;    AdsErrId          : UINT;    SercosErrId       : UINT;    Attribute         : DWORD;    ActualMainVoltage : LREAL;END_VAR

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command.

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

Attribute: Returns the attributes of the Sercos parameter.

PLC Lib: Tc2_MC2_Drive8 Version: 1.0

Page 9: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

ActualMainVoltage: Returns the peak value of the current mains voltage of the AX5000 (e.g. 303.0corresponds to 303.0 V ).

SamplefbReadActMainVoltage : FB_SoEAX5000ReadActMainVoltage;ReadActMainVoltage : BOOL;ActualMainVoltage : REAL;(* NcAxis *)Axis : AXIS_REF; 

IF ReadActMainVoltage THEN fbReadActMainVoltage(    Axis := Axis,    Execute := TRUE,    Timeout := DEFAULT_ADS_TIMEOUT,    ActualMainVoltage=>ActualMainVoltage ); IF NOT fbReadActMainVoltage.Busy THEN    fbReadActMainVoltage(Axis := Axis, Execute := FALSE);    ReadActMainVoltage := FALSE; END_IFEND_IF

3.1.2 FB_SoEAX5000SetMotorCtrlWord

With the FB_SoEAX5000SetMotorCtrlWord function block the ForceLock bit (Bit 0) or the ForceUnlock bitcan be set in the Motor Control Word (P-0-0096) to activate or release the brake. Normally the brake isautomatically handled via the Enable of the drive.

With the ForceLock bit, the brake can be activated independently from the Enable, with the ForceUnlock bit,the brake can be released independently from the Enable. In the case of simultaneously set ForceLock andForceUnlock, ForceLock (Brake activated) has the higher priority.

VAR_INPUTVAR_INPUT    NetId       : T_AmsNetId := '';    Execute     : BOOL;     Timeout     : TIME := DEFAULT_ADS_TIMEOUT;    ForceLock   : BOOL;    ForceUnlock : BOOL;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

ForceLock: Activate brake separately from Enable.

ForceUnlock: Release brake separately from Enable.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

PLC Lib: Tc2_MC2_Drive 9Version: 1.0

Page 10: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT    Busy        : BOOL;    Error       : BOOL;    AdsErrId    : UINT;    SercosErrId : UINT;END_VAR

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command.

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

SamplefbSetMotorCtrlWord : FB_SoEAX5000SetMotorCtrlWord;SetMotorCtrlWord : BOOL;ForceLock : BOOL;ForceUnlock : BOOL;(* NcAxis *)Axis : AXIS_REF; 

IF SetMotorCtrlWord THEN fbSetMotorCtrlWord(    Axis := Axis,    Execute := TRUE,    Timeout := DEFAULT_ADS_TIMEOUT,    ForceLock := ForceLock,    ForceUnlock:= ForceUnlock ); IF NOT fbSetMotorCtrlWord.Busy THEN    fbSetMotorCtrlWord(Axis := Axis, Execute := FALSE);    SetMotorCtrlWord := FALSE; END_IFEND_IF

3.1.3 FB_SoEAX5000FirmwareUpdate

With the FB_SoEAX5000FirmwareUpdate function block the Firmware of the AX5000 can be checked andautomatically changed to a given version (Revision and Build) or to the current Build of the configuredrevision.

For updating:

• the configured slave type is determined, e.g. AX5103-0000-0010• the current slave is determined with the predefined slave address, e.g. AX5103-0000-0009• the current slave firmware is determined, e.g. v1.05_b0009• a comparison of the configuration and the found slave regarding number of channels, current, revision,

firmware is made• the name of the required firmware file is determined and a search for the file performed

PLC Lib: Tc2_MC2_Drive10 Version: 1.0

Page 11: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

• the firmware update (if required) is executed• the current slave with the predefined slave address is determined again• the slave is switched to the predefined EtherCAT state

A successful update ends with eFwUpdateState = eFwU_FwUpdateDone, if the update is not required this issignaled via eFwUpdateState = eFwU_NoFwUpdateRequired. The firmware update occurs via the specifiedchannel (A=0 or B=1) from the stDriveRef. In the case of two-channel devices only one of the two channelscan be used. The other channel signals eFwUpdateState = eFwU_UpdateViaOtherChannelActive or =eFwU_UpdateViaOtherChannel.During the firmware update (eFwUpdateState = eFwU_FwUpdateInProgress) iLoadProgress signals theprogress as a percentage.

CAUTION

During the update the PLC and TwinCAT must not be stopped, the EtherCAT connectionmust not be interrupted and der AX5000 must not be switched off!

VAR_INPUTVAR_INPUTsNetId           : T_AmsNetId;bExecute         : BOOL;    sFirmwareVersion : STRING(20); (* ver-sion string vx.yy_bnnnn, e.g. "v1.05_b0009" for v1.05 Build 0009*)sFirmwarePath    : T_MaxString; (* drive:\path, e.g. "C:\TwinCAT\Io\TcDriveManager\FirmwarePool" *)iReqEcState      : UINT := EC_DEVICE_STATE_OP;tTimeout         : TIME := DEFAULT_ADS_TIMEOUT;END_VAR

sNetId: AMS-NetID of the controller (IPC).

bExecute: The function block is activated by a positive edge at this input.

sFirmwareVersion: Specifies the desired firmware version in the form of vx.yy_bnnnn, e.g. "v1.05_b0009"for Version v1.05 Build 0009.

Release-Builds:

    "v1.05_b0009"    for a specific build, for example v1.05 Build 0009    "v1.05_b00??"    most current build of a predefined version, for example v1.05    "v1.??_b00??"    most current build of a predefined main version, for example v1    "v?.??_b00??"    most current build of the most current version    " "            most current build of the most current version

Custom Firmware-Builds:

    "v1.05_b1009"    for a specific build, for example v1.05 Build 0009    "v1.05_b10??"    most current build of a predefined version, for example v1.05    "v1.??_b10??"    most current build of a predefined main version, for example v1    "v?.??_b10??"    most current build of the most current version

...

    "v1.05_b8909"    for a specific build, for example v1.05 Build 8909    "v1.05_b89??"    most current build of a predefined version, for example v1.05    "v1.??_b89??"    most current build of a predefined main version, for example v1    "v?.??_b89??"    most current build of the most current version

Debug-Builds:

    "v1.05_b9009"    for a specific build, for example v1.05 Build 9009    "v1.05_b90??"    most current build of a predefined version, for example v1.05    "v1.??_b90??"    most current build of a predefined main version, for example v1    "v?.??_b90??"    most current build of the most current version

sFirmwarePath: Specifies the path for the firmware pool in which the firmware files are located, e.g. "C:\TwinCAT\Io\TcDriveManager\FirmwarePool".

PLC Lib: Tc2_MC2_Drive 11Version: 1.0

Page 12: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

iReqEcState: Desired EtherCAT state after the update (only if an update is actually being executed). Thestates are defined in the TcEtherCAT.lib as global constants.

tTimeout: Since the firmware update can take a long time for large EtherCAT networks, only the timeout forindividual internal ADS instances is predefined here.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUTbBusy                 : BOOL;bError                : BOOL;iAdsErrId             : UINT;iSercosErrId          : UINT;iDiagNumber           : UDINT;eFwUpdateState        : E_FwUpdateState;iLoadProgress         : INT;sSelectedFirmware-File : STRING(MAX_STRING_LENGTH); (* found firmware file, e.g. "AX5yxx_xxxx_-0010_v1_05_b0009.efw" *)END_VAR

bBusy: This output is set upon the activation of the function block and remains set until feedback occurs.

bError: This output is set after the bBusy output has been reset when an error occurs in the transmission ofthe command.

iAdsErrId: In the case of a set bError output returns the ADS error code of the last executed command.

iSercosErrId: In the case of a set bError output returns the Sercos error of the last executed command.

iDiagNumber: In the case of a set bError output returns the drive error of the last executed firmware update.

eFwUpdateState: Returns the status of the firmware update. See E_FwUpdateState.

iLoadProgress: Returns the progress of the actual firmware update as a percentage.

sSelectedFirmwareFile: Displays the name of the firmware file being searched for.

SampleVAR CONSTANT iNumOfDrives : INT := 2;END_VAR

VAR fbFirmwareUpdate : ARRAY [1..iNumOfDrives] OF FB_SoEAX5000FirmwareUpdate; Axes : ARRAY [1..iNumOfDrives] OF AXIS_REF; sFirmwareVersion : ARRAY [1..iNumOfDrives] OF STRING(20)(* := 2('v1.04_b0002')*); eFwUpdateState : ARRAY [1..iNumOfDrives] OF E_FwUpdateState; sSelectedFirmwareFile: ARRAY [1..iNumOfDrives] OF STRING(MAX_STRING_LENGTH); iUpdateState : INT; bExecute : BOOL; sNetIdIPC : T_AmsNetId := ''; sFirmwarePath : T_MaxString := 'C:\TwinCAT\Io\TcDriveManager\FirmwarePool’; I : INT; bAnyBusy : BOOL; bAnyError : BOOL;END_VAR 

CASE iUpdateState OF0: IF bExecute THEN    iUpdateState := 1; END_IF1: FOR I := 1 TO iNumOfDrives DO

PLC Lib: Tc2_MC2_Drive12 Version: 1.0

Page 13: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

    fbFirmwareUpdate[I](     Axis := Axes[I],     bExecute := TRUE,     tTimeout := T#15s,     sFirmwareVersion := sFirmwareVersion[I],     sFirmwarePath := sFirmwarePath,     sNetId := sNetIdIPC,     iReqEcState := EC_DEVICE_STATE_OP,     eFwUpdateState => eFwUpdateState[I],    ); END_FOR iUpdateState := 2;2: bAnyBusy := FALSE; bAnyError:= FALSE; FOR I := 1 TO iNumOfDrives DO    fbFirmwareUpdate[I](     Axis := Axes[I],     eFwUpdateState => eFwUpdateState[I],     sSelectedFirmwareFile => sSelectedFirmwareFile[I],    );    IF NOT fbFirmwareUpdate[I].bBusy THEN     fbFirmwareUpdate[I](bExecute := FALSE, Axis := Axes[I]);     IF fbFirmwareUpdate[I].bError THEN        bAnyError := TRUE;     END_IF    ELSE     bAnyBusy := TRUE;    END_IF END_FOR IF NOT bAnyBusy THEN    bExecute := FALSE;    IF NOT bAnyError THEN     iUpdateState := 0; (* OK *)    ELSE     iUpdateState := 0; (* Error *)    END_IF END_IFEND_CASE

3.1.4 FB_SoEAX5000SetPositionOffset

With the FB_SoEAX5000SetPositionOffset function block a Positions-Offset can be saved in the memory ofthe AX5000 or of the digital identification plate of the connected Motor-Encoder.

VAR_INPUTVAR_INPUT   Execute  :  BOOL;   Position :  LREAL;   Relative :  BOOL;   Feedback :  E_PositionOffsetFeedback;   Memory   :  E_PositionOffsetMemory;END_VAR

Execute: The function block is enabled via a positive flank at this input.

Position: New position of the Nc axis

Relative: When this flag is set, the position is relatively interpreted

Feedback: Enumeration of the type E_PositionOffsetFeedback [} 40]. Specifies which feedback isconsidered.

PLC Lib: Tc2_MC2_Drive 13Version: 1.0

Page 14: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

Memory: Enumeration of the type E_PositionOffsetMemory [} 39]. Specifies which memory the newlycalculated Positions-Offset should be stored in.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT   Busy     :  BOOL;   Error    :  BOOL;   ErrorID  :  UDINT;END_VAR

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

ErrorID: In the event of a set error output returns the ADS error code.

3.2 General CoE FBs

3.2.1 FBs for current values

3.2.1.1 FB_CoERead

With the FB_CoERead function block access data from the object directory of an EtherCAT slave can beread out by SDO (Service Data Object). This requires the slave to have a mailbox and to support the"CANopen over EtherCAT" (CoE) protocol. With the help of the SubIndex and Index parameters a selectionis made as to which object should be read out. Via CompleteAccess := TRUE the parameter can be readwith sub-elements.VAR_INPUT   NetId          : T_AmsNetId;(*netID of PC with NC*)   Index          : WORD;(*CoE object index*)   SubIndex       : BYTE;(*CoE sub index*)   pDstBuf        : PVOID;(*Contains the address of the buffer for the received data*)   BufLen         : UDINT;(*Contains the max. number of bytes to be received*)   Execute        : BOOL;(*Function block execution is triggered by a rising edge at this input.*)   Timeout        : TIME := DEFAULT_ADS_TIMEOUT;(*States the time before the function is can-celled.*)   CompleteAccess : BOOL;(*Function block reads the complete object with all sub index*)END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Index: Index of the object that is to be read.

PLC Lib: Tc2_MC2_Drive14 Version: 1.0

Page 15: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

SubIndex: Sub-index of the object that is to be read.

pDstBuf: The address (pointer) of the receive buffer.

BufLen: The maximum available buffer size for the data to be read, in bytes.

Execute: The function block is activated via a positive flank.

Timeout: Maximum time allowed for the execution of the function block.

CompleteAccess: Via Complete Access the complete object can be accessed at once.

VAR_OUTPUTVAR_OUTPUT    Busy         : BOOL;    Error        : BOOL;    AdsErrId     : UINT;    CANopenErrId : UINT;END_VAR

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the event of a set error output returns the ADS error code

CANopenErrId: In the event of a set error output returns the CANopen error code

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

Example of an implementation in ST:PROGRAM MAINVAR    fbCoERead         : FB_CoERead;    NetId             : T_AmsNetId := '';     Index             : WORD := 16#1018;    SubIndex          : BYTE := 1;     Execute           : BOOL := TRUE;    Timeout           : TIME := T#5S;    CompleteAccess    : BOOL := TRUE;    Axis              : AXIS_REF;    vendorId          : UDINT := 2;    Error             : BOOL;    AdsErrId          : UDINT;    CANopenErrId      : UDINT;END_VAR

fbCoERead(    NetId:= NetId,     Index:= Index,     SubIndex:= SubIndex,     pDstBuf:= ADR(vendorId),     BufLen:= SIZEOF(vendorId),     Execute:= Execute,     Timeout:= Timeout,     CompleteAccess:= CompleteAccess,     Axis := Axis);

IF NOT fbCoERead.Busy THEN    Error:=fbCoERead.Error;    AdsErrId:=fbCoERead.AdsErrId;    CANopenErrId:=fbCoERead.CANopenErrId;

PLC Lib: Tc2_MC2_Drive 15Version: 1.0

Page 16: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

    Execute := FALSE;    fbCoERead(Execute := Execute, Axis := Axis);END_IF

3.2.1.2 FB_CoEWrite

With the FB_CoEWrite function block an object from the object directory of an EtherCAT slave can be writtenby SDO-Download. This requires the slave to have a mailbox and to support the "CANopen overEtherCAT" (CoE) protocol. With the help of the SubIndex and Index parameters a selection is made as towhich object should be written. Via CompleteAccess := TRUE the parameter can be written together with thesub-elements.

VAR_INPUTVAR_INPUT   NetId          : T_AmsNetId;(*netID of PC with NC*)   Index          : WORD;(*CoE object index*)   SubIndex       : BYTE;(*CoE sub index*)   pSrcBuf        : PVOID;(*Contains the address of the buffer containing the data to be send*)   BufLen         : UDINT;(*Contains the max. number of bytes to be received*)   Execute        : BOOL;(*Function block execution is triggered by a rising edge at this input.*)   Timeout        : TIME := DEFAULT_ADS_TIMEOUT;(*States the time before the function is can-celled.*)   CompleteAccess : BOOL;(*Function block reads the complete object with all sub index*)END_VAR

NetId: String, which contains the AMS-Network ID of the PC (Type: T_AmsNetId).

Index: Index of the object that is supposed to be written.

SubIndex: Sub-index of the object that is supposed to be written.

pSrcBuf: Address (pointer) of the transmit buffer.

BufLen: Number (in bytes) of data to be sent.

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

CompleteAccess: Via Complete Access the complete object can be accessed at once.

VAR_OUTPUTVAR_OUTPUT    Busy         : BOOL;    Error        : BOOL;    AdsErrId     : UINT;    CANopenErrId : UINT;END_VAR

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the event of a set error output returns the ADS error code

CANopenErrId: In the event of a set error output returns the CANopen error code

PLC Lib: Tc2_MC2_Drive16 Version: 1.0

Page 17: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

Example of an implementation in ST:PROGRAM MAINVAR    fbCoEWrite     : FB_CoEWrite;    NetId          : T_AmsNetId := '';     Index          : WORD := 16#1018;    SubIndex       : BYTE := 1;     Execute        : BOOL := TRUE;    Timeout        : TIME := T#5S;    CompleteAccess : BOOL := TRUE;    Axis           : AXIS_REF;    vendorId       : UDINT := 2;    Error          : BOOL;    AdsErrId       : UDINT;    CANopenErrId   : UDINT;END_VAR

fbCoEWrite(    NetId:= NetId,     Index:= Index,     SubIndex:= SubIndex,     pSrcBuf:= ADR(vendorId),     BufLen:= SIZEOF(vendorId),     Execute:= Execute,     Timeout:= Timeout,     CompleteAccess:= CompleteAccess,     Axis := Axis);

IF NOT fbCoEWrite.Busy THEN    Error:=fbCoEWrite.Error;    AdsErrId:=fbCoEWrite.AdsErrId;    CANopenErrId:=fbCoEWrite.CANopenErrId;    Execute := FALSE;    fbCoEWrite(Execute := Execute, Axis := Axis);END_IF

3.3 General SoE FB

3.3.1 FB_SoEReset

With the FB_SoEReset function block a drive reset (S-0-0099) can be executed. In the case of multiple-channel devices if necessary, both channels will have to perform a reset. The timeout period must be 10s,since depending on the error the reset can take up to 10s.For the AX5000 the "Wait For WcState is OK" flag has to be activated in the Advanced EtherCAT Settings.

PLC Lib: Tc2_MC2_Drive 17Version: 1.0

Page 18: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

An NC reset will not be performed. If an NC reset is necessary, it can be executed via the MC_Resetfunction block from the Tc2_MC2.

VAR_INPUTVAR_INPUT    NetId : T_AmsNetId := '';    Execute : BOOL;    Timeout : TIME := T#10s;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT    Busy        : BOOL;    Error       : BOOL;    AdsErrId    : UINT;    SercosErrId : UINT;END_VAR

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command.

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

PLC Lib: Tc2_MC2_Drive18 Version: 1.0

Page 19: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

SamplefbSoEReset : FB_SoEReset;SoEReset : BOOL;(* NcAxis *)Axis : AXIS_REF; 

IF SoEReset THEN fbSoEReset(    Axis := Axis,    Execute := TRUE,); IF NOT fbSoEReset.Busy THEN    fbSoEReset(Axis := Axis, Execute := FALSE);    SoEReset := FALSE; END_IFEND_IF

3.3.2 FB_SoEWritePassword

With the FB_SoEWritePassword function block (S-0-0267) the drive password can be set.

VAR_INPUTVAR_INPUT    NetId    : T_AmsNetId := '';    Execute  : BOOL;    Timeout  : TIME := DEFAULT_ADS_TIMEOUT;    Password : ST_SoE_String;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

Password: Contains the password as a Sercos string.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT    Busy        : BOOL;    Error       : BOOL;    AdsErrId    : UINT;    SercosErrId : UINT;END_VAR

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command.

PLC Lib: Tc2_MC2_Drive 19Version: 1.0

Page 20: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

SamplefbWritePassword : FB_SoEWritePassword;WritePassword : BOOL;Password : ST_SoE_String;(* NcAxis *)Axis : AXIS_REF; 

IF WritePassword THEN fbWritePassword(    Axis := Axis,    Execute := TRUE,    Timeout := DEFAULT_ADS_TIMEOUT,    Password := Password ); IF NOT fbWritePassword.Busy THEN    fbWritePassword(Axis := Axis, Execute := FALSE);    WritePassword := FALSE; END_IFEND_IF

3.3.3 Command FB

3.3.3.1 FB_SoEExecuteCommand

With the FB_SoEExecuteCommand function block a command can be executed.

VAR_INPUTVAR_INPUT    NetId   : T_AmsNetId := '';    Idn     : WORD;    Execute : BOOL;    Timeout : TIME := DEFAULT_ADS_TIMEOUT;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Idn: Parameter number, to which the FB_SoEExecuteCommand_ByDriveRef refers, "P_0_IDN + 160" forP-0-0160

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

PLC Lib: Tc2_MC2_Drive20 Version: 1.0

Page 21: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

VAR_OUTPUTVAR_OUTPUT    Busy        : BOOL;    Error       : BOOL;    AdsErrId    : UINT;    SercosErrId : UINT;END_VAR

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command.

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

SamplefbExecuteCommand : FB_SoEExecuteCommand;ExecuteCommand : BOOL;Idn : WORD;(* NcAxis *)Axis : AXIS_REF; 

IF ExecuteCommand THEN Idn := P_0_IDN + 160; fbExecuteCommand(    Axis := Axis,    Execute := TRUE,    Timeout := DEFAULT_ADS_TIMEOUT,    Idn := Idn, ); IF NOT fbExecuteCommand.Busy THEN    fbExecuteCommand(Axis := Axis, Execute := FALSE);    ExecuteCommand := FALSE; END_IFEND_IF

3.3.3.2 FB_SoEWriteCommandControl

With the FB_SoEWriteCommandControl function block a command can be prepared, started or canceled.

VAR_INPUTVAR_INPUT    NetId      : T_AmsNetId := '';    Idn        : WORD;    CmdControl : E_SoE_CmdControl;    Execute    : BOOL;    Timeout    : TIME := DEFAULT_ADS_TIMEOUT;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Idn: Parameter number, to which FB_SoEWriteCommandControl_ByDriveRef refers, e.g. "P_0_IDN + 160"for P-0-0160

CmdControl: Indicates, if a command should be prepared (eSoE_CmdControl_Set := 1), executed(eSoE_CmdControl_SetAndEnable := 3) or aborted (eSoE_CmdControl_Cancel := 0)

PLC Lib: Tc2_MC2_Drive 21Version: 1.0

Page 22: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT    Busy        : BOOL;    Error       : BOOL;    AdsErrId    : UINT;    SercosErrId : UINT;END_VAR

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command.

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

SamplefbWriteCommandControl : FB_SoEWriteCommandControl;WriteCommandControl : BOOL;Idn : WORD;CmdControl : E_SoE_CmdControl;(* NcAxis *)Axis : AXIS_REF; 

IF WriteCommandControl THEN Idn := P_0_IDN + 160; fbWriteCommandControl(    Axis    := Axis,    Execute := TRUE,    Timeout := DEFAULT_ADS_TIMEOUT,    Idn     := Idn,    CmdControl := CmdControl ); IF NOT fbWriteCommandControl.Busy THEN    fbWriteCommandControl(Axis := Axis, Execute := FALSE);    WriteCommandControl := FALSE; END_IFEND_IF

3.3.3.3 FB_SoEReadCommandState

With the FB_SoEReadCommandState function block the command execution can be checked.

PLC Lib: Tc2_MC2_Drive22 Version: 1.0

Page 23: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

VAR_INPUTVAR_INPUT    NetId   : T_AmsNetId := '';    Idn     : WORD;    Execute : BOOL;    Timeout : TIME := DEFAULT_ADS_TIMEOUT;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Idn: Parameter number to which FB_SoEReadCommandState_ByDriveRef refers, e.g. "P_0_IDN + 160" forP-0-0160

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT    Busy        : BOOL;    Error       : BOOL;    CmdState    : E_SoE_CmdState;    AdsErrId    : UINT;    SercosErrId : UINT;END_VAR

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command:

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

CmdState: Returns the command status:eSoE_CmdState_NotSet = 0- kein Kommando aktiv

eSoE_CmdState_Set = 1- Kommando gesetzt (vorbereitet) aber (noch) nicht ausgeführt

eSoE_CmdState_Executed = 2- Kommando wurde ausgeführt

eSoE_CmdState_SetEnabledExecuted = 3 - Kommando gesetzt (vorbereitet) und ausgeführt

eSoE_CmdState_SetAndInterrupted = 5- Kommando wurde gesetzt aber unterbrochen

eSoE_CmdState_SetEnabledNotExecuted = 7- Kommandoausführung ist noch aktiv

eSoE_CmdState_Error = 15- Fehler bei der Kommandoausführung, es wurde in den Fehlerstate gewechselt

SamplefbReadCommandState : FB_SoEReadCommandState;ReadCommandState : BOOL;Idn : WORD;CmdState : E_SoE_CmdState;(* NcAxis *)

PLC Lib: Tc2_MC2_Drive 23Version: 1.0

Page 24: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

Axis : AXIS_REF; 

IF ReadCommandState THEN Idn := P_0_IDN + 160; fbReadCommandState(    Axis := Axis,    Execute := TRUE,    Timeout := DEFAULT_ADS_TIMEOUT,    Idn := Idn,    CmdState => CmdState ); IF NOT fbReadCommandState.Busy THEN    fbReadCommandState(Axis := Axis, Execute := FALSE);    ReadCommandState := FALSE; END_IFEND_IF

3.3.4 Diagnosis FB

3.3.4.1 FB_SoEReadDiagMessage

With the FB_SoEReadDiagMessage function block the diagnosis message can be read out as a Sercosstring (S-0-0095).

VAR_INPUTVAR_INPUT    NetId   : T_AmsNetId := '';    Execute : BOOL;    Timeout : TIME := DEFAULT_ADS_TIMEOUT;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT    Busy        : BOOL;    Error       : BOOL;    AdsErrId    : UINT;    SercosErrId : UINT;    DiagMessage : ST_SoE_String;    Attribute   : DWORD;END_VAR

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

PLC Lib: Tc2_MC2_Drive24 Version: 1.0

Page 25: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command.

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

Attribute: Returns the attributes of the Sercos parameter.

DiagMessage: Returns the diagnosis message.

SamplefbDiagMessage : FB_SoEReadDiagMessage;bDiagMessage : BOOL;DiagMessage : ST_SoE_String;(* NcAxis *)Axis : AXIS_REF; 

IF bDiagMessage THEN fbDiagMessage(    Axis := Axis,    Execute := TRUE,    Timeout := DEFAULT_ADS_TIMEOUT,    DiagMessage=> DiagMessage ); IF NOT fbDiagMessage.Busy THEN    fbDiagMessage(Axis := Axis, Execute := FALSE);    bDiagMessage := FALSE; END_IFEND_IF

3.3.4.2 FB_SoEReadDiagNumber

With the FB_SoEReadDiagNumber function block the current diagnosis number can be read out as UDINT(S-0-0390).

VAR_INPUTVAR_INPUT    NetId   : T_AmsNetId := '';    Execute : BOOL;    Timeout : TIME := DEFAULT_ADS_TIMEOUT;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

PLC Lib: Tc2_MC2_Drive 25Version: 1.0

Page 26: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

VAR_OUTPUTVAR_OUTPUT    Busy        : BOOL;    Error       : BOOL;    AdsErrId    : UINT;    SercosErrId : UINT;    DiagNumber  : UDINT;    Attribute   : DWORD;END_VAR

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command.

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

Attribute: Returns the attributes of the Sercos parameter.

DiagNumber: Returns the current diagnosis number.

SamplefbDiagNumber : FB_SoEReadDiagNumber;bDiagNumber : BOOL;DiagNumber : UDINT;(* NcAxis *)Axis : AXIS_REF; 

IF bDiagNumber THEN fbDiagNumber(    Axis := Axis,    Execute := TRUE,    Timeout := DEFAULT_ADS_TIMEOUT,    DiagNumber => DiagNumber ); IF NOT fbDiagNumber.Busy THEN    fbDiagNumber(Axis := Axis, Execute := FALSE);    bDiagNumber := FALSE; END_IFEND_IF

3.3.4.3 FB_SoEReadDiagNumberList

With the FB_SoEReadDiagNumberList function block a history of the diagnosis numbers can be read out asa list (S-0-0375).

VAR_INPUTVAR_INPUT    NetId       : T_AmsNetId := '';    Execute     : BOOL;    Timeout     : TIME := DEFAULT_ADS_TIMEOUT;    pDiagNumber : POINTER TO ST_SoE_DiagNumList;    Size        : UDINT;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Execute: The function block is enabled via a positive flank at this input.

PLC Lib: Tc2_MC2_Drive26 Version: 1.0

Page 27: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

Timeout: Maximum time allowed for the execution of the function block.

pDiagNumber: Pointer to list of the last max. 30 error numbers. The list consists of the current andmaximum number of bytes in the list, as well as the 30 list entries

Size: Size of the list in bytes (as Sizeof())

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT    busy        : BOOL;    Error       : BOOL;    AdsErrId    : UINT;    SercosErrId : UINT;    Attribute   : DWORD;END_VAR

Busy: This output is set when the function block is activated, and remains set until an acknowledgement isreceived.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: Supplies the ADS error code associated with the most recently executed command if the Erroroutput is set.

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

Attribute: Returns the attributes of the Sercos parameter.

SamplefbDiagNumberList : FB_SoEReadDiagNumberList;DiagNumberList : BOOL;stDiagNumberList : ST_SoE_DiagNumList;(* NcAxis *)Axis : AXIS_REF; 

IF DiagNumberList THEN fbDiagNumberList(    Axis := Axis,    Execute := TRUE,    Timeout := DEFAULT_ADS_TIMEOUT,    pDiagNumber:= ADR(stDiagNumberList),    Size := SIZEOF(stDiagNumberList), ); IF NOT fbDiagNumberList.Busy THEN    fbDiagNumberList(Axis := Axis, Execute := FALSE);    DiagNumberList := FALSE; END_IFEND_IF

PLC Lib: Tc2_MC2_Drive 27Version: 1.0

Page 28: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

3.3.4.4 FB_SoEReadClassXDiag

With the FB_SoEReadClassXDiag function block the current class 1 diagnosis (S-0-0011) ... class 3diagnosis (S-0-0013) can be read as WORD. For the evaluation of the class 1 diagnosis as structureST_AX5000_C1D there is a conversion function F_ConvWordToSTAX5000C1D.  See TcDrive.libdocumentation.

VAR_INPUTVAR_INPUT    NetId     : T_AmsNetId := '';     Execute   : BOOL;     DiagClass : USINT:= 1; (* 1: C1D (S-0-0011) is default, 2: C2D (S-0-0012), 3: C3D (S-0-0013) *)    Timeout   : TIME := DEFAULT_ADS_TIMEOUT;END_VAR

NetId: String containing the AMS network ID of the PC. (Type T_AmsNetId)

Execute: The function block is enabled via a positive flank at this input.

DiagClass: Specifies which diagnosis should be read. The diagnosis parameters can vary frommanufacturer to manufacturer. Not all diagnosis parameters (C1D ... C3D) or all bits in it are alwaysimplemented.1: Error: Class 1 Diag (S-0-0011)2: Warnings: Class 2 Diag (S-0-0012)3: Information messages: Class 3 Diag (S-0-0013)

Timeout: Maximum time allowed for the execution of the function block.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT    Busy        : BOOL;    Error       : BOOL;    AdsErrId    : UINT;    SercosErrId : UINT;    ClassXDiag  : WORD;    Attribute   : DWORD;END_VAR

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command.

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

ClassXDiag: Returns the current Class X Diagnosis.

PLC Lib: Tc2_MC2_Drive28 Version: 1.0

Page 29: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

Attribute: Returns the attributes of the Sercos parameter.

SamplefbClassXDiag : FB_SoEReadClassXDiag;bClassXDiag : BOOL;DiagClass : USINT := 1;Class1Diag : WORD;stAX5000C1D : ST_AX5000_C1D;Class2Diag : WORD;(* NcAxis *)Axis : AXIS_REF; 

IF bClassXDiag THEN fbClassXDiag(    Axis := Axis,    Execute := TRUE,    DiagClass := DiagClass,    Timeout := DEFAULT_ADS_TIMEOUT ); IF NOT fbClassXDiag.Busy THEN    fbClassXDiag(Axis := Axis, Execute := FALSE);    bClassXDiag := FALSE;    CASE fbClassXDiag.DiagClass OF    1:     Class1Diag := fbClassXDiag.ClassXDiag;     stAX5000C1D := F_ConvWordToSTAX5000C1D(Class1Diag);    2:     Class2Diag := fbClassXDiag.ClassXDiag;    END_CASE END_IFEND_IF

3.3.5 FB for current values

3.3.5.1 FB_SoERead

With the FB_SoERead function block a parameter can be read.

VAR_INPUTVAR_INPUT    NetId    : T_AmsNetId := '';    Idn      : WORD;    Element  : BYTE;     pDstBuf  : PVOID;    BufLen   : UDINT;    Execute  : BOOL;    Timeout  : TIME := DEFAULT_ADS_TIMEOUT;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Idn: Parameter number, to which the FB_SoERead refers, "S_0_IDN + 33" for S-0-0033

Element: Specifies which part of the parameter should be accessed, e.g. 16#40 is the value (Value) of theparameter

PLC Lib: Tc2_MC2_Drive 29Version: 1.0

Page 30: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

EC_SOE_ELEMENT_DATASTATE :BYTE :=16#01;

EC_SOE_ELEMENT_NAME :BYTE :=16#02;

EC_SOE_ELEMENT_ATTRIBUTE :BYTE :=16#04;

EC_SOE_ELEMENT_UNIT :BYTE :=16#08;

EC_SOE_ELEMENT_MIN :BYTE :=16#10;

EC_SOE_ELEMENT_MAX :BYTE :=16#20;

EC_SOE_ELEMENT_VALUE :BYTE :=16#40;

EC_SOE_ELEMENT_DEFAULT :BYTE :=16#80;

pDstBuf: ADR() of the variables to which the value should be read.

BufLen: SIZEOF() of the variables to which the value should be read.

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT    Busy        : BOOL;    Error       : BOOL;    AdsErrId    : UINT;    SercosErrId : UINT;    Attribute   : DWORD;END_VAR

Busy: This output is set when the function block is activated, and remains set until an acknowledgement isreceived.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command.

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

Attributes: Returns the attributes of the Sercos parameter.

SamplefbRead : FB_SoERead;Read : BOOL;Idn : WORD;ReadValue : UINT;(* NcAxis *)Axis : AXIS_REF; 

IF Read THEN Idn := S_0_IDN + 33; fbRead(    Axis := Axis,    Idn := Idn,    Element := 16#40,    pDstBuf := ADR(ReadValue),    BufLen := SIZEOF(ReadValue),    Execute := TRUE,    Timeout := DEFAULT_ADS_TIMEOUT, );

PLC Lib: Tc2_MC2_Drive30 Version: 1.0

Page 31: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

 IF NOT fbRead.Busy THEN    fbRead(Axis := Axis, Execute := FALSE);    Read := FALSE; END_IFEND_IF

3.3.5.2 FB_SoEWrite

With the FB_SoEWrite function block a parameter can be written.

VAR_INPUTVAR_INPUT    NetId    : T_AmsNetId := '';    Idn      : WORD;    Element  : BYTE;    SrcBuf   : PVOID;    BufLen   : UDINT;    Execute  : BOOL;    Timeout  : TIME := DEFAULT_ADS_TIMEOUT;    Password : ST_SoE_String;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Idn: Parameter number, to which the FB_SoERead refers, "S_0_IDN + 47" for S-0-0047

Element: Specifies which part of the parameter should be accessed, e.g. 16#40 is the value (Value) of theparameter Usually there is only write access to the value, other components of the parameter are read-only.EC_SOE_ELEMENT_DATASTATE :BYTE :=16#01;

EC_SOE_ELEMENT_NAME :BYTE :=16#02;

EC_SOE_ELEMENT_ATTRIBUTE :BYTE :=16#04;

EC_SOE_ELEMENT_UNIT :BYTE :=16#08;

EC_SOE_ELEMENT_MIN :BYTE :=16#10;

EC_SOE_ELEMENT_MAX :BYTE :=16#20;

EC_SOE_ELEMENT_VALUE :BYTE :=16#40;

EC_SOE_ELEMENT_DEFAULT :BYTE :=16#80;

SrcBuf: ADR() of the variable containing the value to be written.

BufLen: SIZEOF() of the variable containing the value to be written

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

Password: contains the password as a Sercos string. Is not yet being used. The password must be writtenwith FB_SoEWritePassword.

PLC Lib: Tc2_MC2_Drive 31Version: 1.0

Page 32: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT    Busy        : BOOL;    Error       : BOOL;    AdsErrId    : UINT;    SercosErrId : UINT;END_VAR

Busy: This output is set when the function block is activated, and remains set until an acknowledgement isreceived.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

SamplefbWrite : FB_SoEWrite;Idn : WORD;Write : BOOL;WriteValue : UINT;Password : ST_SoE_String;(* NcAxis *)Axis : AXIS_REF; 

IF Write THEN Idn := S_0_IDN + 33; fbWrite(    Axis := Axis,    Idn := Idn,    Element := 16#40,    pSrcBuf := ADR(WriteValue),    BufLen := SIZEOF(WriteValue),    Password := Password,    Execute := TRUE,    Timeout := DEFAULT_ADS_TIMEOUT, ); IF NOT fbWrite.Busy THEN    fbWrite(Axis := Axis, Execute := FALSE);    Write := FALSE; END_IFEND_IF

3.3.5.3 FB_SoEReadAmplifierTemperature

With the FB_SoEReadAmplifierTemperature function block the temperature of the drive (S-0-0384) can beread.

PLC Lib: Tc2_MC2_Drive32 Version: 1.0

Page 33: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

VAR_INPUTVAR_INPUT    NetId   : T_AmsNetId := '';    Execute : BOOL;    Timeout : TIME := DEFAULT_ADS_TIMEOUT;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT    Busy                 : BOOL;    Error                : BOOL;    AdsErrId             : UINT;    SercosErrId          : UINT;    AmplifierTemperature : REAL;    Attribute            : DWORD;END_VAR

Busy: This output is set when the function block is activated, and remains set until an acknowledgement isreceived.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command.

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

Attributes: Returns the attributes of the Sercos parameter.

AmplifierTemperature: Returns the drive temperature (e.g. 26.2 corresponds to 26.2 °C).

SamplefbReadAmplifierTemp : FB_SoEReadAmplifierTemperature;ReadAmplifierTemp : BOOL;AmplifierTemperature : REAL;(* NcAxis *)Axis : AXIS_REF; 

IF ReadAmplifierTemp THEN fbReadAmplifierTemp(    Axis := Axis,    Execute := TRUE,    Timeout := DEFAULT_ADS_TIMEOUT,    AmplifierTemperature=>AmplifierTemperature ); IF NOT fbReadAmplifierTemp.Busy THEN    fbReadAmplifierTemp(Axis := Axis, Execute := FALSE);    ReadAmplifierTemp := FALSE; END_IFEND_IF

PLC Lib: Tc2_MC2_Drive 33Version: 1.0

Page 34: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

3.3.5.4 FB_SoEReadMotorTemperature

With the FB_SoEReadMotorTemperature function block the temperature of the motor (S-0-0383) can beread. If the motor does not contain a temperature sensor, reads 0.0, means 0.0 °C.

VAR_INPUTVAR_INPUT    NetId   : T_AmsNetId := '';    Execute : BOOL;    Timeout : TIME := DEFAULT_ADS_TIMEOUT;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT    Busy             : BOOL;    Error            : BOOL;    AdsErrId         : UINT;    SercosErrId      : UINT;    MotorTemperature : REAL;    Attribute        : DWORD;END_VAR

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command.

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

Attributes: Returns the attributes of the Sercos parameter.

MotorTemperature: Returns the motor temperature (e.g. 30.5 corresponds to 30.5 °C). If the motor does notcontain a temperature sensor, reads 0.0, means 0.0 °C.

SamplefbReadMotorTemp : FB_SoEReadMotorTemperature;ReadMotorTemp : BOOL;MotorTemperature : REAL;(* NcAxis *)Axis : AXIS_REF; 

PLC Lib: Tc2_MC2_Drive34 Version: 1.0

Page 35: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

IF ReadMotorTemp THEN fbReadMotorTemp(    Axis := Axis,    Execute := TRUE,    Timeout := DEFAULT_ADS_TIMEOUT,    MotorTemperature=>MotorTemperature ); IF NOT fbReadMotorTemp.Busy THEN    fbReadMotorTemp(Axis := Axis, Execute := FALSE);    ReadMotorTemp := FALSE; END_IFEND_IF

3.3.5.5 FB_SoEReadDcBusCurrent

With the FB_SoEAX5000ReadDcBusCurrent function block the DC-Bus current (S-0-0381) can be read.

VAR_INPUTVAR_INPUT    NetId   : T_AmsNetId := '';    Execute : BOOL;    Timeout : TIME := DEFAULT_ADS_TIMEOUT;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT    Busy         : BOOL;    Error        : BOOL;    AdsErrId     : UINT;    SercosErrId  : UINT;    DcBusCurrent : REAL;    Attribute    : DWORD;END_VAR

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command.

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

Attributes: Returns the attributes of the Sercos parameter.

PLC Lib: Tc2_MC2_Drive 35Version: 1.0

Page 36: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

DcBusCurrent: Returns the DC-Bus current (e.g. 2.040 corresponds to 2.040 A).

SamplefbReadDcBusCurrent : FB_SoEReadDcBusCurrent;ReadDcBusCurrent : BOOL;DcBusCurrent : REAL;(* NcAxis *)Axis : AXIS_REF; 

IF ReadDcBusCurrent THEN fbReadDcBusCurrent(    Axis := Axis,    Execute := TRUE,    Timeout := DEFAULT_ADS_TIMEOUT,    DcBusCurrent=>DcBusCurrent ); IF NOT fbReadDcBusCurrent.Busy THEN    fbReadDcBusCurrent(Axis := Axis, Execute := FALSE);    ReadDcBusCurrent := FALSE; END_IFEND_IF

3.3.5.6 FB_SoEReadDcBusVoltage

With the FB_SoEReadDcBusVoltage function block the Dc-Bus voltage of the drive (S-0-0380) can be read.

VAR_INPUTVAR_INPUT    NetId   : T_AmsNetId := '';    Execute : BOOL;    Timeout : TIME := DEFAULT_ADS_TIMEOUT;END_VAR

NetId: String containing the AMS network ID of the PC. (Type: T_AmsNetId)

Execute: The function block is enabled via a positive flank at this input.

Timeout: Maximum time allowed for the execution of the function block.

VAR_IN_OUTVAR_IN_OUT   Axis : AXIS_REF;END_VAR

Axis: Axis data structure of the type AXIS_REF, which uniquely addresses an axis in the system. Amongother things it contains the current status of the axis such as the position, the speed and the error state.

VAR_OUTPUTVAR_OUTPUT    Busy         : BOOL;    Error        : BOOL;    AdsErrId     : UINT;    SercosErrId  : UINT;    DcBusVoltage : REAL;    Attribute    : DWORD;END_VAR

PLC Lib: Tc2_MC2_Drive36 Version: 1.0

Page 37: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Function blocks

Busy: This output is set upon the activation of the function block and remains set until feedback occurs.

Error: This output is set after the Busy output has been reset when an error occurs in the transmission of thecommand.

AdsErrId: In the case of a set Error output returns the ADS error code of the last executed command.

SercosErrId: In the case of a set Error output returns the Sercos error of the last executed command.

Attributes: Returns the attributes of the Sercos parameter.

DcBusVoltage: Returns the Dc-Bus voltage (e.g. 294.0 corresponds to 294.0 V).

SamplefbReadDcBusVoltage : FB_SoEReadDcBusVoltage;ReadDcBusVoltage : BOOL;DcBusVoltage : REAL;(* NcAxis *)Axis : AXIS_REF; 

IF ReadDcBusVoltage THEN fbReadDcBusVoltage(    Axis := Axis,    Execute := TRUE,    Timeout := DEFAULT_ADS_TIMEOUT,    DcBusVoltage=>DcBusVoltage ); IF NOT fbReadDcBusVoltage.Busy THEN    fbReadDcBusVoltage(Axis := Axis, Execute := FALSE);    ReadDcBusVoltage := FALSE; END_IFEND_IF

3.4 F_GetVersionTcMc2Drive

This function can be used to read PLC library version information.

FUNCTION F_GetVersionTcMc2Drive: UINTVAR_INPUT    nVersionElement : INT;END_VAR

nVersionElement: Version element to be read. Possible parameters:

• 1 : major number;• 2 : minor number;• 3 : revision number;

PLC Lib: Tc2_MC2_Drive 37Version: 1.0

Page 38: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Data types

4 Data types

4.1 E_FwUpdateStateThe E_FwUpdateState describes the state of a firmware update.TYPE E_SoE_CmdState :( (* update states *) eFwU_NoError := 0, eFwU_CheckCfgIdentity, eFwU_CheckSlaveCount, eFwU_CheckFindSlavePos, eFwU_WaitForScan, eFwU_ScanningSlaves, eFwU_CheckScannedIdentity, eFwU_CheckScannedFirmware, eFwU_FindFirmwareFile, eFwU_WaitForUpdate, eFwU_WaitForSlaveState, eFwU_StartFwUpdate, eFwU_FwUpdateInProgress, eFwU_FwUpdateDone, eFwU_NoFwUpdateRequired,

 (* not updating via this channel *) eFwU_UpdateViaOtherChannelActive, eFwU_UpdatedViaOtherChannel,

 (* error states *) eFwU_GetSlaveIdentityError := -1, eFwU_GetSlaveCountError    := -2, eFwU_GetSlaveAddrError     := -3, eFwU_StartScanError        := -4, eFwU_ScanStateError        := -5, eFwU_ScanIdentityError     := -6, eFwU_GetSlaveStateError    := -7, eFwU_ScanFirmwareError     := -8, eFwU_FindFileError         := -9, eFwU_CfgTypeInNoAX5xxx     := -10, eFwU_ScannedTypeInNoAX5xxx := -11, eFwU_ChannelMismatch       := -12, eFwU_ChannelMismatch_1Cfg_2Scanned := -13, eFwU_ChannelMismatch_2Cfg_1Scanned := -14, eFwU_CurrentMismatch       := -15, eFwU_FwUpdateError         := -16, eFwU_ReqSlaveStateError    := -17 );END_TYPE

Update Status eFwU_NoError : Initialzustand

 eFwU_CheckCfgIdentity : Einlesen des konfiguriertenSlavetypen (Anzahl Kanäle, Strom, Revision)

 eFwU_CheckSlaveCount : Ermitteln derkonfigurierten Slaveanzahl

 eFwU_CheckFindSlavePos : Suchen der Slave-Adresse im Master-Objektverzeichnis

 eFwU_WaitForScan : Warten auf Online-Scan

 eFwU_ScanningSlaves : Online-Scan der Slaves

 eFwU_CheckScannedIdentity : Einlesen des gescannten Slavetypen (Anzahl Kanäle, Strom, Revision)

 eFwU_CheckScannedFirmware : Einlesen der Firmware-Version

 eFwU_FindFirmwareFile : Suchen nach der gewählten Firmware-Datei

 eFwU_WaitForUpdate : Warten auf State des Updates

 eFwU_WaitForSlaveState : Ermitteln des EtherCAT Slave-States

 eFwU_StartFwUpdate : Starten des Firmware-Updates

PLC Lib: Tc2_MC2_Drive38 Version: 1.0

Page 39: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Data types

 eFwU_FwUpdateInProgress : Firmwareupdate aktiv

 eFwU_FwUpdateDone : Firmwareupdate erfolgreich beendet

 eFwU_NoFwUpdateRequired : Kein Firmwareupdate erforderlich

 eFwU_UpdateViaOtherChannelActive : Update erfolgt über denanderen Achskanal

 eFwU_UpdatedViaOtherChannel : Update erfolgte über denanderen Achskanal

Update Fehler eFwU_GetSlaveIdentityError : Einlesen des konfiguri-erten Slavetypen schlug fehl, siehe iAdsErrId

 eFwU_GetSlaveCountError : Ermitteln der konfigurierten Slaveanzahl schlug fehl, siehe iAdsErrId

 eFwU_GetSlaveAddrError : Suchen der Slave-Adresse im Master-Objektverzeich-nis schlug fehl, siehe iAdsErrId

 eFwU_StartScanError : Starten des Online-Scan schlug fehl, siehe iAdsErrId

 eFwU_ScanStateError : Online-Scan schlug fehl, siehe iAdsErrId

 eFwU_ScanIdentityError : Einlesen des gescannten Slavetypen (Anzahl Kanäle, Strom, Revi-sion) schlug fehl, siehe iAdsErrId

 eFwU_GetSlaveStateError : Ermitteln des EtherCAT Slave-States schlug fehl, siehe iAdsErrId

 eFwU_ScanFirmwareError : Einlesen derFirmware-Version schlug fehl, siehe iAdsErrId + iSercosErrId

 eFwU_FindFileError : Suchen nach der gewählten Firmware-Datei schlug fehl, siehe iAdsErrId

 eFwU_CfgTypeInNoAX5xxx : Der konfigurierte Slave ist kein AX5000

 eFwU_ScannedTypeInNoAX5xxx : Der gescannte Slave ist kein AX5000

 eFwU_ChannelMismatch : Anzahl der konfigurierten bzw. gefunde-nen Kanäle des AX5000 passen nicht zusammen

 eFwU_ChannelMismatch_1Cfg_2Scanned : Einkanaliges Gerät konfiguriert aber zweikanaliges Gerät ge-funden

 eFwU_ChannelMismatch_2Cfg_1Scanned : Zweikanaliges Gerät konfiguriert aber einkanaliges Gerät ge-funden

 eFwU_CurrentMismatch : AX5000-Type passt vom Strom her nicht, z.B. AX5103 (3A) konfiguri-ert aber AX5106 (6A) gefunden

 eFwU_FwUpdateError : Allgemeiner Updatefehler, siehe iAdsErrId 

 eFwU_ReqSlaveStateError : Umschalten in den gewünschten EtherCAT-State schlug fehl

4.2 E_PositionOffsetMemoryTYPE E_PositionOffsetMemory :( ePositionOffsetMemory_Encoder   := 0 ePositionOffsetMemory_Drive     := 1) BYTE;END_TYPE

ePositionOffsetMemory_Encoder: As memory for the new Positions-Offset the motor name plate of theEncoder is selected.

ePositionOffsetMemory_Drive: As memory for the new Positions-Offset the internal memory of the drive isselected.

PLC Lib: Tc2_MC2_Drive 39Version: 1.0

Page 40: Manual PLC Lib: Tc2 MC2 Drive - Directory contents of ... PLC Lib: Tc2_MC2_Drive TwinCAT 1.0 2016-05-30 Version: Date: Table of contents Table of contents 1Foreword ..... 4

Data types

4.3 E_PositionOffsetFeedbackTYPE E_PositionOffsetMemory :( ePositionOffsetFeedback1       := 0 ePositionOffsetFeedback2       := 1) BYTE;END_TYPE

ePositionOffsetFeedback1: Reference for the recalculation of the Positions-Offset is Feedback-System 1.

ePositionOffsetFeedback1_Drive: Reference for the recalculation of the Positions-Offset is Feedback-System 2.

PLC Lib: Tc2_MC2_Drive40 Version: 1.0