FB_MTP_ServiceControl

FB_MTP_ServiceControl 1:

The function block FB_MTP_ServiceControl enables the execution of procedures from different sources: internal PLC logic, manual operation (e.g. via OPC UA) or control system (e.g. via OPC UA). Switching requests and value specifications are managed via Service Mode.

FB_MTP_ServiceControl 2:

The FB_MTP_ServiceControl is an abstract function block. This cannot be instantiated, but must be derived (see Syntax section)!

FB_MTP_ServiceControl 3:

The use of MTP engineering and its automatic code generation is recommended for the use of services!

Procedures

All procedures associated with the service are transferred as ARRAY[*] OF POINTER TO FB_MTP_Procedure at the input Procedures. A service requires at least one procedure.

A procedure is selected via the variables ProcedureInt, ProcedureOp, ProcedurExt depending on the state of the Service Mode of the service. The currently preselected procedure ID, which is used when the service is started, is displayed via ProcedureReq. If the procedure ID is invalid, a 0 is output here. ProcedureCur shows the procedure currently started. Only one procedure can be executed at a time.

Parameter

At the input ConfParameters, all configuration parameters associated with the service are transferred as ARRAY[*] OF POINTER TO FB_MTP_ParameterElement.

At the input ProcParameter, all procedure parameters associated with the service are transferred as ARRAY[*] OF POINTER TO FB_MTP_ParameterElement.

The service-wide transfer of new values for the parameters follows the same principle as described in the sub-chapters of ParameterElements. The values of all parameters assigned to the service are applied at once. The values to be applied can be checked in advance using the variable VReq of the parameters.

The application is enabled via the variable ProcParameterApplyEn for procedure parameters or via the variable ConfigParameterApplyEn for configuration parameters. A service-wide enable is only possible if all procedure parameters or configuration parameters are enabled ApplyEn = TRUE.

Depending on the state of Service Mode, the values are applied service-wide via the variables ProcParameterApplyInt, ProcParameterApplyOp or ProcParameterApplyExt for procedure parameters or via the variables ConfigParameterApplyInt, ConfigParameterApplyOp or ConfigParameterApplyExt for the configuration parameters if Apply = TRUE is set.

Report values

All report values associated with the service are applied at the input ReportValues as ARRAY[*] OF POINTER TO FB_MTP_ReportValue. All report values V of the service can be frozen via the input ReportValueFreeze. If the value of the input value VIn changes more than once during this time, this is displayed at the output MissedValue = TRUE of the parameter.

The figure below shows an overview of the arrays to be applied:

FB_MTP_ServiceControl 4:
FB_MTP_ServiceControl 5:

If no ConfParameter, ProcParameter or RequiredEquipment are required, apply an empty array.

Service state machine

The service state machine has 16 states on five levels. The states are divided into transient and non-transient states. The transient states are reached via control commands of the control word. Non-transient states are reached after the transient states (SC) have been successfully processed. One exception is the state Execute. This can be both transient and non-transient. This is defined via the variable IsSelfCompleting in the procedure.

The service state machine is structured according to the scheme below:

FB_MTP_ServiceControl 6:

The service state machine can be viewed in different loops:

Main loop

The main loop for executing the main process function(s) of the machine contains the following states:

Idle→Starting→Execute→Completing→Completed→Resetting→Idle

The following loops can also be considered:

Pause loop

The pause loop can only be started from the state Execute. It is terminated by the command Resume or by a command that leads to a higher-level state.

Sample:

Execute→Pausing→Paused→Resuming→Execute

Hold loop

The hold loop can be started from the states from level 2 or lower. It is terminated by the command Unhold or by a command that leads to a higher-level state.

Sample:

Execute→Holding→Held→Unholding→Execute

FB_MTP_ServiceControl 7:

In the MTP guideline, the hold loop is used for the implementation of the logic to be executed in the event of an error.

Stop loop

The stop loop can be started from the states from level 3 or lower. It is terminated with the command Reset or Abort.

Execute→Stopping→Stopped→Resetting→Idle

FB_MTP_ServiceControl 8:

In the MTP guideline, the stop loop is used for the implementation of the logic to stop the service.

Abort loop

The abort loop can be started from the states from level 4 or lower. It is terminated with the command Reset.

Execute→Aborting→Aborted→Resetting→Idle

