String initialization (Step7, STL)

Supreame

Member
Join Date
Jul 2008
Location
Brasov
Posts
33
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 Initial Value in DBand I put there '' each element of the string will contain '' - the character space (hex: 0x20).

For example I have a string in DB1 defined like this:

Address, Name, Type, Initial value
+0.0, EmptyStr, STRING[30], ''

For initialization I use this commands:

L 0
T DB1.DBB 2
T DB1.DBB 3
...
T DB1.DBB 32


But this mode of string initialization is quite primitive.
I will like something as this C code:

i=2;
do
EmptyStr=0;
i++;
while(i<=32)

What is the STL equivalent for EmptyStr ?
 
In SCL you can write

MyDB.EmptyStr := '' ;

In STL, that translates to

L W#16#xx00
T DBn.DBW 0

Where "xx" is the length of the STRING in hex.
"n" is the DB number.

If you have defined a STRING[20] in DB1 as the 1st variable in the DB then it becomes

L W#16#1400
T DB1.DBW 0

edit: I assume that you interpret the STRING only as STRING. In that case it should be enough to set the length to zero, as I did.
If you somehow look at the individual CHARs in the STRING, then I think you have to clear them all as LD[] does.
 
Last edited:
Here's a zero string example:

string010.JPG



Code for FC2:
Code:
FUNCTION FC 2 : VOID
TITLE =
VERSION : 0.1

VAR_INPUT
  sString : POINTER ; 
END_VAR
VAR_TEMP
  iDB : INT ; 
  iCount : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =clear string
	  L	 P##sString; 
	  LAR1  ; 
	  L	 W [AR1,P#0.0]; 
	  T	 #iDB; 
	  L	 D [AR1,P#2.0]; 
	  LAR1  ; 
	  OPN   DB [#iDB]; 
	  L	 B [AR1,P#0.0]; 
Loop: T	 #iCount; 
	  L	 0; 
	  T	 B [AR1,P#2.0]; 
	  +AR1  P#1.0; 
	  L	 #iCount; 
	  LOOP  Loop; 
END_FUNCTION
 
Thank you so much sir. Your knowledge is very useful for me.

Here's a zero string example:

string010.JPG



Code for FC2:
Code:
FUNCTION FC 2 : VOID
TITLE =
VERSION : 0.1

VAR_INPUT
  sString : POINTER ; 
END_VAR
VAR_TEMP
  iDB : INT ; 
  iCount : INT ; 
END_VAR
BEGIN
NETWORK
TITLE =clear string
	  L	 P##sString; 
	  LAR1  ; 
	  L	 W [AR1,P#0.0]; 
	  T	 #iDB; 
	  L	 D [AR1,P#2.0]; 
	  LAR1  ; 
	  OPN   DB [#iDB]; 
	  L	 B [AR1,P#0.0]; 
Loop: T	 #iCount; 
	  L	 0; 
	  T	 B [AR1,P#2.0]; 
	  +AR1  P#1.0; 
	  L	 #iCount; 
	  LOOP  Loop; 
END_FUNCTION
Very helpful sir. Thanks a lot.
 

Similar Topics

I'm using PanelBuilder32 (version 3.5, build 84) with a PV1000 HMI (2711-K10C9). Does anyone know how to include control characters in the...
Replies
2
Views
2,037
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
84
As the title says, I'm using CCW with a PV800 (and Micro850). I've made a scheduler in which a user can choose a month, day (1-31), hour (0-23)...
Replies
15
Views
454
Hello, So i managed to read the string coming from control logix and put a string display in PanelView 800. Now I am struggling to do the other...
Replies
1
Views
115
Does anyone know why my one string is displaying this way? It is causing issues with my HMI displaying it.
Replies
4
Views
241
Back
Top Bottom