Local variables in Siemens S7-200

GEOFRA

Member
Join Date
Jul 2002
Location
Nicosia
Posts
99
I would like to ask a question regarding local variables in S7-200.
If I define a Byte in the local variable table of a subroutine and let's say this is assigned as LB5 then I can use it in my subroutine as #LB5 without any problem. If now I want to use the first bit of this byte I have to write L5.0 without a # .
My question is if this L5.0 is a local or a global variable since it is not preceded by a # sign. Is there a way to use L5.0 as a local variable?
 
There is no requirement to delcare local variables at any
S7 System (S7-200/300/400), like on a PC with high level programming langauge like C.
However, this editor function is released to offer you the ability to associate symbolic expressions to a specific memory
address.

There is no difference if you address the symbolic value for LB5 or directly e.g. L5.0, this is always the same local variables.

But there are 3 stages of local variables on S7-200.
The main program(OB1) has its own independent local memory area.
Also the subrotine and interrupt routines has its own.
This means L5.0 in OB1 is not the same like L5.0 in a subroutine.
 
Geofra,

to be short: L is always local data. Only if you use a symbolic name you have to precede the name with a # to distinguish it from a global variable. Global variables can be any type except L.

Kind regards,
 
Local variables

Thank you for your answers.
My problem is that I have written three subroutines that have only local variables.
If I call only oneof them in my main program each one alone works perfect.
The problem comes when I call more than one subroutine in my program. Then they don't run as expected and the behave strange.
The inputs/outputs to the subroutine are physical I/O and they are independent for each subroutine. The only variables that are not preceded by # in my subroutines are the bits of a local byte.
 
As i mentioned before the subroutines shares internal one
memory area for the local address area.
Therefore you program works as long you call only 1 subroutine, but fails if you call more(different).


The local addresses only offers a temporary storage while execution of a subroutine.
After end of that subroutine this memory storage is used by other subroutines, so at next cylce it could have any value.

The user is therefore responsible to preset all used local variables at begin and if required store them before leaving into global(persistent) addresses or pass back to the calling routine.
 
I don't know anything of Siemens.
Maybe he means funtion block instead of function. The local variables of a function block are static and the local variables of a function block are not static.
 

Similar Topics

Hey all, I have an AOI with multiple instances created in my running project. The question i have is: where do Local variables of each instance...
Replies
2
Views
1,128
Hi all one question about Logix5000 and AOI: normally I work with Siemens, and I use FBs with multi-instances Now I need to transpose the...
Replies
8
Views
2,709
As a relative newbie to Siemens I can not seem to find any documentation that explains the following. In an FB I have the following code (see...
Replies
5
Views
2,490
I changed a counter in a function block in Simatic S7 program on offline. Then i saved and closed the function block and open the data block...
Replies
1
Views
6,702
Hi folks. I am currently working on a little program that needs to index files in several directories and decide which ones need to be emailed...
Replies
1
Views
5,469
Back
Top Bottom