S7 Adres registers

Werner

Member
Join Date
Apr 2005
Location
IJsselstein
Posts
336
I have an FC.

Input: level_nr : INT
Output: Data : UDT9

In this FC I use indirect addressing to copy data from a DB to the output. When I'm looking online I see a V mark in the column of AR1. Does anybody know what this means?

It looks like:

--------------------------------AR1 AR2

OPN DB60 ----------------------0.0 92.0
L DBX[AR2,P#2.0]---------------0.0 92.0
T Data.Nr_batches ------------V 0.0 92.0

??????-------------------------^
 
Before I calculated a pointer on AR1. Does the V also mean that the AR1 register is overwriten by the temporary local data? With the pointer in AR1 the block wasn't working. Later I calculated a pointer in AR2, this seems to be working.
 
If you use a UDT as a parameter in an FC, AR1 is used to access each element of the UDT. Note also that if the parameter exists in a DB, the DB is left open after the UDT parameter access.
 
As a general rule you should store AR1/AR2 at very begining of your FC/FB and restore them at very end if you plan mess up with them. It will prevent your code in case of malfunction from hitting the rest of the program.
 
jacekd said:
As a general rule you should store AR1/AR2 at very begining of your FC/FB and restore them at very end if you plan mess up with them. It will prevent your code in case of malfunction from hitting the rest of the program.
I thought the plc automatically handles the AR1/2 when it jumps back into the calling block? I have played with both AR1 and 2 but I have never restored or had any problems with it (that I know of).

Cheers
Borte
 
So if I understand correctly: (looking at the code posted by SimonGoldsworthy)

1. In an FC AR1 is overwritten when using temporary local data
2. In an FB AR2 is overwritten when using temporary local data

So this is very tricky! (Especially if you make a small change in a program that already worked, what I did.) But the rewards can be a very short piece of code...There's always a catch to it.
 
SimonGoldsworthy said:
In a FC, AR1 is overwritten when referencing a parameter of type UDT. This is not what you have written - is this what you meant ?

Yes, sorry. I'm used to Visual Basic. So it's hard to get into the indirect addressing of Siemens. All things that look normal to me can't be done with Siemens.

Example: L DB60.DBW[AR1,P#2.0]
or: L DB60.DBW[Index] (I know CSL could do this...)
 
Last edited:
In this function I copy data from an DB to the UDT at the output of the function. Why do I have to open the DB every time between a copy? See code below

Code:
OPN DB	60
A	 DBX [AR2,P#0.0]
=	 #Info.Empty
OPN DB	60
A	 DBX [AR2,P#0.1]
=	 #Info.Loading

The DB1 registers is set to zero when coping data to the UDT. If I don't open de DB I get area length error when reading. Is there an other solution to prevent this? (Maby try to open the DB in an other register? or first copy all data to temporary data (not in UDT) and then in the end copy to UDT?):unsure:
 
Your instruction:

= #Info.Empty

will change AR1 and the DB1 register (if the value exists in a DB). The DB register is modified you must save the DB register before hand and then restore it afterwards. (From my testing, if Info.Empty is in the local data of the calling block, the DB register does not change - you would be unwise to rely on this though)
 
Is it possible to store the output of the function (The UDT) directly in an DB which also has the UDT defined in it? I tried to copy the output of the function with an ANY pointer to the DB. Unfortunately Siemens does not except my input! (P#DB16.DBX0.0 Byte 20)
 
An alternative is to declare the UDT in the local data area and then do

OPN DB 60
A DBX [AR2,P#0.0]
= #Local.Empty
etc....

then
A #Local.Empty
= #Info.Empty
etc...
 

Similar Topics

Hello, I got the following installation: We have 2 equal HMI displays (MP377) the only different is the MPI adres. Right now we have to change...
Replies
2
Views
3,052
Hello, I want to show the missing profibus adres on a display when a profibus slave is missing. How can i do this? (siemens S7 313C DP + TP177)...
Replies
3
Views
3,375
Hey, An example code of S7: LAR2 P#66.0 // Preset Basic Adres for AR2 L MW [AR2,P#9.0] // Call MW75, offset 9.0 + preset 66.0 T...
Replies
1
Views
1,665
Hi, I understand how this works, but when can u use stuff like this? : L MW 100 T MW 210...
Replies
7
Views
2,471
What is the best way to extract the hour and minute from the register that comes from Yaskawa VFD. In studio 5000 I have a register saved as INT...
Replies
3
Views
96
Back
Top Bottom