S7 Forwarding IN-Parameter of Pointer Type

lauu

Member
Join Date
Aug 2003
Posts
83
Hej All

I hope some of you can help me with this issue:

I want to make a function block where, the IN-Parameter of data type "pointer"(DB-Pointer) of the function block are "forwarded" to the IN-parameter of the called function (FC92, SHRB).

When I try this I get no errors form Step7, and when I download the code to the cpu(PLC-SIM) it run with out error, but it dosen't work?

I can't figure out what I'am doing wrong.

Forwarding.jpg
 
The reason your code does not work is that FC92 is being passed P##S_Bit i.e. a pointer to S_Bit. The pointer parameter is not being passed on, instead FC92 is shifting the area of memory where the S_Bit pointer is stored - namely the instance data associated with the FB. You cannot 'pass on' a pointer parameter.

One method to overcome your problem would be to use the pointer parameter data and copy the data you wish to shift into a static data area declared in the FB interface. You would then call FC92 using the static data area name. After the call FC92, you would then copy the static data area back to the source area. A limitation of this method is that you need to know the size of the data area involved so you can size the static data area and specify the size when copying the data.

Another method would be to implement your own version of FC92 but use an Any pointer as the parameter for S_BIT. Any pointers can be dynamically created during run time hence you can use them to 'pass on' parameters.
 
Thank you L D[AR2,P#0.0]

I get your point.

I think I will go with the Any-Pointer, and make my one Bit-Shift Function.

Best Regard
Jesper
 
Here's an alternative to FC92 that uses an any pointer instead.

Code:
FUNCTION FC 992 : VOID
TITLE =bit shift as FC92 but using Any pointer as input parameter
VERSION : 0.1
 
VAR_INPUT
DATA : BOOL ; 
RESET : BOOL ; 
S_BIT : ANY ; 
N : WORD ; 
END_VAR
VAR_TEMP
iDB : INT ; 
iLoopCount : INT ; 
bNew : BOOL ; 
bOld : BOOL ; 
END_VAR
BEGIN
NETWORK
TITLE =get start address of area to shift
	 L	 P##S_BIT; 
	 LAR1 ; 
	 L	 W [AR1,P#4.0]; //DB number fo any pointer
	 T	 #iDB; 
	 L	 D [AR1,P#6.0]; //area pointer
	 LAR1 ; 
NETWORK
TITLE =loop shifting bits
	 L	 #iDB; // DB number = 0 ?
	 L	 0; 
	 ==I ; 
	 JC	nodb; // if so then no db to open
	 OPN DB [#iDB]; // else open the DB
nodb: L	 #N; // get size of shift register
	 A	 #DATA; // get input data to shift register
	 =	 #bOld; 
 
Loop: T	 #iLoopCount; // for all data in shift register
	 A	 #bOld; 
	 =	 #bNew; // new value to write to shift register
	 A	 [AR1,P#0.0]; 
	 =	 #bOld; // read old data for next time round loop
	 A	 #bNew; 
	 AN	#RESET; 
	 =	 [AR1,P#0.0]; // write new data (if reset=1 then data=0)
	 +AR1 P#0.1; // increment pointer to next bit
	 L	 #iLoopCount; // 
	 LOOP Loop; 
	 SET ; // make ENO true
	 SAVE ; 
END_FUNCTION

Edit: added example call:-
anyany001.JPG
 
Last edited:
Thank you again L D[AR2,P#0.0]

I'am impressed your so fast, I can see why your name is
"L D[AR2,P#0.0]" :geek:

I hope I can help you some time, BUT I doubt, your the best!

Best Regards
Jesper 🍻
 
Note that FC92 accesses the "next" bit off the end of the shift register so if your shift register happens to exist at the end of a data block FC92 will generate an Area read error, FC992 will not :)
 
L D[AR2 said:
Note that FC92 accesses the "next" bit off the end of the shift register so if your shift register happens to exist at the end of a data block FC92 will generate an Area read error, FC992 will not :)

I will have that in mind, when using FC92(y)
 

Similar Topics

Hi Guys, I have a Stratix 5700 managed switch that will connected to another different network thus: Stratix 1 on 10.50.3.xx >connect through...
Replies
0
Views
102
Hi all - I'm having some trouble getting the S7-1200 PLCs we're using to respond to any kind of remote request when using port forwarding on the...
Replies
6
Views
201
Hi everyone, I have a customer that is using wireless modem to communicate to many different PLC's and HMI's. I just added my PLC and HMI to...
Replies
6
Views
3,799
Hi, I have a question about SQL. This question is a little to much on the IT side I suppose, but I will give it a try anyway as I do not have an...
Replies
6
Views
2,517
Hi all. I have a question regarding networking over several subnets. I am tasked with Automating an AB Intellicenter, which is now installed...
Replies
5
Views
2,745
Back
Top Bottom