STL String copy (as ANY parameter) error!

Supreame

Member
Join Date
Jul 2008
Location
Brasov
Posts
33
Hello,

I want to copy a string of max. length (ex. from DB2) into the instance DB of the FB (ex.DB10 of FB10).

The string is given to FB10 as an input parameter of type ANY.
In the STAT area of instance DB10 I defined a string of max. length (254 same as length of source string in DB2).

I used BLKMOV (SFC20) and specified data type as byte (B#16#2) when preparing the ANY pointers.
The copy works OK (in VAT I can see that the string was copied into DB10).
In FB10 when I try to get the length (with IEC function FC21 LEN) of the just copied string I get this error (in Diagnostic Buffer):

Event 3 of 100: Event ID 16# 2522
Area length error when reading
Own local data, byte access, Access address: 45
FC number: 21
Module address: 28
What is the problem?

Thanks!
 
Since you're dealing with a String here, are you sure you've allowed enough space in your DB? A String is actually two Bytes longer than the defined String length - the first Byte in the String holds the maximum length a String can be, the second Byte holds the current length.

This wouldn't bother SFC 20, it just drops the last two Bytes, however, FC21 will look at the length data at the start of the String and complain loudly if it can't find the last two Bytes.
 
Post your code (cut down to show the problem) as a zip attachment. (Copy the blocks to a library and archive the library)
 
.... the second Byte holds the current length.......... FC21 will look at the length data at the start of the String and complain loudly if it can't find the last two Bytes.

FC21 reports no errors - it simply returns the value in the second byte of the string. If you contruct an any pointer to the L area at run time and pass it to FC21... that will you give you the Own Local Data Area Length Error. The fix is to modify the created any pointer to point to the V area instead.
 
Guess I phrased that badly, by "loud complaint" I meant the area length error in the diagnostic buffer, whereas, as far as I know, SFC20 doesn't give such an error.
 
Post your code (cut down to show the problem) as a zip attachment. (Copy the blocks to a library and archive the library)

Hello,

Here is the project saved in library & archived.
So when trying to get the length inside FB you'll get an error (see the attachment).

Thanks!

PS: The help for IEC FC21 LEN says:
You can assign only a symbolically defined variable for the input parameter.
 
You cannot use STAT variables whilst AR2 has been modified - you must restore AR2 before the call to FC21, not after.
(You have used AR2 to point to the temp area - this is what is being passed to FC21 and is why you get the error)

Code:
      L     0
      T     #TMP_INT_CPY_STR_LEN
      L     #TMP_DW_SAVE_AR2
      LAR2  
      CALL  FC    21
       S      :=#STAT_STR_CPY
       RET_VAL:=#TMP_INT_CPY_STR_LEN
      L     #TMP_INT_CPY_STR_LEN
      T     #INOUT_INT_STR_LEN
 

Similar Topics

Hello everyone, I have made a sample project with one FC, and one global DB with a few strings. In the global DB all strings are written...
Replies
8
Views
1,917
Hello, I want to do a very basic string initialization: each element of the string to be NULL (hex: 0x0). I noticed that if I use the...
Replies
5
Views
6,810
i am new to simatic manager and i am trying to figure what this part do in the code : A I 5.6 = DB50.DBX 4.6...
Replies
3
Views
129
Hello everyone, can anyone help me with covert the STL code to ladder. Iam using plc s71200. A %DB1.DBX33.7 // angel of vaccum...
Replies
2
Views
207
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
316
Back
Top Bottom