FUNCTION_BLOCK FB1331
VAR_INPUT
strINPUT : STRING; //read input string from I/O in Format: 123.45,123.67,123.89...
_str AT strINPUT: STRUCT //local variable to ref struct.
length: BYTE;
act_length: BYTE;
str: ARRAY [1..254] OF BYTE;
END_STRUCT;
END_VAR
VAR
tempTable: ARRAY [1..20] OF STRING; //Array to hold string values
tempString : STRING; //temporary value to store here
i : INT; //Position in the tempTable array
j : INT; //Number of real values
stop : INT; //ACTUAL length of input String
X: BYTE; //Current BYTE
END_VAR
VAR_OUTPUT
//OUTPUT OF REAL VALUES
OUTPUT : ARRAY [1..20] OF REAL; //Output of REAL values
END_VAR
BEGIN
///////////TODO/////////////////////////////////
//1 Iterate through string and find 0-9 and '.'
//2 Iterat through string and find ',' indicating new value
////////////////////////////////////////////////
//1 Iterate through string and find 0-9 and '.'
stop := BYTE_TO_INT(_str.act_length); //Find actual length of string;
FOR i := 1 TO stop DO;
X := _str.str[i]; //Catch current Byte to search in
IF ((BYTE_TO_INT(X) > 47 AND BYTE_TO_INT(X) < 58) OR BYTE_TO_INT(X) = 16#2E) THEN//46 = period (16#2E)
//Build temporary string out of findings
tempString := CONCAT (IN1:= tempString, IN2 := BYTE_TO_CHAR (_str.str[i]));
//2 Iterat through STRING AND FIND ',' indicating new value. Write to array and increment j
IF BYTE_TO_INT(X)=16#2C THEN //44 = comma (16#2C)
j:=j+1; //Increment number of comma
//Move tempString into temporary array
tempTable[j] := tempString;
//Clear tempString
tempString:='';
//Reset array position if End of String
IF i=stop THEN
j:=0;
END_IF;
END_IF;
END_IF;
END_FOR;
END_FUNCTION_BLOCK