FB_SoEReadCommandState_ByDriveRef
The function block FB_SoEReadCommandState_ByDriveRef can be used to read the state of a command.
VAR_INPUT
VAR_INPUT
stDriveRef : ST_DriveRef;
Idn : WORD;
bExecute : BOOL;
tTimeout : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR
stDriveRef: The drive reference can be linked in the System Manager between PLC and drive. The link can be done to an instance of the ST_PlcDriveRef. The structure ST_PlcDriveRef contains the NetID as byte array. The byte array can be converted to a string. See ST_DriveRef.
nIdn: Parameter number for the command state, i.e. "P_0_IDN + 160" for checking the state of execution of a P-0-0160 command
bExecute: The block is activated by a rising edge at this input.
tTimeout: Maximum time allowed for the execution of the function block.
VAR_OUTPUT
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
eCmdState : E_SoE_CmdState;
iAdsErrId : UINT;
iSercosErrId : UINT;
END_VAR
bBusy: This output is set when the function block is activated and remains set until an acknowledgement is received.
bError: This output is set up after the bBusy output has been reset if there has been an error in transmission of the command.
iAdsErrId: Supplies the ADS error code associated with the most recently executed command if the bError output is set.
iSercosErrId: Supplies the Sercos error code associated with the most recently executed command if the bError output is set.
dwAttribute: Supplies the attribut of the Sercos parameter.
eCmdState: Supplies the command state
eSoE_CmdState_NotSet =
0
- no command active
eSoE_CmdState_Set =
1
- command set (prepared) but (not yet) executed
eSoE_CmdState_Executed =
2
- command was executed
eSoE_CmdState_SetEnabledExecuted =
3 - command set (prepared) and executed
eSoE_CmdState_SetAndInterrupted =
5 - command was set but interupted
eSoE_CmdState_SetEnabledNotExecuted = 7 -
command execution is stll active
eSoE_CmdState_Error =
15
- error during command execution, switched to error state
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