FB_MTP_ServiceControl 9:

In the MTP guideline, the abort loop is used for the implementation of the logic to stop the service quickly.

Control of the service state machine

The variable CommandEn enables the individual control commands of the control word. The variables CommandInt, CommandOp and CommandExt can be used to specify the control word (see ) for the service state machine depending on the state of the Service Mode.

All states can be transferred to a higher level state with a control command, provided this is enabled: e.g. all states of levels 1 and 2 can be transferred to the state Holding with the command Hold.

Execution of procedures

If the command Start is issued, the selected procedure is transferred to the state Starting. All other procedures assigned to the service are blocked.

The states, with the exception of Idle, are executed in the methods of the selected procedure with the same name. When executing transient states, the state transition (SC) occurs when the respective method returns TRUE. After successful execution, they enter their subsequent state.

Another procedure can only be selected and started once the service state machine is back in the state Idle. The current state of the service state machine is displayed via the variable StateCur (see ).

Dependencies with Service Mode

If the Service Mode is transferred from the Offline state to one of the other two states Operator or Automatic*, the service state machine is always in the Idle state. It is only possible to return the Service Mode to the Offline state if the service state machine is in the basic state Idle. Switching between Operator and Automatic* is possible regardless of the state of the service state machine and does not change its current state.

Position description

A text list can be created to describe the current state of the service in more detail. This can be used to describe the individual work steps in more detail. The variable PosTextID can be used to refer to the individual work steps in the text list.

FB_MTP_ServiceControl 10:

The use of MTP engineering and its MTP export is recommended for the position description, as the text list is not made available via OPC UA, but is described in the MTP file!

Service operator interaction

Interaction between the service and the operator can take place during runtime. Text lists with questions and corresponding answers are created for this purpose. The service uses the variable QuestionID to refer to a question in the text list. You will be shown possible answers to the question. When a response is selected, it is written to the service via the variable InteractQuestionID. The variable AdditionalInfo makes it possible to provide further information in text form.

FB_MTP_ServiceControl 11:

The use of MTP engineering and its MTP export is recommended for service operator interaction, as the text lists are not made available via OPC UA, but are described in the MTP file!

In the sample below, the procedures, configuration parameters and report values are declared in the declaration part of a derivation of FB_MTP_ServiceControl and summarized in arrays. These are then called up in the body of the FB_MTP_ServiceControl. This means that all service-relevant procedures, parameters and report values are combined in one place.

Only one procedure can be executed at a time. A procedure can only be started if the service is in the Idle state.

Syntax

FUNCTION_BLOCK FB_MTP_Service EXTENDS FB_MTP_ServiceControl
VAR
///Procedures – Parameters and Required Equipment
///Procedure 1
   <ProcParametersArray1>    : ARRAY[0..<n>] OF POINTER TO FB_MTP_ParameterElement := [ADR(<ProcParam_0>), ADR(<ProcParam_1>)];
   <RequiredEquipmentArray1> : ARRAY[0..<n>] OF I_MTP_ReqEq := [ADR(<ReqEq_0>), ADR(<ReqEq_1>)];

///Procedure 2
   <ProcParametersArray2>    : ARRAY[0..<n>] OF POINTER TO FB_MTP_ParameterElement := [ADR(<ProcParam_1>), ADR(<ProcParam_2>)];

   <RequiredEquipmentArray2> : ARRAY[0..<n>] OF I_MTP_ReqEq := [ADR(<ReqEq_0>), ADR(<ReqEq_1>)];

///Procedures
   ProcedureArray          : ARRAY[1..<n>] OF POINTER TO FB_MTP_Procedure := [ADR(<Procedure_1>), ADR(<Procedure_1>)];

///ConfigurationParameters
   ConfParameterArray      : ARRAY[0..<n>] OF POINTER TO FB_MTP_ParameterElement := [ADR(<ConfParameter_0>)]

///ProcedureParameters
   ProcParameterArray      : ARRAY[0..<z>] OF POINTER TO FB_MTP_ParameterElement := [ADR(<ProcParameter_0>), ADR(<ProcParameter_1>), ADR(<ProcParameter_2>)];

///ReportValues
   ReportValueArray        : ARRAY[0..<n>] OF POINTER TO FB_MTP_ReportValue [ADR(<ReportValue_0>)]
