pass a pointer to a function

kyoq

Member
Join Date
Sep 2006
Location
Poland
Posts
18
Hi, how to pass a pointer to a function ?
I want wtrite a function that get the pointer and starts fill (few bytes) bytes from the pointer

OB1:
CALL FC 666
pass_POINTER:=MB7
pass_ANY :=P#M 50.0 BYTE 10

FC666:
L P##pass_POINTER
T MD 200
LAR1
BEU

end in AR1 I have previous local data P#V29.0, why ?
 
Prior to calling FC666, the block editor generates a pointer to MB7 and stores that pointer in its temp local data. When FC666 is called, a pointer to the temp local data is used so you need use a pointer to a pointer as follows in FC666:

Code:
	  L	 P##pass_pointer
	  LAR1  
	  L	 W [AR1,P#0.0]			   //DB for pointer, =0 for M area
	  L	 D [AR1,P#2.0]			   //Area pointer
	  LAR1							  //AR1=M7.0
	  BEU
 
works ....but still i don't know why. How come pointer is passed ? AR has only 4 bytes capacity and in this way pointer needs 4 bytes and 2 bytes extra for DB number information.
 
The following description is a bit daunting, but may help give an insight into what goes on when you pass a pointer and anypointer to a function.

The following call shown in the ladder editor as
Code:
	 CALL FC	 1
	 p1:=MB7
	 p2:=P#M 50.0 BYTE 10
actually performs the operations shown below.

Code:
	 Call
	 BLD 1
	 =	 L	 20.0
	 L	 0
	 T	 LW	21
	 L	 P#M 7.0
	 T	 LD	23
	 L	 W#16#1002
	 T	 LW	27
	 L	 10
	 T	 LW	29
	 L	 0
	 T	 LW	31
	 L	 P#M 50.0
	 T	 LD	33
	 UC	FC	 1
			P#L 21.0
			P#L 27.0
	 BLD 2
	 End Call
As you can see, prior to calling the function, 0 for the DB is loaded into LW21 and the area pointer to MB7 is loaded into LD23 for the pointer parameter.
Similarly the components of the any pointer are loaded into LW27, LW 29 and LD31. FC1 is then called and the parameters are shown
as area pointers following the UC call statement. (Within the FC, when a parameter is referenced the code actually refers to the area pointers for the parameters).
Pointers and any pointers are passed to FC's by loading
them into local data and then passing a pointer to the local data area they are in. That's the way the Step7 editor works.

Note that the LW addresses used will just depend on what temp variables you have declared. The editor uses
local data following on from your declarations.
 

Similar Topics

Ok have read some of the old threads but this subject still confuses me.. What i want to do is: I have a FB wich i would like to pass what to...
Replies
12
Views
7,297
Sorry double posted thread.. The thread that is the correct is named Pass ANY Pointer to FB inside FB OT how to delete a thread?
Replies
0
Views
2,838
Hello, I am still new to PLC programming and I just got this job two year out of school so I don’t remember much. I was given a task were I have...
Replies
1
Views
181
So I'm having issues with a certain rung and one of my coworkers mentioned it may not allow the signal past the latch coil. For example in the...
Replies
27
Views
3,761
I’m a bit stuck on HMI (KTP-1200) programming… See the picture attached. The PASS or FAIL box should only appear when the toggle switch is...
Replies
7
Views
1,089
Back
Top Bottom