FB_SoEReadCommandState_ByDriveRef

FB_SoEReadCommandState_ByDriveRef 1:

With the FB_SoEReadCommandState_ByDriveRef function block, the execution of the command can be checked.

FB_SoEReadCommandState_ByDriveRef 2: Inputs

VAR_INPUT
    stDriveRef : ST_DriveRef; 
    nIdn       : WORD; 
    bExecute   : BOOL; 
    tTimeout   : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR

Name

Type

Description

stDriveRef

ST_DriveRef

Reference to the drive. The reference to the drive can be linked directly to the PLC in the System Manager. To do this, an instance of the structure ST_PlcDriveRef must be allocated and the NetID must be converted from the byte array into a string (Type: ST_DriveRef).

nIdn

WORD

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

bExecute

BOOL

The command is executed with a rising edge at the Execute input.

tTimeout

TIME

Maximum time (10 s) allowed for the execution of the function block.

FB_SoEReadCommandState_ByDriveRef 3: Outputs

VAR_OUTPUT
    bBusy        : BOOL;
    bError       : BOOL;
    iAdsErrId    : UINT;
    iSercosErrId : UINT;
END_VAR

Name

Type

Description

bBusy

BOOL

This output is set when the function block is activated, and remains set until feedback is received.

bError

BOOL

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

eCmdState

eSoE_CmdState

Returns the command state.

iAdsErrId

UINT

Returns the ADS error code of the last executed command when the bError output is set.

iSercosErrId

UINT

Returns the Sercos error of the last executed command in the event of a set bError output.

Sample

fbReadCommandState : FB_SoEReadCommandState_ByDriveRef;
bReadCommandState  : BOOL;
nIdn : WORD;
eCmdState : E_SoE_CmdState;
stPlcDriveRef AT %I* : ST_PlcDriveRef;
stDriveRef : ST_DriveRef;

IF bInit THEN
   stDriveRef.sNetId := F_CreateAmsNetId(stPlcDriveRef.aNetId);
   stDriveRef.nSlaveAddr := stPlcDriveRef.nSlaveAddr;
   stDriveRef.nDriveNo := stPlcDriveRef.nDriveNo;
   stDriveRef.nDriveType := stPlcDriveRef.nDriveType;
   IF (stDriveRef.sNetId <> '') AND (stDriveRef.nSlaveAddr <> 0) THEN
     bInit := FALSE;
   END_IF
END_IF

IF bReadCommandState AND NOT bInit THEN
   nIdn := P_0_IDN + 160;
   fbReadCommandState(
     stDriveRef := stDriveRef,
     bExecute := TRUE,
     tTimeout := DEFAULT_ADS_TIMEOUT,
     nIdn := nIdn,
     eCmdState => eCmdState
   );
   IF NOT fbReadCommandState.bBusy THEN
      fbReadCommandState(stDriveRef := stDriveRef, bExecute := FALSE);
      bReadCommandState := FALSE;
   END_IF
END_IF