String copy Step7

AlanW

Member
Join Date
Apr 2007
Location
Newcastle
Posts
19
There must be a way to create a 'String Copy' function in Step7, something like:

Call FCx
FromStr:=SourceString
ToStr:=DestString

or am I being stupid?
 
Hello Alan;

Try SFC20, "BLKMOV"; it will accept a string variable as source and destination:
SFC20_String.jpg


Hope this helps,
Daniel Chartier
 
SFC20 - Block move?
      CALL  "BLKMOV"
SRCBLK :=#Source_string
RET_VAL:=#SFC20_Ret_Val
DSTBLK :=#Destin_string



Edit: Daniel beat me to it!
 
I'd seen the BLKMOV but if I'm within a function of mine which is passed a sring, which then gets manipulted by my function, how do I then copy it out to another (or the same) string which is a supplied parameter to my function.

Hope this makes sense.

So my function will have two IN parameter, say:
FromStr and ToStr (what type would they be String, pointer, string[xxx]?)
so within the function I call

CALL "BLKMOV"

SRCBLK :=#FromStr

RET_VAL:=#SFC20_Ret_Val

DSTBLK :=#ToStr
 
I dont think there is a standard funcion in Step7. You have to make your own any-pointers and then use the blkmov (SFC20) to copy the string data.
 
It is not possible to specify FC parameters as the arguments for SFC20.

I would create a temp string variable in the FC and then copy the source string to this temp area using a loop and indirect addressing. Once the processing is completed, copy the result string to the destination using the same method. (NB: strings are actually passed as DB_Pointers to a function DBNO+Area pointer, if DBNO=0 then you don't need to open a DB). See an example below for copying the input string to a temp string.

Code:
FUNCTION FC 1 : VOID
TITLE =
VERSION : 0.1

VAR_INPUT
  InputString : STRING  [254 ]; 
END_VAR
VAR_TEMP
  TempString : STRING  [254 ]; 
  iLoopCount : INT ; 
  iDBNumber : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =
	  L	 P##InputString; 
	  LAR1  ; 
	  L	 W [AR1,P#0.0]; //DB number of input string
	  T	 #iDBNumber; 
	  L	 D [AR1,P#2.0]; //area pointer of input string
	  LAR1  ; 
	  L	 0; 
	  L	 #iDBNumber; //if DB number = 0 then don't open DB
	  ==I   ; 
	  JC	nodb; 
	  OPN   DB [#iDBNumber]; //else open correct DB for Input string
nodb: L	 B [AR1,P#0.0]; //get string max length
	  +AR1  P#1.0; 
	  L	 B [AR1,P#0.0]; //get string actual length
	  +AR1  P#1.0; 
	  LAR2  P##TempString; //point to temp string
	  T	 B [AR2,P#1.0]; //set actual length of temp string
	  TAK   ; 
	  T	 B [AR2,P#0.0]; //set max length of temp string
	  TAK   ; 
	  +AR2  P#2.0; //update ar2 to pint to first char
	  L	 0; //actual length = 0 ?
	  ==I   ; 
	  JC	Exit; //if so then exit
	  TAK   ; 
Lop1: T	 #iLoopCount; 
	  L	 B [AR1,P#0.0]; //copy char from input string..
	  T	 B [AR2,P#0.0]; //..to temp string
	  +AR1  P#1.0; //index to next
	  +AR2  P#1.0; //index to next
	  L	 #iLoopCount; //until all done
	  LOOP  Lop1; 
Exit: NOP   0; 
END_FUNCTION

Edit: added code snippet.
 
Last edited:
Hi Simon,
What would be the correct syntax for the IN variable "Inputstring" when called?

I created a DB (DB1) with a single string 'Test'

dbstr.JPG


i tried p#db1.dbx0.0 byte 254 also symbolically "String Test".test but regardless of combinations the compiler moans and Inputstring stays red regardless.

Thanks Steve
 
"String Test".test is the correct syntax provided of course that "String Test" is in the symbol table against a DB. I've encountered problems in the past when I've tried to enter the code symbolically and created the DB symbol name afterwards - the parameter stays red. I've had to shut down the editor and start again and then everything is happy. Here's the source code from the blocks I've been using.

Code:
DATA_BLOCK "dbStrings"
TITLE =
VERSION : 0.1

  STRUCT  
   MyString : STRING  [254 ]; 
  END_STRUCT ; 
BEGIN
   MyString := 'Peter Piper'; 
END_DATA_BLOCK

........
 
	  CALL FC	 1 (
		   InputString			  := "dbStrings".MyString);
	  NOP   0;
 
Last edited:
Yep - that fixed it - never come across that before! thought i was going mad......

Thanks again
 
L D[AR2 said:
"String Test".test is the correct syntax provided of course that "String Test" is in the symbol table against a DB. I've encountered problems in the past when I've tried to enter the code symbolically and created the DB symbol name afterwards - the parameter stays red.

QUOTE]

Had a similar problem but too many not used symbols .Delete most unused and problem fixed.
 
What you want to do is relatively easy to do with SCL.
I just did a test to see if I could achieve the "parameter" functionality. It was quite easy.
1st I created a UDT "STRING_255" that only contained a STRING[255].
2nd I added a "strings" ARRAY[1..10] of STRING_255 to the "test" DB.
After that in SCL I could program this:
Code:
FUNCTION FC25: INT
VAR_input
 in_index, out_index : INT  ;
END_VAR
	"test".strings[out_index] := "test".strings[in_index] ;
	FC25 := 100;
END_FUNCTION
 
Hi All,

I want to copy strings from DBs to local declared Strings within my FB. Manipulate the data (i.e Use FC 10 String Compare) and then pass them on to another DB (Eg Report DB). THe string lengths will differ.
 

Similar Topics

Hello Inside a FB, I´m trying to transfer a string from a DB to a IN_OUT var that was define as a UDT. The problem is that i can´t determine the...
Replies
4
Views
128
Hi Im trying to use SFC20 BLK Move in a piece of SCL code in Step7. I need to copy/move one string[16] in a DB to another DB place ! If a block...
Replies
5
Views
13,502
I feel like I'm going crazy, new to Siemens, coming from AB, and I cannot get a dang string copied in SCL. This is a S7-300, V16 PLC. I have a...
Replies
10
Views
3,476
HI Guys So i am trying to write a real SINt or DINT value into a string tag. If in string browser I write it manually, no problem. But how can I...
Replies
8
Views
5,952
I am using v14 with a 1215 dc/dc/dc. I need to copy a 50 element array of strings to another 50 element array of strings. I can work it out for...
Replies
3
Views
4,042
Back
Top Bottom