S7-300 SCL program convert string DB to real DB

Is the format of the real values always 3 decimal digits, a period, 2 fraction digits and a comma ?
If that is the case you can 'simply' extract every character one by one.
something like this:

Code:
FUNCTION_BLOCK "FB_SPLITREALSTRING"

VAR
    sourcestr : STRING[72] ; //:= '123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45' ;
    sourcestr_chars AT sourcestr : ARRAY[0..73] OF CHAR ;
    strTable : ARRAY[0..11] OF STRING[7] ;
    strTable_chars AT strTable : ARRAY[0..107] OF CHAR ;
    i : INT ;
END_VAR

LABEL 
    ERROR, NORMALEXIT ;
END_LABEL ;


FOR i:= 0 TO 11 BY 1 DO
  IF NOT (sourcestr_chars[i*7 + 5] = '.') OR NOT (sourcestr_chars[i*7 + 8] = ',') THEN 
    GOTO ERROR ;
  END_IF ;
    strTable_chars[i*9 + 2] := sourcestr_chars[i*7 + 2]; 
    strTable_chars[i*9 + 3] := sourcestr_chars[i*7 + 3]; 
    strTable_chars[i*9 + 4] := sourcestr_chars[i*7 + 4]; 
    strTable_chars[i*9 + 5] := '.';
    strTable_chars[i*9 + 6] := sourcestr_chars[i*7 + 6]; 
    strTable_chars[i*9 + 7] := sourcestr_chars[i*7 + 7]; 
    strTable_chars[i*9 + 8] := ',';
END_FOR ;
GOTO NORMALEXIT ;

ERROR:  ;

NORMALEXIT:    ;
END_FUNCTION_BLOCK
This is just a rough code idea. Not tested !
Not sure if I got the character count right, but you get the idea.
 
Last edited:
Here's an alternative using the inbuilt string handling functions:

Code:
FUNCTION_BLOCK FB67
VAR
    sourcestr : STRING[250] ;
    strTable : ARRAY[1..12] OF STRING[7] ;
    i,iPlace,iLen, P : INT ;
END_VAR
BEGIN
//load data into source string for testing
sourcestr:='100.01,200.02,300.03,400.04,500.05,600.06,700.07,800.08,900.09,1000.10,1100.11,1200.12';// end of loading test data
FOR i:= 1 TO 11 DO
  iPlace:=FIND(IN1:=sourcestr,IN2:=',');
  strTable[i]:=LEFT(IN:=sourcestr, L:=iPlace-1);
  iLen:=LEN(S:=sourcestr);
  sourcestr:=RIGHT(IN:=sourcestr, L:=(iLEN-iPlace));
END_FOR;
strTable[12]:=sourcestr;
END_FUNCTION_BLOCK
 
Hi, can you please show me how to do the coding in STL(S7 300), I used the P_RCV block to receive data from rs232(using a CP341 card) into DB1 string[8]. Now I need to display the value as a real value on the operator screen(HMI). Please help
 

Similar Topics

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,503
How to realize transformation functions : 1/s and 1/(1+s) into SCL inside S7-300
Replies
0
Views
944
Hi. I tryid to make a shiftregister with 31 entry's. the string array are declared in the Static area of the FB. When I run the code its not...
Replies
1
Views
1,280
Looking for some help with an array of strings in SCL. I have an array of 99 string[98] I also have an array of 99 INT My first 4 chars of the...
Replies
9
Views
2,448
I am trying to take several individual CHAR bytes and turn them into a string. The CHAR bytes are located in a DB. I am trying to figure out the...
Replies
4
Views
3,502
Back
Top Bottom