Server - SBO Control with normal security

This sample shows the implementation of ctlModel := 2 (SBO control with normal security, operate-once or operate-many) in a server for the following CDCs:

Download TwinCAT XAE Project (*.zip): Sample22.zip

The example described here uses the state machine that is described in the "General Server project structure" chapter. The States 0, 1, 10 and 100 are identical to the state machine described there. Other states were modified for the example or new states were also added.

A new "FB_SboControl" function block has been added. The state machine for the control model is implemented in this. In order for this to be executed for a data object, an "FB_SboControl" instance must be declared as follows in the "VAR_INPUT" part of the function block of the data object to be controlled:

fbControl: FB_SboControl := (ipCtrl:=THIS^.AddServerJob(ipEvent:=fbControl, ipCompletion:=fbControl));

Each of these instances has an "Execute" method that must be called every cycle to monitor the control model. In this sample, this is accomplished in the "FB_IEDServerSession" function block. This method contains the state machine and the monitoring for sending "LastApplError" messages. In addition to the "Execute" method, the "FB_SboControl" function block has further methods and properties that are required for the control model. These are explained in the following tables.

Methods of the "FB_SboControl" function block

Method name

Description

_CheckCancelReq

Is called when a "Cancel" request is received and checks if it is valid. If this is invalid, a corresponding "LastApplError" message is sent.

_CheckCtlVal

In accordance with the controllable CDC of the data object, a check is made to determine whether the value of "ctlVal" to be written is valid. If the value is invalid, a corresponding error code is returned.

_DynamicTest

This method performs the dynamic test. Since this is not needed in this sample, a successful result is always returned. A custom dynamic test can be implemented in this method.

_Init

Initializes the "FB_DirectControl" function block by determining the CDC of the data object to be controlled.

_OperativeTest

This method performs the operational test. The system checks whether the state of the logical node that is superordinate to the data object to be controlled permits control and whether the value to be written is valid. If the test is successful, the address of the client is cached to identify which client triggered the control model. If the test fails, a "LastApplError" message is sent to the client.

_Reset

Resets the values cached for an SBOControl.

_ResetCancelValues

Resets the values of the "Cancel" data attribute to the configured initial values.

_ResetOperValues

Resets the values of the "Oper" data attribute to the configured initial values.

_SendLastApplError

Sends a "LastApplError" message to the Client.

_Set[CDC]Value

A method is added for each controllable CDC, as most CDCs use different types, for example, "APC" -> "REAL" and "SPC" -> "BOOL". As the CDCs use different types, each of these methods also has a different input parameter for the value (e.g. ctlVal). This parameter is used to set the value of the data object to be controlled.

_SetValue

Sets the value of the data object to be controlled according to the value of "ctlVal". Depending on the CDC of the data object, the corresponding "_Set[CDC]Val" method is called for this purpose.

_UpdateTimestampValue

Sets the value of the data attribute "t" of the data object to be controlled to the current system time.

Execute

The state machine for the control model is implemented in this method. The other methods from this function block are called according to the state machine in this method.

OnAbort

Is called when the server disconnects and stops sending the "LastApplError" message.

OnCompletionWaitEvent

This method is called by the server implementation after each write operation. This determines whether an "Operate" request was received. If this is the case, the server implementation is informed that it must wait until the SBOControl is connected before sending the response to the "Operate" request.

OnGetVEvent

This method is part of the "I_AcsiDataAccessEventClass" interface and is called after each read access to the data object to be controlled. This functionality is used to reset the value of the data attribute "SBO" after a "Select" request.

OnGetVPreEvent

This method is part of the "I_AcsiDataAccessEventClass" interface and is called before each read access to the data object to be controlled. This functionality is used to review "Select" requests and accept or reject them accordingly.

OnSetVEvent

This method is part of the "I_AcsiDataAccessEventClass" interface but is not needed for this sample.

OnSetVPreEvent

This method is part of the "I_AcsiDataAccessEventClass" interface and is called before each write access to the data object to be controlled. This functionality is used to prevent overwriting of the "Oper" and "Cancel" structure as well as the "SBO" data attribute during a control operation, for example, by another client.

Properties of the "FB_SboControl" function block

Property name

Description

eType

Specifies the controllable CDC (e.g. "APC").

ipBehVal

Interface pointer to the value of the "Beh" data object of the logical node that is superordinate to the data object to be controlled.

ipCtrl

Interface pointer to the data object to be controlled.

ipStepSize

Optional interface pointer to the "stepSize" data attribute. This can be used for setting the value of a "BAC" data object.

The state machine shown in the figure below, which is implemented in the "Execute" method of the "FB_SboControl" function block, is used for the SBOControl process. The transitions between the individual states are controlled by Boolean variables. In addition, the Boolean variable "bNewState" is used to detect new states and implement the corresponding behavior when the state changes.

Server - SBO Control with normal security 1:

Since a "Select" request is a read request on the "SBO" data attribute, it is checked in the "OnGetVPreEvent" method. In this method, the "Select" request can be accepted by setting the value of "SBO" to the reference to the "SBO" data attribute. To reject the request, the value is set to an empty string. After sending the response, the "OnGetVEvent" method is called, in which the value of the data attribute can be reset. The process of a successful "Select" request is shown in the following figure.

Server - SBO Control with normal security 2:

Since there may be several PLC cycles between receiving the "Operate" request and executing it, the server application must be told how long it must wait before sending a response. An instance of the "FB_AcsiServiceResultClass" function block called "fbCompletion" is used for this. When an "Operate" request is received, it is set to the "Busy" state in the "OnCompletionWaitEvent" method and transferred to the Server application as an interface pointer. This now waits until "fbCompletion" is in the "Completed" state and then sends the response to the "Operate" request. If the "Operate" request is to be rejected directly, this is done in the "OnSetVPreEvent" method. The process of an "Operate" request is shown in the following figure.

Server - SBO Control with normal security 3:
Server - SBO Control with normal security 4:

This is just an example of the implementation of the SBOControl function in the TwinCAT PLC.