Step7 - BLOCK_DB and ANY parameters

RMA

Member
Join Date
Sep 2004
Location
North of Hamburg, Germany
Posts
2,052
This is probably one for Simon again! I've got an FB called "CopyByte" which does exactly what its name suggests. As parameters it requires Source, Destination, Number_of_Bytes and Error. Source and Destination are both ANY-parameters.

My problem is that this time I need to have different Destination DBs, so the DB Number is only available as a BLOCK_DB parameter. Is there any way I can use this for the Destination parameter - so far I haven't found one! Is this possible or must I just copy each Byte one by one into the opened DB? In this case it's not too painful, because the Source is in the IDB and we're only talking about sixteen Bytes, but if were a couple of hundred, it wouldn't be so much fun!

Cheers

Roy
 
Last edited:
Are you currently creating the source and destination parameters dynamically or hardcoding them ?

Edit: Does CopyByte copy source byte 1,2,3,4,n to Destination byte 1,2,3,4,n (i.e. a block copy) or does it Copy source byte 1 to destination bytes 1,2,3,4,n (i.e. a block fill) ?
 
Last edited:
Until now I've been using hard-coded parameters, but this time I want to keep things general because this program will almost certainly be used again and this particular DB will be different each time, so I want to be able to pass it over as a parameter.

Edit:

In this case, it's a Block Copy function.
 
Last edited:
Do you want to add parameters to your exisiting FB to pass in the destination DB and (a boolean to use it or not) or leave the interface the same and dynamically create the desination any pointer in the calling block ?
 
I'm not sure if I've understood your question correctly, partly because I'm spreading confusion myself. I'm writing a new FB to fetch supplementary data from a Cognex camera. Depending which Station (1 - 4) the camera is in, the resultant data needs to be stored in the appropriate DB (60 - 63). This DB, I want to pass over to my FB as a parameter.

The CopyByte FC (incorrectly called an FB in Post 1) should then copy the Data from the Receive Buffer of the Cognex Camera's DB to the Send buffer of DB60 - DB63 (which sends the data to the AMS-PC) as required. The DB is available as a BLOCK_DB parameter, but I can't find a format that will allow me to use the Parameter (called AMS_DB) directly. Is there some way that I can use the BLOCK_DB to create (and store) an ANY parameter that the CopyByte FC will accept?
 
Here's an example FB that creates an any pointer at run time and passes it to SFC21 to perform a sfc21 fill (I used this for ease of testing). Does this make sense and can you now see how to solve your problem ?

Code:
FUNCTION_BLOCK FB 2
TITLE =
VERSION : 0.1

VAR_INPUT
  DestDB : BLOCK_DB ; 
  iNumberOfBytes : INT ; 
END_VAR
VAR
  StaticData : BOOL ; 
END_VAR
VAR_TEMP
  TempData : BYTE ; 
  RunTimeCreatedAny : ANY ; 
