Step 7: Access 'M' memory byte address inside FB

STL???

Member
Join Date
Sep 2005
Location
UK
Posts
879
Hi - Merry Christmas Plcs.net members!

I would like my function block to use a Memory byte address which i pass in as a start address to which all offsets inside the FB are based.

Basically if i want to call this block more than once - i can enter different start addresses and the block does the rest for me.

i first experimented with passing in a value as follows;
Code:
      L     #iStartAddress  // FB IN - type INT
      SLW   3
      LAR1  
      L     100
      T     MB [AR1,P#0.0]
      L     101
      T     MB [AR1,P#1.0]
      etc...........
This works well but i want people to be able to cross reference the start address to guide them to the FB.

so i tried this - it works but i was wondering if i'm over complicating matters.
Code:
      L     P##StartAddress            // Load Pointer into Accu (Ar1 has L14.0)
      LAR1                              // Load into Ar1            
      // Ar1 contents DI0.0 
      // Retrieve - Byte 6 Memory Area | Byte 7,8,9 Byte/Bit Address      
      L     D [AR1,P#6.0]               
      // Ar1 contents DI0.0        
      LAR1                              // Update Ar1
      // Ar1 contents M100.0
      L     50
      T     MB [AR1,P#0.0]
      L     51
      T     MB [AR1,P#1.0]
Is this ok inside a FB? are there any pitfalls with this approach? can it be done simpler?

Thanks in advance for any help on this matter.
 
Is this ok inside a FB? are there any pitfalls with this approach?

Indirect addressing inside FB's needs to take into account AR2 if you want to be able to use the FB as a multiple instance FB

How many MBs are you pre-loading inside the FB
 
Last edited:
Indirect addressing inside FB's needs to take into account AR2 if you want to be able to use the FB as a multiple instance FB

Thanks for replying LD - this is the part where i'm unsure to be honest.

To provide some background info, this is an existing program which has been converted from S5, each stations data is mapped to the same memory area - i believe this was a common practice back then.

The FB is unconditionally called and references a global DB via the OPN command so I'm thinking of converting the FB to a FC.

i want to create unique memory area's for each station - ultimately so monitoring is simpler.

How many MBs are you pre-loading inside the FB

14 bytes in total

Thanks
 
Instead of passing a pointer to the start byte, use 14 parameters, one for each of the bytes - they will all come up in the xref then.
 
Instead of passing a pointer to the start byte, use 14 parameters, one for each of the bytes - they will all come up in the xref then.

this is what ill do in the interests of simplicity :)

i did experiment doing the same inside a FC;
Code:
      TAR1  #dwSaveAr1

      L     P##pStartAddress            // Load Pointer into Accu (Ar1 has L14.0)
      LAR1                              // V memory?  

// make sure data type is 'M'        
      L     B [AR1,P#6.0]
      L     B#16#83
      <>I   
      JC    End

      L     D [AR1,P#6.0]               // Retrieve - Byte 6 Memory Area | Byte 7,8,9 Byte/Bit Address
      LAR1  

      L     50
      T     MB [AR1,P#0.0]
      L     51
      T     MB [AR1,P#1.0]
      L     52
      T     MB [AR1,P#2.0]
      L     53
      T     MB [AR1,P#3.0]
      L     54
      T     MB [AR1,P#4.0]
      L     55
      T     MB [AR1,P#5.0]
      L     56
      T     MB [AR1,P#6.0]

End:  LAR1  #dwSaveAr1
If i understand correctly V memory is the local data of the block in which my function is called (in this case OB1)

i have saved Ar1 before processing and restore it after so i shouldn't have any issues there.

what is the relationship between Fc parameters and V memory?
 
All parameters are passed to FC's by 32 bit area pointers. In the case of anypointers for example,(they occupy 10 ten bytes) the parameter is an area pointer which points to the location of the anypointer. The editor generates code which copies the anypointer data into local memory of the calling block, hence your FC will need to access the V area to access the pointer to the anypointer, and the anypointer data as well.
 
All parameters are passed to FC's by 32 bit area pointers. In the case of anypointers for example,(they occupy 10 ten bytes) the parameter is an area pointer which points to the location of the anypointer. The editor generates code which copies the anypointer data into local memory of the calling block, hence your FC will need to access the V area to access the pointer to the anypointer, and the anypointer data as well.

A lot goes on behind the scenes then :p
Seriously LD - your S7 knowledge is impressive.

STL???, what about posting the original Step5 FB? Perhaps there are other solutions also?

Kalle

Hi Kalle - i have requested the original S5 program - if it turns up ill update this thread.

i Appreciate you both taking the time to help me - thanks again.
 

Similar Topics

Hi all, We're having performance issues with opening larger Step 7 projects from a shared folder on a fileserver. Access speed to the server is...
Replies
2
Views
1,664
We're have an S7-300 (313C-2 DP) configured to talk to another PLC via a DP-DP coupler. We configured the I/O for the coupler with 3 blocks of...
Replies
6
Views
1,838
We added a Safety Gate to FB250 When I add two new I/O points to my ladder program I get the following error message when I save the program. I...
Replies
8
Views
4,194
Hi all, I need to access PLC values using an external program that I am writing. I have tried OPC but it is not fast enough or reliable enough...
Replies
5
Views
2,171
I am having a step7 v5.4 program where the blocks are encrypted and locked. And the manufacturer is stopped the support. Is there any ways to...
Replies
2
Views
175
Back
Top Bottom