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

indexed access to an array tag

  • Entry
  • Associated product(s)


QUESTION:
How can I address a tag via its index in an array consisting of elementary data types?

ANSWER:
Access to a tag via its index is possible via the absolute address of that tag. You can define the pointer address of the desired element from the start address of the array and the elementary data type used. You can then fetch and modify this tag via direct addressing in the address register.

Sample function:

In the example attached the absolute pointer address of a specific array tag of the index is determined in the function FC1.

FC parameters:

Parameter

Declaration

Data type

Description

data_type

INPUT

BYTE

Data type coding

index

INPUT

INT

Index of the array tag

address

OUTPUT

DWORD

Absolute address of the pointer format

db_number

OUTPUT

WORD

DB number

field_address

IN_OUT

ANY

ANY pointer at start address

At the input parameter "data_type" the function needs the coding for data type used in the field:

 

B#16#00

Data type BOOL

 

B#16#01

Data type BYTE

 

B#16#02

Data type WORD / INT

 

B#16#03

Data type DWORD / DINT

For the input parameter "index" specify the index of the array tag whose address you are supposed to find out.
Assign the ANY pointer of the start address the tag field to the input/output parameter "field_address".
The function returns the output parameters "address" and "db_number".

The "address" parameter contains the pointer address of the indexed element. If the array is in a data block, the "db_number" parameter contains the number of the data block. If the array is not in a data block, this parameter returns the value "0".

The download contains a STEP 7 V5 project with the function FC1, the data block DB1 and two sample calls from the organization block OB1. You can adapt the blocks to suit your needs.

array_index.exe

Copy the "array_index.exe" file into a separate directory and then start the file with a double-click. You can then open the 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.