END_VAR
BEGIN
NETWORK
TITLE =create a run time any pointer
	  LAR1  P##RunTimeCreatedAny; 
	  L	 W#16#1002; 
	  T	 W [AR1,P#0.0]; //pointer of bytes
	  L	 #iNumberOfBytes; 
	  T	 W [AR1,P#2.0]; 
	  OPN   #DestDB; 
	  L	 DBNO; 
	  T	 W [AR1,P#4.0]; //db number
	  L	 P#DBX 0.0; //destination area
	  T	 D [AR1,P#6.0]; 
 
NETWORK
TITLE =example for test - sfc21 fill
	  L	 99; 
	  T	 #TempData; 
	  CALL "FILL" (
		   BVAL					 := #TempData,
		   RET_VAL				  := MW	 0,
		   BLK					  := #RunTimeCreatedAny);
END_FUNCTION_BLOCK
 
I'm going to need to look at that in peace over the weekend (tomorrow's a holiday in southern Germany and I'm off on my way back home in 20 minutes) before I understand it completely, but I can already see that it solves my problem.

Thanks a lot!

Cheers

Roy
 
Roy, the any pointer parameter story as follows. When you create a function
call with an any pointer as a parameter, the block editor creates code in the
background. All parameters to functions are passed as area pointers (4 bytes),
so, as any pointers occupy 10 bytes the parameter passed to the FC will be an area
pointer giving the location of the any pointer. The temp local area is always used
for passing any pointers. In the example code below FC2 has one input parameter of type
anypointer.


Example 1:

Any pointer to Static data area var address=2.0
Static data for this fb starts at 4.0
Here is the code as normally shown by the editor:
Code:
	 CALL FC	 2
	 pAny:=#StaticVarReal
	 NOP 0

And now with the hidden code produced by the editor revealed. The any pointer
is contructed by the code starting at L21.0 and then L21.0 is passed as the area pointer
to FC2. Note that in this example even though the data is located in the static data area
of a function block, the code generates the absolute address of the variable within the
instance DB, so the anypointer is actually refering to global data.
Code:
	 Call
	 BLD 1
	 =	 L	 20.0
	 TAR2 LD	16	 //Save ar2 in local data
	 L	 W#16#1008	//generate any pointer of type 8=Real
	 T	 LW	21
	 L	 1			//number of elements=1
	 T	 LW	23
	 L	 DINO		 //get current instance DB
	 T	 LW	25
	 +AR2 P#2.0		//add on address of staticvarReal to give 
	 TAR2			 //absolute area pointer of StaticVarReal 
	 LAR2 LD	16	 //restore AR2
	 T	 LD	27	 //ptr address into any area
	 UC	FC	 2
			P#L 21.0	 //any pointer has been contructed starting at L21.0
	 LAR2 LD	16
	 BLD 2
	 End Call
	 NOP 0


Example 2:
Any pointer to Temp local data var address=2
Here is the normal code
Code:
	 CALL FC	 2
	 pAny:=#TempVarReal
	 NOP 0

And now with the hidden code produced by the editor revealed.The any pointer
is contructed by the code starting at L21.0 and then L21.0 is passed as the area pointer
to FC2. TempVarReal exists in local memory at L2.0

Code:
	 Call
	 BLD 1
	 =	 L	 20.0
	 TAR2 LD	16	 //save ar2
	 L	 W#16#1008	 //generate any pointer of type 8=real
	 T	 LW	21
	 L	 1			 //number of elements=1 
	 T	 LW	23
	 L	 0			 //DB number=0 for local data
	 T	 LW	25
	 L	 P#L 2.0	 //Area pointer to TempVarReal
	 T	 LD	27
	 UC	FC	 2
			P#L 21.0	 //any pointer has been contructed starting at L21.0 
	 LAR2 LD	16
	 BLD 2
	 End Call
	 NOP 0

Example 3:

any pointer to hardcoded area
Normal code
Code:
	 CALL FC	 2
	 pAny:=P#DB99.DBX 0.0 INT 33
	 NOP 0

And now with the hidden code produced by the editor revealed. Same story as the previous examples.
Code:
	 Call
	 BLD 1
	 =	 L	 20.0
	 TAR2 LD	16	 //save ar2
	 L	 W#16#1005	//generate any pointer of type 5=int
	 T	 LW	21
	 L	 33		 //number of elements=33
	 T	 LW	23
	 L	 99		 //DB number=99
	 T	 LW	25
	 L	 P#DBX 0.0	//area pointer
	 T	 LD	27
	 UC	FC	 2
			P#L 21.0	 //any pointer has been contructed starting at L21.0
	 LAR2 LD	16
	 BLD 2
	 End Call
	 NOP 0

Example 4:
any pointer from temp var of type any at address=6
Normal code
Code:
	 CALL FC	 2
	 pAny:=#TempVarAny
	 NOP 0

And now with the hidden code produced by the editor revealed. The editor produces the
following code when you specify a temp variable of type any. The editor has not produced
any code to contruct the any pointer, it just passes the area pointer to the any pointer.
The assumption here is that you, the programmer, have contructed the any pointer yourself
starting at L6.0 before calling the FC. (In this example I have not done so)

Code:
	 Call
	 BLD 1
	 =	 L	 20.0
	 TAR2 LD	16	//save ar2
	 UC	FC	 2
			P#L 6.0	 //code assumes any pointer has been contructed at L6.0
	 LAR2 LD	16
	 BLD 2
	 End Call
	 NOP 0

Hope this fills that gap in the weekend !

Regards, Simon
 
When the temperature finally went over 32°C in the shade on Sunday, I decided it was time to retire indoors with Berger and this Thread. After about an hour I came to the conclusion that I finally understand what's going on here. However, as with Maths classes, understanding what the teacher has explained and knowing how and when to implement it are occasionally two very different things! So I may still be back with some follow-up queries.

In the mean time, I now know why you aren't allowed to create DB0!

By the way, how do you manage to persuade the editor to show the "hidden" code, or do you possess powers that we lesser mortals don't have?

Thanks for the clear and concise (as usual :D) explanation.

Cheers

Roy
 
The method I use to reveal the code is as follows:

I use a test project which I copy blocks into to perform these actions, not the actual project.

Download the block doing the calling and the called block to the plc (I use the simulator). Delete both blocks from the offline folder. (After this step, the editor has lost all knowledge of the interface of the block being called). Copy the block doing the calling (and only this block) from the online folder to the offline folder. Open the block doing the calling in the offline folder and the hidden code will be shown. Note that you will receive various warnings as all variable names have been lost.
 
Sorry about the time it's taken me to get back and say thanks for the explanation. I'm sure it'll come in useful sometime. It reminds me a bit of how to look at S7GRAPH code in the STL editor - not necessarily useful, but interesting.

Cheers

Roy
 

Similar Topics

My Step7 program has several Data Blocks built from UDT structures that no longer show the symbol names from the original UDT, just STAT. How do...
Replies
1
Views
1,875
Hello, I posted a thread and it did not seem to go through so I will try again.. I am looking for sample code for a Duty/Standby block for a pump...
Replies
3
Views
2,735
Hello to all members of this thread, I've been trying to compare siemens step7 project online and offline block comparison in ladder. when I click...
Replies
2
Views
6,072
Hello friends, Two days ago something strange happened that I cannot edit data blocks ie change the contents of data blocks. They turned to gray...
Replies
2
Views
7,756
Hi all. I wan't to copy a string message(160 characters) in to a Datablock from wich a SMS message(also 160 characters) is sent. I've tryed to...
Replies
10
Views
6,906
Back
Top Bottom