Indirect addressing in SCL

boneless

Lifetime Supporting Member + Moderator
Join Date
Feb 2008
Location
OKC
Posts
1,628
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 either a DB or a DB number into an FC?

My problem is that the DB can be 10 or 1000 values long, depending on my use. In STL I just input the number as an INT and use it from there.

Code:
OPN   DB [#DBNR]
L     DBW [DBD 0]

Any inputs would be great, thank you!
 
From the online help in the SCL editor:
STATUS_1:= DB11.DW[COUNTER];
STATUS_2:= DB12.DX[WNO, BITNO];
STATUS_1:= Database1.DW[COUNTER];
STATUS_2:= Database2.DX[WNO, BITNO];
STATUS_1:= WORD_TO_BLOCK_DB(INDEX).DW[COUNTER];

edit: I have to comment that it would be a good opportunity to tidy up the code.
Rather than accessing data values by absolute addressing, it is better to try to program symbolically as much as possible.
You can for example arrange data by UDTs and define ARRAYs for easy indexing. You can also make ARRAYs of entire STRUCTs and ARRAYs of ARRAYs.
If your data cannot be arranged in ARRAYs, then in SCL you can use the "alternative view" of data with the AT view to look at the data as an ARRAY anyway, and then do indexing of the data by means of the alternate view.
 
Last edited:
First two would not work since my DB number changes.
Second two would not work since my DB name changes.
Same goes for last.

Thanks though!
 
INDEX is just a number.

So if
INDEX := W#16#10 ; // since it is word/hex then it is actually 16 decimal

then
STATUS_1:= WORD_TO_BLOCK_DB(INDEX).DW[COUNTER];
//STATUS_1 refers to DB16.

If the WORD format is a nuisance, then use an INT and wrap it in an INT_TO_WORD.
 
Two lines in... Next problem lol.

Is there a SCL alternative for DBLG?
Code:
L     DBD    0
      L     DBLG                        //check if db is full
      SLD   3
      <D    
      JC    END1
      L     P#16.0
      T     DBD    0
      SET   
      =     DBX   14.0                  //db is filled
 
Last edited:
I got it to work, thanks all! I now just pass the number of samples I defined in the DB into my FC together with the DB number.

Related question.

Could I generate a DB automatically from my code?
I could then automatically generate a DB containing an array, with the amount of elements needed as specified by my sample input.
 

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,179
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,097
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,903
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...
Replies
10
Views
6,802
Howdy folks, I am an Allen Bradley guy currently living in an Emerson world. Working with Rx3i on PacSystems Machine Edition v. 9.6? i think...
Replies
3
Views
623
Back
Top Bottom