Siemens Step7 - Static FB Tag Array Games

esr@qissi

Member
Join Date
Nov 2012
Location
MI
Posts
3
Hello all.... I'm still coming to terms with Siemens PLC programming after many years of only knowing AB, so be gentle - :rolleyes:

I've got an FB with some tags and a few 'scratchpad' type arrays (type 'char') set up in the 'STAT' area. What I'm trying to do is take a few puzzle pieces and move them into certain bytes within those static arrays without specifically addressing the DB that I have assigned to my FB (e.g. P#DB500.DBX5.0 BYTE 5)

For one example, I have a BLKMOV where I'm moving a string value which is 5 characters/bytes into one of these arrays. I can directly use my 'STAT' string tag name, and the array tag name in the BLKMOV instruction, but cant define a length. Wil it actually copy all 5 bytes to the array?

The other example, is now taking the 5 bytes from the 'STAT' array above (or another), and moving them into another 'STAT' array at a particular byte. So basically copy byte#0-4 of ARRAY_01 into byte #10-14 of ARRAY_02. Again, I know I can reference the absolute DB and byte range, but is there a way to keep it generic and only reference the 'STAT' tags for the FB? I don't really want to have to go back and change stuff if my DB number has to be updated, and so I can use the base code in the FB with no (or very little) mods elsewhere in my program.

The majority of my code is LADDER (ala AB programming for years), since I'm still fumbling through STL (which I can see is pretty powerful).

Thanks in advance for any help or slaps on the wrist! ;)
 
When you specify the symbolic name for data to be passed to the SFC20 BLKMOVE, the entire declared data will be used.
If for example ypu have specified in the STAT area
#myCharArray : ARRAY[1..10] OF CHAR ;
or
#myString : STRING[10] ;
then you just have to specify #myCharArray or #myString for the BLKMOVE block.

The other example, is now taking the 5 bytes from the 'STAT' array above (or another), and moving them into another 'STAT' array at a particular byte. So basically copy byte#0-4 of ARRAY_01 into byte #10-14 of ARRAY_02. Again, I know I can reference the absolute DB and byte range, but is there a way to keep it generic and only reference the 'STAT' tags for the FB? I don't really want to have to go back and change stuff if my DB number has to be updated, and so I can use the base code in the FB with no (or very little) mods elsewhere in my program.

The majority of my code is LADDER (ala AB programming for years), since I'm still fumbling through STL (which I can see is pretty powerful).
To go 'inside' a declared variable is cumbersome and really not adviseable in Ladder.
You cannot specify for example #myCharArray[1..4].
You would have to copy individual chars, one-by-one, #myCharArray[1] ... etc.

If you want to do a lot of data manipulation, then SCL (= Structured Text) is much better suited to this.
In SCL you can declare multiple views for the same data ("AT" views), and/or do easy looping through arrays etc.

Maybe you could try to describe what you want to achieve to get better advice. Maybe there is a much more straightforward way to do what you want to achieve.
 
Last edited:
Thank you for the reply and info on the first item Jesper!

For my 2nd question, I guess I could show it with the absolute DB reference... and if I can do the same in STL that would be fine, just need to know how

So my 2 'STAT' arrays:

ARRAY_01, ARRAY[1..10] of CHAR
(Lets say this is byte '0' through '9' in my DB)

ARRAY_02, ARRAY[1..64] of CHAR
(And this one is byte '100' through '163' in my DB)

If I want to take 5 bytes from ARRAY_01 and move them to ARRAY_02 with an offset of 10 bytes, I would do a BLKMOV with absolute DB reference, it would look like this (roughly)

SRCBLK = P#DB500.DBX0.0 BYTE 5
DSTBLK = P#DB500.DBX110.0 BYTE 5

So to reiterate, the above would take the first 5 bytes of the 1st array, and essentially move/insert them with a 10 byte offset into my 2nd array.

I just want to do this without the DB# reference and use the 'STAT' arrays in the FB environment if possible.

Again, thanks for any help!
 
Just to check, I assume you're using Simatic manager (Step 7 v5) and an S7-300/400, correct? If you are using a newer 1500, then there are some improved commands you could use.

I'll second what Jesper said. What you want to do, grabbing from the middle of a symbol, is really only convenient to do symbolically at a large scale in SCL. The 300's are really based around absolute addressing, and symbolic programming is possible but limited. LD's method does work, of course, but can get tedious for large data sets quite quickly.

I noticed that you were using arrays of CHAR. If you are using them because they are conveniently one byte long, then that is fine, but you could use the BYTE data type. If you are using the array of CHAR because you want a string, there is a STRING data type you could use, that allows for the use of some specific string functions, including Insert and Replace, which could potentially be more helpful than block move. They would allow you to specify in which char of the string you start copying (allowing you to do things symbolically), but the down side is that they copy the WHOLE string, not just part of it. You would need to separate out the part of the string you want before you copy it (potentially with Left, Mid, or Right).
 
source code for FC1
Code:
FUNCTION FC 1 : INT
TITLE =
VERSION : 0.1


