Description STEP 7 V5.x and STEP 7 (TIA Portal) provide various block protection facilities to protect the know-how of your programs in the blocks against unauthorized persons. You can also encrypt programs created in S7-SCL, S7-GRAPH and CFC and protect the block code against unauthorized access. The program code, the temporary/static variables and the network comments are then not displayed. It is not possible to change the protected block. The following table gives you an overview of the know-how protection facilities.
SIMATIC STEP 7
Setting up block protection
STEP 7 V5.x
LAD / FBD / STL
Input: "KNOW_HOW_PROTECT" in the STL source
Additional information is available in Entry ID: 10025431
Input: "KNOW_HOW_PROTECT" in the S7-SCL source
Additional information is available in Entry ID: 14761527
Input: "KNOW_HOW_PROTECT" in the S7-GRAPH source
Additional information is available in Entry ID: 10024793
Enable the "KNOW_HOW_PROTECT" function
in the CFC chart and SCL source
Additional information is available in Entry ID: 14761890
STEP 7 V5.5
LAD / FBD / STL / SCL
Using the function: S7-Block Privacy
Additional information is also available in Entry ID 45632073
STEP 7 (TIA Portal)
LAD / FBD / STL / SCL / GRAPH
Enable the block protection with the "Edit > Know-How Protection" function
Additional information is available in the STEP 7 (TIA Portal) Online Help under:
Setting up know-how protection
Opening know-how protected blocks
Removing know-how protection
LAD / FBD / SCL
LAD / FBD / STL / SCL
How can you open a data block in S7-SCL without declaring the DB explicitly?
For this programming, you can use the parameter data type BLOCK_DB (Fig. 01). At the time of compiling, the data block is not known, so the S7-SCL compiler cannot find the corresponding data type by means of the symbol table and tag declaration of the DB in question. If the DB is now accessed by absolute addresses, S7-SCL assumes that the data type is BOOL, BYTE, WORD or DWORD.
In the following example you will see how, by using absolute addressing, you can access an item of DB data. The DD0 data of a DB not known at the moment (db_test) is read in an FB.
The DD0 data area of the DB assigned when the FB is called has the DINT format. DD0 is to be further processed as a tag of the TIME type.
The statement "WORD_TO_BLOCK_DB(Code_2).dw[Byte_Index]...;" permits you to also access a DB indirectly. You must define the "Code_2" tag for the DB number with the WORD data type and the "Byte_Index" tag with the INTEGER data type.
If the number of the DB is an input parameter of the "BLOCK_DB" type for the function, you can access the DB indirectly with the "dbnumber.dw0" tag (of the BLOCK_DB type).
More information is available in the S7-SCL Online Help under
Instructions: For the variables of a data block that are assigned to a UDT (user-defined data type) and are of the data type STRING, for example, you must define the initial values within the UDT. Fig. 01 shows the declaration of two DB variables: "DB_Var_1" and "DB_Var_2".
Variable "DB_Var_1" in the data block is of the type "UDT1" (defined symbol: "UserType1"), where UDT1 includes the structured data type specification "String_1" of the data type "STRING". The initial value (e.g. "Start_Value") must be entered here in the UDT.
Variable "DB_Var_2" in the data block is of the type "STRING". Here you can assign the initial value (e.g. "Init_Value") directly.
We recommend proceeding as in the following table for initializing the data block or if the actual value is to be overwritten with the initial value for each data element.
In the SIMATIC Manager open the data block in the LAD/STL/FBD editor.
Set the data block view to "Data View" via "View > Data View".
Via the menu command "Edit > Initialize Data Block" you can transfer the initial values to the actual values.
Then you must once again load the data block into the CPU.
How do you call a function or system function that has a function type and thus an output parameter RET_VAL?
Many SFCs (system functions) have the output parameter RET_VAL (return value), which provides an evaluable error code. More information on system functions and the output parameter RET_VAL is available in the STEP 7 Online Help. You obtain the relevant Online Help by marking the SFC in the SIMATIC Manager and pressing the "F1" key.
Likewise a programmed function can return a function result - e.g. self-defined debugging. The table below gives a number of examples of how to call a function (FC or SFC) with a return value (RET_VAL) in S7-SCL:
Examples of calling a function (FC and SFC) with return value:
Function with return value INT:
Function call with return value:
Calling a system function (our example SFC24):
When you call the system function SFC 24 "TEST_DB" (test data block) you receive information about a data block in the CPU's main memory. The SFC24 determines the number of data bytes for the DB selected and checks whether the DB is write-protected.
The number of data bytes that the selected DB contains is output via the parameter "DB_LENGTH" and the parameter "WRITE_PROT" contains the information about the write-protection ID of the DB selected (FALSE means not write-protected).
Notes on string functions
When using a function the S7-SCL compiler creates a temporary variable for the function value on the stack. This variable has a fixed type-dependent length (1 to 8 bytes) for all functions except the string functions. In the case of a function with a return value of the STRING data type, S7-SCL calculates a string length of 254 characters. This data type is generally generated with a length of 256 bytes. A variable of the STRING data type (character string) has a maximum length of 256 characters with 254 bytes of net data.
However the maximum string length can be reduced to a number of bytes in the compiler settings in S7-SCL ("Tools > Settings... > Tab: Compiler"). If the return value STRING of an IEC function is assigned to a variable from the VAR_TEMP area, you must initialize that variable beforehand with a character string (for example, abc := '';).
Keywords FC call, Function call
How are instance and multi-instance DBs adapted in S7-SCL when interface changes are required in a function block?
When a function block is created as an S7-SCL source, it is sensible to create the instance DB in the source straight away. If the instance data block isn't declared in the corresponding source, it has to be regenerated each time the interface is changed (within another S7-SCL source). Otherwise, a data conflict would arise between the instance DB and the function block. However, if the instance DB is declared directly in the source of the function block, there is no need for this step. The instance DB is automatically created when you execute the command "File > Compile". Thus, the function block's changed tags are transferred directly to the instance DB. This prevents the possibility of a data conflict occurring.
Fig. 01 depicts the setup of a function block in an S7-SCL source with the declaration of the corresponding instance DB. Program the function block first, then the instance DB so that the function block variables are identified when the instance DB is created.
If one function block is called from within another function block, only one instance data block can be allocated in the case of function blocks with multi-instance capability. This instance data block is called a multi-instance DB. This involves declaring a static variable of the same type as the called FB in the FB where the call is made. The static local data (and block parameters) of the called function block then become a subset of the static local data of the calling block.
Fig. 02 shows the SFB4 being called in the FB22. A static "TON" type (symbolic name for the SFB4) variable is declared for the application of a common multi-instance DBs (for SFB4 and FB22), e.g. "SFB4_TON". The multi-instance data block DB22 is only programmed once the FB22 has been programmed by calling the SFB4.
In order to update instance data blocks, we would advise you to check the data block consistency in the SIMATIC Manager before downloading. Mark the block folder and open the dialog box "Edit > Check Block Consistency...". Then execute the function "Program > Compile all".
How can you read out the start information of an organization block (OB) in S7-SCL (e.g. the OB1 cycle time)?
Instructions: The table below describes the procedure for generating an S7-SCL source for an organization block and importing and reading the appropriate STL code into the source for the OB's start information:
Select the source file in the SIMATIC Manager and insert an S7-SCL source into your STEP 7 project with the menu command "Insert > S7 Software > SCL source".
Next open the S7-SCL editor by double-clicking on the S7-SCL source.
You can create an OB via "Insert > Block template > OB" in S7-SCL editor. An ARRAY OF BYTES is then created as default for the OB start information in the temporary area.
If you want to further process the start information of an OB in your S7-SCL source, open the following path in Explorer
You find the STL sources for the organization blocks here. Open the appropriate STL source, for example the OB1.STL and copy the STL code from the STL source into the S7-SCL source.
Enter the symbol name for the organization block of the S7-SCL source in the symbol table, for example the symbol name "Cycle Execution" for the OB1.
Now you have to adapt the syntax in the S7-SCL source:
At the beginning of the program, configure "TITLE" and "VERSION" with quotation marks (or delete "TITLE" and "VERSION"), for example TITLE='' and VERSION: '0.1',
Insert a semi-colon in the statement part after "BEGIN".
Then you can compile the S7-SCL source for the organization block.
In the following S7-SCL program, the temporary program "OB80_OB_NUM" is evaluated for the OB80 (Cycle Time Fault). If the cycle time was exceeded by the OB3, the OB80 is called and the marker M1.0 is set.
In the list (Fig. 02) there are the 44 organization blocks from STEP 7 that are included as S7-SCL sources (templates) in the download "OB_Templ.zip".
Copy the "OB_Templ.zip" file into a separate directory. After dearchiving, this file is saved in "OB Templates S7 SCL" in the STEP 7 library. This library contains the sources the 44 organization blocks listed above.