END_VAR

VAR_INPUT
///Procedures
   <Procedure_1>             : FB_Procedure := (<initial values>);
   <Procedure_2>             : FB_Procedure := (<initial values>);

///ConfigurationParameters
   < ConfParameter_0>        : FB_MTP_AnaServParam := (<initial values>);

///ProcedureParameters
   (<ProcParameter_0>        : FB_MTP_AnaServParam := (<initial values>);
   (<ProcParameter_1>        : FB_MTP_AnaServParam := (<initial values>);
   (<ProcParameter_2>        : FB_MTP_AnaServParam := (<initial values>);

///ReportValues
   (<ReportValue_0>: FB_MTP_AnaReportValue := ((<initial values>);
END_VAR
<Procedure_1>(
   ProcParameters    := <ProcParametersArray_1>,
   RequiredEquipment := <RequiredEquipmentArray_1>);

<Procedure_2>(
   ProcParameters    := <ProcParametersArray_2>,
   RequiredEquipment := <RequiredEquipmentArray_2>);

SUPER^(
   Procedures     := ProcedureArray,
   ConfParameters := ConfParameterArray,
   ProcParameters := ProcParameterArray,
   ReportValues   := ReportValueArray);

Further characteristics

Name of the object

Object description

WQC

OSLevel

Service Mode

FB_MTP_ServiceControl 12: Inputs

Name

Type

Description

OPC UA access

TagName

STRING

Name of the interface

-

TagDescription

STRING

Description of the interface

-

WQC

BYTE

Worst Quality Code

Read

OSLevel

BYTE

Level must be defined for system. Value 0 is reserved for local operation.

Read/write

Procedures 

ARRAY [*] OF POINTER TO FB_MTP_Procedure

Array with all procedures belonging to the service

-

ConfParameters 

ARRAY [*] OF POINTER TO FB_MTP_ParameterElement

Array with all configuration parameters belonging to the service

-

ProcParameters 

ARRAY [*] OF POINTER TO FB_MTP_ParameterElement

Array with all procedure parameters belonging to the service

-

ReportVaIues

ARRAY [*] OF POINTER TO FB_MTP_ReportValue

Array with all ReportValues belonging to the service

-

Commandlnt 

DWORD

Internal control word (relevant if StateAutAct = TRUE and SrcIntAct = TRUE)

Read

Procedurelnt 

DWORD

Internal procedure preselection (relevant if StateAutAct = TRUE and SrcIntAct = TRUE)

Read

CommandEn 

DWORD

Enabling control commands of the control word

Read

State*

Src*

 

See Service Mode

 

PosTextID 

DWORD

ID variable for the position text

Read

InteractQuestionID 

DWORD

ID variable for the question text

Read

InteractAddInfo 

STRING

Additional information on the current InteractQuestionID

Read

ProcParamAppIyInt 

BOOL

Apply all Internal process parameter values VInt belonging to the service. (Relevant, if StateAutAct = TRUE and SrcIntAct = TRUE)

Read

ConfigParamAppIyInt 

BOOL

Apply all Internal configuration parameter values VInt belonging to the service. (Relevant, if StateAutAct = TRUE and SrcIntAct = TRUE)

Read

ReportVaIueFreeze 

BOOL

1: Freeze all report values of the service

0: Do not freeze the report values of the service

Read/write


FB_MTP_ServiceControl 13: Outputs

Name

Type

Description

OPC UA access

StateCur 

DWORD

Current state of the service state machine

Read

ProcedureCur 

DWORD

Procedure currently used

Read

ProcedureReq 

DWORD

Currently preselected procedure, which is executed at start.

Read

State*

Src*

 

See Service Mode

 

ProcParamAppIyEn 

BOOL

Enable Apply procedure parameters:

1: Parameters can be applied.

0: Parameters cannot be applied.

Read

ConfigParamAppIyEn

BOOL

Enable Apply configuration parameters:

1: Parameters can be applied.

0: Parameters cannot be applied.

Read


External variables

Name

Type

Description

OPC UA access

State*

Src*

BOOL

See Service Mode

 

CommandOp

DWORD

Operator control word (relevant if StateOpAct = TRUE)

Read/write

CommandExt

DWORD

External control word (relevant if StateAutAct = TRUE and SrcExtAct = TRUE)

Read/write

ProcedurOp

DWORD

Operator procedure preselection (relevant if StateOpAct = TRUE)

Read/write

ProcedureExt

DWORD

External procedure preselection (relevant if StateAutAct = TRUE and SrcExtAct = TRUE)

Read/write

InteractAnswerID

DWORD

ID variable for the answer text

Read/write

ProcParamAppIyOp 

BOOL

Apply all Operator process parameter values VOp belonging to the service. (Relevant if StateOpAct = TRUE)

Read/write

ProcParamAppIyExt 

BOOL

Apply all External process parameter values VExt belonging to the service. (Relevant, if StateAutAct = TRUE and SrcExtAct = TRUE)

Read/write

ConfigParamAppIyOp 

BOOL

Apply all Operator configuration parameter values VOp belonging to the service. (Relevant if StateOpAct = TRUE)

Read/write

ConfigParamAppIyExt 

BOOL

Apply all External configuration parameter values VExt belonging to the service. (Relevant, if StateAutAct = TRUE and SrcExtAct = TRUE)

Read/write

FB_MTP_ServiceControl 14: Methods

Name

Type

Description

Idle 

 

Non-transient initial state. No process function is executed.

IsActuatorsInternal

BOOL

1: All actuators assigned to the service are in the state Internal.

IsActuatorsManual

BOOL

1: All actuators assigned to the service are in the state Manual.

IsActuatorsOffline

BOOL

1: All actuators assigned to the service are in the state Offline.

IsActuatorsOperator

BOOL

1: All actuators assigned to the service are in the state Operator.

IsActuatorsAutomatic

BOOL

1: All actuators assigned to the service are in the state Automatic.

IsReqEqInternal

BOOL

1: PID logic and all actuators assigned to the service are in the state Internal

IsReqEqManual

BOOL

1: PID logic and all actuators assigned to the service are in the state Manual

IsReqEqOffline

BOOL

1: PID logic and all actuators assigned to the service are in the state Offline

IsReqEqOperator

BOOL

1: PID logic and all actuators assigned to the service are in the state Operator

IsReqEqAutomatic

BOOL

1: PID logic and all actuators assigned to the service are in the state Automatic

SetActuatorsInternal

BOOL

All actuators assigned to the service are transferred to the state Internal.

SetActuatorsManual

BOOL

All actuators assigned to the service are transferred to the state Manual.

SetActuatorsOffline

BOOL

All actuators assigned to the service are transferred to the state Offline.

SetActuatorsOperator

BOOL

All actuators assigned to the service are transferred to the state Operator.

SetActuatorsAutomatic

BOOL

All actuators assigned to the service are transferred to the state Automatic.

SetReqEqInternal

BOOL

PID logic and all actuators assigned to the service are transferred to the state Internal.

SetReqEqManual

BOOL

PID logic and all actuators assigned to the service are transferred to the state Manual.

SetReqEqOffline

BOOL

PID logic and all actuators assigned to the service are transferred to the state Offline.

SetReqEqOperator

BOOL

PID logic and all actuators assigned to the service are transferred to the state Operator.

SetReqEqAutomatic

BOOL

PID logic and all actuators assigned to the service are transferred to the state Automatic.

SetOffline 

BOOL

Transfer the service to the state Offline.

SetOperator 

BOOL

Transfer the service to the state Operator.

SetAutomaticIntern

BOOL

Transfer the service to the state AutomaticIntern.

SetAutomaticExtern

BOOL

Transfer the service to the state AutomaticExtern.

SetProcParamAppIy
En 

BOOL

Value specification (input variable of the method ApplyEn) for input variable ApplyEn of the procedure parameters:

All service parameters assigned to the service (if SyncOnly = FALSE)

All service parameters assigned to the service with input variable Sync = TRUE (if input variable of the method SyncOnly = TRUE)

SetConfigParamAppIyEn 

BOOL

Value specification (input variable method ApplyEn) for configuration parameters:

All service parameters assigned to the service (if SyncOnly = FALSE)

All service parameters assigned to the service with input variable Sync = TRUE (if input variable of the method SyncOnly = TRUE)

ToOnline

BOOL

Implementation of logic when leaving the Offline state.

ToOffline

BOOL

Implementation of logic when entering the Offline state.