Transfer AnyPointer To FC in Step 7

Rusty_K

Member
Join Date
Mar 2004
Location
Norway
Posts
73
Hello,

I am currently building an FC which calls SFC21 "BLKMOV" from inside it :

CALL "BLKMOV"
SRCBLK :=#PriSec_AnyPointer
RET_VAL:=#Retun_Value
DSTBLK :=#Jokan_PriSec_AnyPointer

I would like to have the source and destination blocks dynamic, in the sense that the can be entered as inputs to my FC. I've tried declaring inputs of type "Any" and passing them into my FC. I've then tried plugging them directly into "SRCBLK" and "DSTBLK" but Step7 will not except them. I keep getting the error : "Declaration range of the actual side VAR_INPUT does not fit the formal declaration range VAR_OUTPUT of the formal parameter DSTBLK"

Any ideas on what I'm doing wrong?

Any help would be greatly appreciated...thank you kindly for your time

Cheers,

R.K.
 
Hi Simon,

Thank you kindly for your reply. Yes, this is what I am currently doing..I was wondering if it was possible to avoid all this and simply enter the anypointer as an input to the FC and plug that in directly to the BLKMOV function found inside my FC.

Based on the approach you took, I'm guessing this is not possible..am I right to assume this? Is there any reason why it cant be done?

Thanks again for the help

R.K.
 
Yes, like I said in my first original post...I get the error :

"Declaration range of the actual side VAR_INPUT does not fit the formal declaration range VAR_OUTPUT of the formal parameter DSTBLK"

This happens only when I pass the any pointer into the FC and plug it into the BLKMOV located inside the FC. If I type the any pointer directly into the SFC "BLKMOV" then it works..the idea is I'm trying to create a universal FC that I can use in several places, hence the pointer to the area will change.

Anyone have any ideas?

R.K.
 
Oh, sorry for the confusion! My FC is doing a lot more than just the block move..it's comparing ASCII characters, setting outputs etc. I use the block move to index values in a DB.

Cheers!

R.K.
 
I'm guessing that he has other code in his FC, which would make it handy to use dynamic pointers.

In any case Rusty, you will have to move the FC input variables to local variables, and then it will work. I do that all the time. Here is an example (Source and Destination are local ANY variables; the other variables are you inputs to the FC):

L P##InputPointer

LAR1

L P##Source

LAR2



