Entry type: FAQ, Entry ID: 21946854, Entry date: 04/18/2011
(0)
Rate

How can you construct an ANY pointer in S7-SCL using the AT function?

  • Entry
  • Associated product(s)

Instructions
In S7-SCL you can use the AT command to define other views of the declared variables. The two examples below describe how to declare the components for the ANY pointer, create the ANY pointer and parameterize the SFC20 (BLKMOV) for copying data from DB6 to DB7.

The table below describes how to proceed to define an ANY pointer in a function.
 

No. Procedure
1 STEP 7 saves the data of the parameter type ANY in 10 bytes. For this you must define a structured variable that contains the parameter types like "data type", "repeat factor", "DB number", as well as the byte and bit address for constructing the ANY pointer. Fig. 01 shows a sample declaration of the two structured variables "Test1" and "Test2" in the FC.


Fig. 01

2 Use the S7-SCL instruction AT to create a template via the structured variable "Test1" or "Test2" and declare the "ANY" type for the variable defined for this, for example "pAny_source". Thus with the instruction
  • "pAny_source AT Test1: ANY;"

you have defined an ANY pointer.

3 Now you must preset the ANY pointer with the structured instructions as in Fig. 01. The following instructions correspond to the structure of the ANY pointer "P#DB6.DBX0.0 Byte 10":
  • "Test1.Any_id:= 16#10;"  //Hex for the syntax ID
  • "Test1.Source_DataType:= 16#02;"  //for the data type Byte
  • "Test1.Source_Length:= 16#0A;"  //length here 10 bytes
  • "Test1.Source_DB_Number:= 16#06;"  //for DB6
  • "Test1.Source_Byte_Pointer:= dw#16#84000000;"  //byte and bit address of the data block
4 Parameterize the ANY parameters of the SFC20 (BLKMOV) with the defined ANY variables "pAny_source" and "pAny_destin" (Fig. 01), for example,
  • "erg:= SFC20(srcblk:= pAny_source, dstblk:= pAny_destin)";

The variable "erg" of the INT type corresponds to the function's return value (RET_VAL).

The table below describes how to proceed to define an ANY pointer in a UDT.
 

No. Procedure
1 To define the ANY parameters you first create a UDT, for example a UDT1 with the symbolic name "AnyPoint" for the parameters:
  • SyntaxID: BYTE;  //specification of the syntax ID
  • DataType: BYTE;  //code for the data type
  • DataCount: INT;  //repeat factor
  • DB_Number: WORD;  //number for data block
  • BytePointer: DWORD;  //pointer for byte and bit address
2 In the function you declare the variables, for example "buffer_source" (for the source DB) and "buffer_destin" (for the destination DB) of the type "AnyPoint" (UDT1). Use the S7-SCL instruction AT to create the templates via the structured variables "buffer_source" and "buffer_destin" and declare the "ANY" type for the variables defined for this, for example "Source_Any" and "Destin_Any". Thus with the instructions
  • "Source_Any AT buffer_source: ANY;"
  • "Destin_Any AT buffer_destin: ANY;"

you have defined the ANY pointers as in Fig. 02.


Fig. 02

3 Now you must preset the ANY pointer with the structured instructions as in Fig. 02. The following instructions correspond to the ANY pointer "P#DB7.DBX0.0 Byte 10" for the destination data block.
  • "buffer_destin.SyntaxID:= 16#10;"  //hex for the syntax ID
  • "buffer_destin.DataType:= 16#02;"  //for data type Byte
  • "buffer_destin.DataCount:= 16#0A;"  //length here 10 bytes
  • "buffer_destin.DB_Number:= 16#07;"  //for DB7
  • "buffer_destin.BytePointer:= dw#16#84000000;"  //byte and bit address of the data block
4 Parameterize the ANY parameters of the SFC20 (BLKMOV) with the defined ANY variables "Source_Any" and "Destin_Any" (Fig. 02), for example,
  • "erg:= SFC20(srcblk:= Source_Any, dstblk:= Destin_Any)";

The variable "erg" of the INT type corresponds to the function's return value (RET_VAL).

More information on the structure of the ANY pointer is also available in the Online Help of STEP 7 in the chapter entitled

  • Format of the ANY parameter type

Note
If you call a function with the STL program in S7-SCL, which has an OUT parameter of the ANY type, then parameterization with an ANY pointer, like "P#DB10.DBX0.0 BYTE 10", for example, is not possible in S7-SCL, because the ANY pointers are processed differently in STL and S7-SCL. When assigning from ANY to ANY in S7-SCL, the 10 bytes are copied from on pointer to the other (6 bytes) in order to forward the ANY pointers received to the INPUT parameters. To parameterize the ANY OUT parameters of an STL program we recommend variables of the "STRUCT" type (as described above in the example). If a variable of a type other than ANY is assigned to an ANY variable, then the S7-SCL compiler creates the address (10 bytes) and writes it to the ANY pointer.

Copy the "SCL_Any.zip" file into a separate folder and then start the file with a double-click. The STEP 7 V5.5 project then unpacks automatically with all the associated subdirectories. You can then use the SIMATIC Manager to open and process the extracted project. The STEP 7 project includes two stations. Station_1 contains the program for defining the ANY pointer in a function and Station_2 contains the program for defining the ANY pointer in a UDT.

SCL_ANY.zip ( 88 KB )

Keywords
Filter, Filtering, Data types of variables, Views of variables