SCL indirect addressing questions

diwa130

Member
Join Date
May 2009
Location
Farmingdale
Posts
5
Hello,
I have a couple of problems I am trying to solve.
1. how to use indirect addressing with variables of type T (timer) similarly to
all the other variables, Q, I, DB etc. More in detail , I can use I[bytenum, bitnum]
or DB1.DW[bytenumber] etc. How can I use something like T[x] ? On the manuals is written that it is possible but apparently is not. Any clues ?

2. similar question but related to DB, while it is possible to use
DB100.DW[byteindex] , I find hard to use the same approach with DB[number].
I know that is possible to use WORD_TO_BLOCK_DB(DB(number).DW0) but this not solving my problems. I have the following FB with multiple instances db as in the following:

FOR LOOP ....
FB501.DB501(....parameters ...
END_FOR
and I would like to use something like that:
FOR LOOP .... with j increments ...
FB501.DB[j](....parameters ...
END_FOR

Thank You,
diwa130
 
As for DB I use this way:
myDB :WORD;
i :INT;
j:INT;
...............

// set i, j as you want, then
myDB:=INT_TO_WORD(500+i);

// then Use DB This Way

WORD_TOBLOCK_DB(myDB).dw[j]
 
SCL indirect addressing

Thank you Yuryas, but how can you use that approach for the
case of function block, multiple data blocks ?
I have
FB1.DB501(par1 := p1, par2 := p2 ,etc.);
FB1.DB502(par1 := p1, par2 := p2 ,etc.);
FB1.DB503(par1 := p1, par2 := p2 ,etc.);
and so on. The approach you showed is fine for addressing DB internal parameter, but what about the situation as before ?
Thank You ,
Walter
 
I know what you are trying to do but I don't think it can be done

Thank you Yuryas, but how can you use that approach for the
case of function block, multiple data blocks ?
I have
FB1.DB501(par1 := p1, par2 := p2 ,etc.);
FB1.DB502(par1 := p1, par2 := p2 ,etc.);
FB1.DB503(par1 := p1, par2 := p2 ,etc.);
and so on. The approach you showed is fine for addressing DB internal parameter, but what about the situation as before ?
Thank You ,
Walter
You are trying to turn a DB into a class complete with methods. I have never seen an example of an indirect call to a subroutine on a S7. I would like to do this myself.
 
diwa130,

my idea was simple:
In case of your FB interface and the internal variables structure are not complex,
you could make loop with one working DB and
using WORD_TOBLOCK_DB(myDB).dw[j] indirect addresses set initial state before FB call
from say "myDB=500+..." into FB's static Variables (there are appropriete fields in the working DB),
and after FB call to save state (output and static variables) into current "myDB=500+...".

The result be the same as it would be possible to use your record "FB500.DB[j]"
(Except for all this multiple DBs have to be preliminary set)

There is another idea to use call for several FBs with one DB
It is "Multiple Instance Data Block"
I have seen SCL Example here:
http://forums.mrplc.com/index.php?showtopic=14055

Thanks.
 
Last edited:
You want to address multiple instance DB values, by indexing through the instance part, is that right ?
For indexing, you need arrays unless you address absolutely in stead of symbolically. The problem is that it is not possible to create an array of FB declarations. So it is not possible, at least symbolically.
With absolute addressing, you can use Yuryas approach if you carefully dissect the data structures you want to index through. However, it is a nightmare of coding. You have to adjust your code everytime you change your data.

The same thing CAN be done symbolically by creating a shared DB with groups of ARRAYs of UDTs.
You then have to change from using FBs+IDBs to shared DBs+UDTs+FCs.
There is one important catch: The UDTs cannot contain FBs, not even FB4 (TON) for example. It all has to be made up of elementary data types and other UDTs.
If this is OK, you will find it is a piece of cake to index through whatever you want, as long as it is an ARRAY or ARRAYs of UDTs of ARRAYs etc. I use this extensively myself.
 
Thank You , for your insights. I was actually pursuing the approach you report at the end : I have wrapped the FB with another FB and DB and use arrays to indirect addressing the calls in the original FB. Of course it works fine, I just wanted to explore other approaches. Frankly I don't understand why SCL
has been designed in that a so poorly way. It doesn't make much sense. Moreover there are already many other well establishe languages (C++ for instance or even C) that can work much better. But this is another story.
Walter


diwa130,

my idea was simple:
In case of your FB interface and the internal variables structure are not complex,
you could make loop with one working DB and
using WORD_TOBLOCK_DB(myDB).dw[j] indirect addresses set initial state before FB call
from say "myDB=500+..." into FB's static Variables (there are appropriete fields in the working DB),
and after FB call to save state (output and static variables) into current "myDB=500+...".

The result be the same as it would be possible to use your record "FB500.DB[j]"
(Except for all this multiple DBs have to be preliminary set)

There is another idea to use call for several FBs with one DB
It is "Multiple Instance Data Block"
I have seen SCL Example here:
http://forums.mrplc.com/index.php?showtopic=14055

Thanks.
 
You are trying to turn a DB into a class complete with methods. I have never seen an example of an indirect call to a subroutine on a S7. I would like to do this myself.
Not really. We are very far away from a class concept. I wish that could be done. I just wanted to simply address indirectly DBs like other vars (I,M,Q, or even DBx.DW etc.)
Walter
 
I find that SCL works very well.
Some recommendations:
Start thinking symbolically in stead of absolute addresses.
And, at all cost, avoid using M addresses or S5 Timers in SCL code.
 
Thank You for you advise, I come from a C++/Java object oriented oriented background, so I alway think "symbolically" . I find SCL quite limited, but way much better than any other language in this business. Probably with a little effort they could have developed a better language.
Anyway, I was just curious about M addresses , why do you
think we should stay away from it in SCL ?
Regards,
diwa130

I find that SCL works very well.
Some recommendations:
Start thinking symbolically in stead of absolute addresses.
And, at all cost, avoid using M addresses or S5 Timers in SCL code.
 
I dont think that way about SCL specifically. I mean that for any STEP7 language.
The S5Timers and S5Counters, and M memory is an arcaic leftover from S5. It is just way too problematic to try and squeze these into structured reusable programming.
I only use these myself for quick-and-dirty programming where I need to check something in a hurry.
And, I have a few globals that I also use M addresses for.
 

Similar Topics

Hi, I am facing invalid data type when i compile SCL and no luck in finding any old threads? could point me out to right direction? Thanks...
Replies
3
Views
2,177
Hello, I am currently forced to use s7-1200 (6ES7214-1AG40-0XB0) PLC for one small project. I do have some experience with S7-300/400 mostly in...
Replies
6
Views
5,094
Hi all In a step7 SCL FB (NOT TIA portal) , I have declared many variables as IEC timers (SFB4). Now I need to iterate this variables (hundreds...
Replies
15
Views
7,874
Hi all, Trying to figure out how to convert a block I created in STL to SCL and I run into problems from line one, lol. Is there a way to input...
Replies
10
Views
3,239
Hi I am trying to read data from various DB's So "DB_HMI".Data1 := DB[PARAM].Data1 etc where PARAM = 1 to 99
Replies
8
Views
4,073
Back
Top Bottom