×
Siemens Industry Online Support
Siemens AG
Entry type: Application example Entry ID: 5442006, Entry date: 10/23/2000
(0)
Rate

indexed processing of arrays with composite data types

  • Entry
  • Associated product(s)


QUESTION:
How can I have variable access to elements of arrays with composite data types?

ANSWER:
Variable access to elements of arrays with composite data types can only be done via a separate function. As transfer parameters this function thus has the desired array number and the start address of the array [0]. The requirement for the function is that the array is located in a data block and that the array [0] is not used for current data. The determines the addresses from the parameters transferred and copies the specified array into the array [0], which serves as processing area. Then the array can be processed symbolically. Afterwards this is copied back to the original array number.

Programming notes for the function:

  • Configure a function with the parameters given below.
  • From the parameters define and calculate the addresses for the array [0] and the array numbers to be processed. Save these in the temporary tags of the function.
    L P##Field_Start // enter the field address [0]
    LAR1
    L D [AR1,P#0.0] // save the addresses in the temporary tags of the type ANY
    T LD 0 // temp 'firststruc' = LD 0-9
    T LD 10 // temp 'sourcestruc' = LD 10-19
    L D [AR1,P#4.0]
    T LD 4
    T LD 14
    L W [AR1,P#8.0]
    T LW 8
    T LW 18
    L LD 16 // define the address of the desired array
    LAR1
    L #Indices
    L LW 12
    *I
    SLD 3
    +AR1
    TAR1 LD 16
  • Then using the SFC20 (BLKMOV) copy the array to be processed into the array [0].
  • Now, depending on the requirements of your application, you can symbolically access the indexed array.
  • Then, using the SFC20 (BLKMOV), copy the array [0] back into the original area.

Note:
In the STEP 7 online help under
"Help > Help Topics > Index > Format: BLOCK > Parameter type ANY"
you will find a description of the structure of the ANY pointer. Under
" Help > Help Topics > Index > ANY, Parameter:Description and Application"
you will find an example of how you can specify the data area indirectly.

FC Parameters:

Declaration

Name

Type

Comment

In

Indices

INT

Transfer of desired array number

In_out

Field_Start

ANY

Specification of the address of the array [0] of the DB with its structure

temp

firststruc

ANY

Memory for the ANY pointer of array [0]

temp

sourcestruc

ANY

Memory for the ANY pointer of the desired array number

temp

ret_value

ANY

Memory for the ANY pointer for the array [0]

The example includes the function FC2 which is called via the organization block OB1. Futhermore there is a data block DB2 available with an array of the data type "STRUC", which contains various elementary data types. If you use this example, you have to adapt the data block DB2 to suit your requirements and change the user code in Network 3. The FC2 can be used for all composite data types.

Aarray.exe

Copy the "Aarray.exe" file into a separate directory and then start the file with a double-click. The STEP7 V5 project is now unpacked with its associated subdirectories. You can then open and process the unpacked project with the SIMATIC Manager.

Security information
In order to protect technical infrastructures, systems, machines and networks against cyber threats, it is necessary to implement – and continuously maintain – a holistic, state-of-the-art IT security concept. Siemens’ products and solutions constitute one element of such a concept. For more information about cyber security, please visit
https://www.siemens.com/cybersecurity#Ouraspiration.
Rate entry
no rating
Requests and feedback
What do you want to do?
Note: The feedback always relates to the current entry / product. Your message will be forwarded to our technical editors working in the Online Support. In a few days, you will receive a response if your feedback requires one. If we have no further questions, you will not hear from us.