L D [AR1,P#0.0]

T LD [AR2,P#0.0]

L D [AR1,P#4.0]

T LD [AR2,P#4.0]

L W [AR1,P#8.0]

T LW [AR2,P#8.0]



L P##DestinationPointer

LAR1

L P##Destination

LAR2



L D [AR1,P#0.0]

T LD [AR2,P#0.0]

L D [AR1,P#4.0]

T LD [AR2,P#4.0]

L W [AR1,P#8.0]

T LW [AR2,P#8.0]



CALL "BLKMOV"

SRCBLK :=#Source

RET_VAL:=MW10

DSTBLK :=#Destination


There are many ways to do this, but this is pretty straight forward.
 
Awesome! That's the answer I was looking for!

I'll give it a shot and let you know how it pans out!

Thanks for all the help Simon & S7Guy!

Cheers!

R.K.
 
Just posting this when I saw S7Guy had also posted ! Dont forget to save AR2 if any of this code has been called from a function block higher up.

Code:
FUNCTION FC 1 : VOID
TITLE =pass on any pointers to sfc20
VERSION : 0.1


VAR_INPUT
  pSource : ANY ; 
  pDestination : ANY ; 
END_VAR
VAR_OUTPUT
  sfc20Return : INT ; 
END_VAR
VAR_TEMP
  pSrc : ANY ; 
  pDest : ANY ; 
  dwtar2 : DWORD ; 
END_VAR
BEGIN
NETWORK
TITLE =source any pointer

	  TAR2  #dwtar2; //save ar2
	  L	 P##pSource; 
	  LAR1  ; 
	  LAR2  P##pSrc; 
	  L	 W [AR1,P#0.0]; 
	  T	 W [AR2,P#0.0]; 
	  L	 W [AR1,P#2.0]; 
	  T	 W [AR2,P#2.0]; 
	  L	 W [AR1,P#4.0]; 
	  T	 W [AR2,P#4.0]; 
	  L	 D [AR1,P#6.0]; 
	  T	 D [AR2,P#6.0]; 

NETWORK
TITLE =destination any pointer

	  L	 P##pDestination; 
	  LAR1  ; 
	  LAR2  P##pDest; 
	  L	 W [AR1,P#0.0]; 
	  T	 W [AR2,P#0.0]; 
	  L	 W [AR1,P#2.0]; 
	  T	 W [AR2,P#2.0]; 
	  L	 W [AR1,P#4.0]; 
	  T	 W [AR2,P#4.0]; 
	  L	 D [AR1,P#6.0]; 
	  T	 D [AR2,P#6.0]; 

NETWORK
TITLE =block move

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

	  NOP   0; 
NETWORK
TITLE =restore ar2

	  LAR2  #dwtar2; 

END_FUNCTION
 
And as a late tailpiece, the reason you can't do it by simply passing the name of the input parameter is, to quote the STEP7 manual,

"STEP 7 restricts the assignment of formal parameters of an FC as actual parameters for the formal parameters of a different FC. You cannot, for example, assign parameters with complex data types or a parameter type as the actual parameter."

So there you have it. Clear as ... well, clear as you'll find in a Siemens' manual anyway.

As far as I can see you should be able to do it with 'simple' data types declared as parameters (INT, BYTE, WORD etc) but passing on 'complex' parameters (ARRAY, ANY, POINTER etc) is strictly verboten.

Regards

Ken
 
Any idea why??

Hey guys-

Don't know if anybody's still monitoring this, but I've got a question: does anybody know *why* you can't pass on a formal parameter of "non-elementary" type? I can't for the life of me think of a good reason, since it will pass a local variable of the same type, and it makes things difficult (though not impossible) when writing a library of functions that operate on complex data types. Guess I should be used to the power of Step7 by now...

Anyway, thanks for the explanation, Ken- yours was much more straightforward than the manual's.

Steve
 
Elementary data types are passed to FC with their values located in the local data of calling block (you can check this by L P##parameter), complex data types are passed as pointers (also located in local data of calling block). Internally Step7 translates access to complex data type for ex. structure to something like this:
You are writing:
L Structure.Element // Element is Word type
PLC executes:
OPN DB xxx // if Structure is located in the DBxxx
LAR1 StructureStartingAddress
L W[AR1,P#Y.0] // Y is offset to Element from StuctureStartingAddress.
Thats why complex parameter types cannot be passed.
 
All parameters to FC's are passed by pointer.

The problem I see with passing on parameters concerns data that is passed in the V area, i.e. in the local data area of the calling block. In order to pass this data on to another block, the data would have to be copied into the local data area of the block that is passing on the parameter - but, and it's a big but, the block trying to pass on the data does not know how much data to copy.
 
Last edited:

Similar Topics

I'm trying to verify a project with a PLC. The Transfer Setup menu item is grayed out and every time I click Verify with PLC, I get an error...
Replies
1
Views
55
Hello, I need to create an automatic transfer panel that connects to the generator when the mains power is cut. I can draw up to 60kW and draw up...
Replies
0
Views
86
Does anyone know what the data transfer rate for this series of CompactLogix PLC's? 1769-L24ER-QB1B to be exact. Cheers.
Replies
1
Views
98
Hi all, Im having trouble transferring a program from one panelview 550 to an new one. I can insert a flash card into the old panelview and upload...
Replies
20
Views
357
Hi Everyone, I have a customer that needs a CQM1H (CPU51) replaced. They purchased the processor new-old-stock from a source they found online...
Replies
3
Views
354
Back
Top Bottom