Pointers & Strings in STL (STEP7)

Supreame

Member
Join Date
Jul 2008
Location
Brasov
Posts
33
Hello,

I try to understand a function block where a string is copied from an address (source) to another address (destination) by using pointers and SFC20 (BLKMOV).

The function that does the job has the following code:

TAR1 #TAR1
TAR2 #TAR2

// Copies the UserName To the SRC

L P##UserName
LAR1
L P##Any_SRC
LAR2

L 5
L1: T #CNT
L W [AR1,P#0.0]
T W [AR2,P#0.0]
L P#2.0
+AR1
+AR2
L #CNT
LOOP L1


// Copies the CurrentUser to Dest

L P##CurrentUser
LAR1
L P##Any_DEST
LAR2
L 5
L2: T #CNT
L W [AR1,P#0.0]
T W [AR2,P#0.0]
L P#2.0
+AR1
+AR2
L #CNT
LOOP L2

LAR1 #TAR1
LAR2 #TAR2

// Copies the blocks

CALL SFC 20
SRCBLK :=#Any_SRC
RET_VAL:=#ReturnValue
DSTBLK :=#Any_DEST



Where the parameters of the FB are like this:

Name, Data_Type, Address, Interface_of_FB

UserName, Any, 10.0, IN
CurrentUser, Any, 30.0, IN

Any_SRC, Any, 0.0, TEMP
Any_DEST, Any, 10.0, TEMP



The FB is called with the following parameters:

UserName := P#DB420.DBX24.0 BYTE 16
CurrentUser := P#DB410.DBX136.0 BYTE 16



Content of DB420 is:

Address, Type, Initial_Value

+22.0, STRING[16], ''


Content of DB410 is:

Address, Type, Initial_Value

+134.0, STRING[16], ''



I think the bold part of FB does this things:

L 5 // AC1 = 5 (index)
L1: T #CNT // #CNT = AC1 (5)
L W [AR1,P#0.0] // AC1 = First Word from P##UserName[0]
T W [AR2,P#0.0] // AC2 = AC1 copy to P##Any_SRC[0] a Word from P##UserName[0]
L P#2.0 // AC1 = P#2.0
+AR1 // AR1 = AR1 + AC1; P##UserName[2.0] will be addresd in the first LOOP, then P##UserName[4.0] until P##UserName[8.0] (5 passes)
+AR2 // AR2 = AR2 + AC1; P##Any_SRC[2.0], and so on
L #CNT // AC1 = #CNT
LOOP L1 // AC1 = AC1 -1;
// if (AC1 > 0) JMP to L1
// else -> the program execution goes to the next line


The problem

If my understanding is correct (and please tell me) those instructions will copy only the first 5 Words from P##UserName to P##Any_SRC. This means that only 10 Bytes [0-9] are copied, but P##UserName points to 16 Bytes, starting from DB420.DBX24.0 and so 6 Bytes are suppoesed to remain uncopied. But in practice this FB is working well, all the characters from source string are copied to the destination string.

Please help me to solve this mistery !!!
 
The two sets of 10 bytes that are being copied are the anypointers to the source and destination strings. They are being copied to temp variables ANY_source and ANY_dest in preparation for the call to SFC20 which actually performs copy of the strings.
 
An anypointer for data types occupies 10 bytes as follows:

Byte 0 = siemens id = 16#10
Byte 1 = Type (bool, byte, int etc.)
Bytes 2,3 = Quantity
Bytes 4,5 = DB number
Bytes 6,7,8,9 = Area pointer
 

Similar Topics

Hello, I've just came out of a call where a program that was modified two weeks ago threw the processor into fault. The program has been done...
Replies
9
Views
3,470
I'm trying to get a 5069-L306er to talk to a Automation Direct ProSence Controller by using RA's AOI for modbus client but its stuck not getting a...
Replies
9
Views
1,881
The last time I did anything with Wonderware was just after the dot com bust. Boy, I feel old. Anyway, it looks like I will get the chance to...
Replies
3
Views
1,518
Hi guys, Some pointers needed: Having PC with WIN7 pro X64 and Amsamotion clone of 6ES7 972-0CB20-0XA0 cable and need to backup VIPA cpu...
Replies
14
Views
3,121
Is there any form of Reference Type or Pointer Type like Codesys has? I am aware that you can nut a tag in the index of an array reference. but...
Replies
7
Views
1,893
Back
Top Bottom