VAR_INPUT
  Source : ANY ;    
  Dest : ANY ;    
  Count : INT ;    
END_VAR
VAR_TEMP
  pSrc : ANY ;    
  pDest : ANY ;    
END_VAR
BEGIN
NETWORK
TITLE =

      L     P##Source; 
      LAR1  ; 
      LAR2  P##pSrc; 
      L     W [AR1,P#0.0]; //s7 byte and type
      T     W [AR2,P#0.0]; 
      L     #Count; //count
      T     W [AR2,P#2.0]; 
      L     W [AR1,P#4.0]; //db
      T     W [AR2,P#4.0]; 
      L     D [AR1,P#6.0]; //area ptr
      T     D [AR2,P#6.0]; 

      L     P##Dest; 
      LAR1  ; 
      LAR2  P##pDest; 
      L     W [AR1,P#0.0]; //s7 byte and type
      T     W [AR2,P#0.0]; 
      L     #Count; //count
      T     W [AR2,P#2.0]; 
      L     W [AR1,P#4.0]; //db
      T     W [AR2,P#4.0]; 
      L     D [AR1,P#6.0]; //area ptr
      T     D [AR2,P#6.0]; 

      CALL "BLKMOV" (
           SRCBLK                   := #pSrc,
           RET_VAL                  := #RET_VAL,
           DSTBLK                   := #pDest);



END_FUNCTION
 
FC2 source code
Code:
FUNCTION FC 2 : INT
TITLE =coded for chars/bytes only
VERSION : 0.1


VAR_INPUT
  Source : ANY ;    
  Dest : ANY ;    
  sourcestartindex : INT ;    //1 based
  deststartindex : INT ;    //1 based
  Count : INT ;    
END_VAR
VAR_TEMP
  pSrc : ANY ;    
  pDest : ANY ;    
END_VAR
BEGIN
NETWORK
TITLE =

      L     P##Source; 
      LAR1  ; 
      LAR2  P##pSrc; 
      L     W [AR1,P#0.0]; //s7 byte and type
      T     W [AR2,P#0.0]; 
      L     #Count; //count
      T     W [AR2,P#2.0]; 
      L     W [AR1,P#4.0]; //db
      T     W [AR2,P#4.0]; 
      L     D [AR1,P#6.0]; //area ptr
      L     #sourcestartindex; 
      +     -1; 
      SLD   3; 
      +D    ; 
      T     D [AR2,P#6.0]; 

      L     P##Dest; 
      LAR1  ; 
      LAR2  P##pDest; 
      L     W [AR1,P#0.0]; //s7 byte and type
      T     W [AR2,P#0.0]; 
      L     #Count; //count
      T     W [AR2,P#2.0]; 
      L     W [AR1,P#4.0]; //db
      T     W [AR2,P#4.0]; 
      L     D [AR1,P#6.0]; //area ptr
      L     #deststartindex; 
      +     -1; 
      SLD   3; 
      +D    ; 
      T     D [AR2,P#6.0]; 

      CALL "BLKMOV" (
           SRCBLK                   := #pSrc,
           RET_VAL                  := #RET_VAL,
           DSTBLK                   := #pDest);



END_FUNCTION
 
Thanks a ton for the info everyone... There is definitely a bit of a learning curve with the S7 stuff.

mk42 - to answer your question, yes.. Step7 v5.5, S7-315. Nice to know that the S7-1200 is a little more advanced. Hopefully I'll get the play with one of those soon. But for now, I know I need to get more acquainted with this model...

LD - I was wondering if there was a way to do what you supplied. Basically, you are manipulating the supplied input parameters from the FC call into a way that the BLKMOV would expect to see and accept right?... fooling the system essentially? I may check this out, since it is right along the lines of what I'm looking for - something modular that I can reuse else where in the code and just update the input variables.

I'll follow back up once I have had a chance to do some testing with these ideas.

Many thanks to all!!
 
esr@qissi

Try to decribe what you want to achieve. Not what are doing to achieve it.
Copying some data from one data area to another data area is a means to achieve something.

I have a feeling that what you want to achieve can be accomplished relatively easily, either with SCL or with some of the canned functions in the standard library.
If we know what the task is at a functional level, we can help you better.
 

Similar Topics

This is the first time I am working with Simatic Manager Step7 as I started my siemens journey with TIA which is pretty easy and do a lot of stuff...
Replies
3
Views
142
When you download a DB, the values get overwritten by what is in the "actual" column in offline DB. Does this happen at the start of the PLC...
Replies
6
Views
142
I have a word in some DB which I want to load to AR1 and use as a pointer. In order to do this I need to write L DBxy.DBW xy SLD 3 LAR1 I...
Replies
3
Views
533
Hi, I received a Step7 Backup from my client and tried opening this backup but it won't open as there seems to be files missing from the backup...
Replies
11
Views
3,014
Hi! i'm just wondering did there is any chance to change Set Time(TV) on Siemens plc timer without step 7 using c# or python if timer not set in...
Replies
1
Views
1,245
Back
Top Bottom