Step 7 ANY pointer

barryoc

Lifetime Supporting Member
Join Date
Nov 2009
Location
Kilkenny
Posts
148
Hi guys,

I am just starting to write some STL and thanks to this forum I got the solution to what i was trying to achieve. The question i have is that in my code i needed to use SLD 4 instead of SLD 3 for my pointer to operate correctly. Can someone please explain why this is so. I understand that SLD 3 shifts the pointer to the byte level. Source code attached.

Just to explain what this is doing,
DB2 stores the on and off times for heating, Sun to Sat entered from HMI
DB4 is the current working on and off times for the current day.
If day is Sunday move DB2.DBW0-DBW 18 into DB4.DBW0-DBW18
If day is Tuesday move DB2.DBW40-DBW58 into DB4.DBW0-DBW18

Thanks,
Barry.
 
Last edited:
Your coding to calculate MD160 is based on the number of words( i.e 10) which is why you have to perform the SLD 4
Your comment in the posted code is incorrect, Weekday 2 starts at DBW20, not DBW10

Your calculation for MD160 should be based on the number of bytes (i.e. 20) then you would use SLD 3

Why have you chosen to use MD160 instead of a temporary variable?
 
Here is the relevant part of your function re-coded. I'm using AR2 as a temp holding register.
(Note you are not writing to the output return value)

Code:
FUNCTION FC 999 : VOID
TITLE =
VERSION : 0.1


VAR_OUTPUT
  return : INT ;    
END_VAR
VAR_TEMP
  psourcedb : ANY ;    
  pdestdb : ANY ;    
  iNumberOfBytes : INT ;        
END_VAR
BEGIN
NETWORK
TITLE =
      L     20; 
      T     #iNumberOfBytes; 

      L     DB99.DBW    0; //Sunday =1 Saturday = 7
      +     -1; //make zero based
      L     #iNumberOfBytes; // bytes for each day of on off times
      *D    ; //byte number for day times
      SLD   3; //convert to pointer format
      LAR2  P#DBX 0.0; //offset from DB
      +AR2  ; 
NETWORK
TITLE =
//Bar Heating, Move preset times from DB2 into DB4, The working area.
      LAR1  P##psourcedb; 
      L     W#16#1002; 
      T     W [AR1,P#0.0]; 
      L     #iNumberOfBytes; 
      T     W [AR1,P#2.0]; 
      OPN   DB     2; //DB use will come up in xref
      L     DBNO; 
      T     W [AR1,P#4.0]; 
      TAR2  ; 
      T     D [AR1,P#6.0]; 

      LAR1  P##pdestdb; 
      L     W#16#1002; 
      T     W [AR1,P#0.0]; 
      L     #iNumberOfBytes; 
      T     W [AR1,P#2.0]; 
      OPN   DB     4; //DB use wil come up in xref
      L     DBNO; 
      T     W [AR1,P#4.0]; 
      L     P#DBX 0.0; 
      T     D [AR1,P#6.0]; 


      CALL SFC   20 (
           SRCBLK                   := #psourcedb,
           RET_VAL                  := #return,
           DSTBLK                   := #pdestdb);


END_FUNCTION
 
Last edited:
Cheers LD,

My comment on day 2 pointing to DBW10 was a typo. Only starting out in writing code in STL. I am going to study the code you posted and hopefully you will answer any questions that i may have.

Many thanks,
Barry.
 
Guys, a bit of guidance needed. I used the above code that LD wrote and it worked perfectly, i think. Now i'm getting plc stop caused by:

area lenght error when writing
Event id: 86

When i change T W [AR1, P#X.0]
To T LW [Ar1, P#X.0] on all lines it works fine.

I know LD wrote the code in SCL. I entered it in STL. Is this a reason why?

Can someone explain the reason for this.

Sorry if this is a stupid question guys.

Regards,
Barry.
 
If you have DB4 downloaded in the PLC, then your pointer is trying to address an area that is beyond the end of the DB.

The reason it doesn't stop (NB note that I did NOT say the reason it works) when you change the address to LW... is that you are then accessing the Local TEMP memory (of which there is enough) so that you don't get an address error - on the other hand, you don't get the correct data either!
 
Guys, a bit of guidance needed. I used the above code that LD wrote and it worked perfectly, i think. Now i'm getting plc stop caused by:

area lenght error when writing
Event id: 86

When i change T W [AR1, P#X.0]
To T LW [Ar1, P#X.0] on all lines it works fine.

I know LD wrote the code in SCL. I entered it in STL. Is this a reason why?

Can someone explain the reason for this.

Sorry if this is a stupid question guys.

Regards,
Barry.

Guys, he is talking about the presetting of the anypointer that is defined in the L -area, and not the source or sink address. I allways use the L prefix here, didn't remember why, but it could be I've experienced the same.

Kalle
 
LD,

This is running in a 6ES7 315-2AF02-0AB0. I thought i had run this in a real PLC when it worked, but it must have been PLCSim.

Thanks for the suppport guys,

Barry.
 
Can you post a screen shot showing AR1 whilst monitoring this block or are you letting the CPU go into stop ?
 

Similar Topics

Hi all, I'm looking for a steer using a pointer. The code is working in a fashion but i'm not setting the bit i require. The code looks at...
Replies
25
Views
5,056
Hello, Is it possible to perform operation like pointer on function. Regardless of value inside pointer or what ever variable I want to call...
Replies
2
Views
1,500
I would need advice in design which we are currently making in Step 5. Control system is based on Control modules which have defined structure...
Replies
6
Views
1,680
Hello Folks! I'm still trying to get the hang of using STL and Pointers in Step 7 (V5.5). For background, I'm writing a sample application...
Replies
7
Views
3,286
Hello everybody How we can use pointer for Timers and counters,so that we could change Timer or counter address in the program?
Replies
7
Views
2,268
Back
Top Bottom