Page 1 of 1

FOR ... DO in SCL TIA Portal

Posted: Mon Jun 29, 2020 11:48 am
by ggg315
What is this instruction in SCL in TIA Portal
Limit is defined as a constant =7
What does this mean FOR #index := #LIMIT TO 1 BY -1 DO especially the part BY -1 DO
Limit to 1 means we start at 7,6,5,4,3,1 and move to 1, but i dont understand what this ( BY -1) mean does it tell it to reduce -1 each time

https://prnt.sc/t8fws2

Code: Select all

(* Part 1 Sorting of data ******************************************************
Swaps adjacent pairs of values using the ”bubble sort”
method until the measured data buffer is correctly sorted. *)
REPEAT
    #swap := FALSE;
    FOR #index := #LIMIT TO 1 BY -1 DO
        IF #sortbuffer[#index -1 ] > #sortbuffer[#index] THEN
            #aux := #sortbuffer[#index];
            #sortbuffer[#index] := #sortbuffer[#index -1 ];
            #sortbuffer[#index -1] := #aux;
            #swap := TRUE;
        END_IF;
    END_FOR;
UNTIL NOT #swap
END_REPEAT;
(* Part 2 Calculation of results ***********************************************
Calculates square root using standard function SQRT and
square using function SQUARE. *)
FOR #index := 0 TO #LIMIT BY 1 DO
    #valr := INT_TO_REAL(#sortbuffer[#index]);
    #resultr := SQRT(#valr);
    #calcbuffer[#index].squareroot := REAL_TO_INT(#resultr);
    #calcbuffer[#index].square := "SQUARE" (#sortbuffer[#index]);
END_FOR;


Re: FOR ... DO in SCL TIA Portal

Posted: Mon Jun 29, 2020 2:21 pm
by Answers to FAQs
Limit to 1 means we start at 7,6,5,4,3,1
it is mean with BY operand only

FOR #index := (start_value) TO (end_value) BY (step) DO
operand FOR not compare between start_value & end_value, and cannot know if increment or decrement the start_value

Re: FOR ... DO in SCL TIA Portal

Posted: Mon Jun 29, 2020 5:56 pm
by ggg315
Thank you so much

Where Can I read in details about instructions of SCL

Update 2 for SCL TIA Portal

Posted: Tue Jun 30, 2020 5:11 am
by Update
(sdown) 2.1 Improvements in Update 2 for TIA Portal https://support.industry.siemens.com/cs ... /109775861
29.06.2020 wrote:Update 2 for TIA Portal contains the following improvements and changes for SCL :
SCL: Derived data types in arithmetic expressions
The rules for derived data types have been standardized. It is now no longer permitted to use these data types in arithmetic expressions in SCL.
Example:
The following expression is no longer permissible in V16 Update 2:
(boom) #myInt := #myHW_IO + 5;

In such cases, use a temporary tag of the basic data type:

Code: Select all

#myTempUInt := #myHW_IO;
#myINt := #myTempUInt + 5;
Alternatively, you can also convert the operand explicitly to the basic data type:

Code: Select all

#myInt := UINT_TO_INT(#myHW_IO) + 5;

Re: FOR ... DO in SCL TIA Portal

Posted: Tue Jun 30, 2020 7:14 am
by ggg315

Code: Select all

FUNCTION_BLOCK TEST
VAR_INPUT
FINALVAL: INT; //Input parameter
END_VAR
VAR_IN_OUT
IQ1: REAL; //In/Out parameter
END_VAR
VAR_OUTPUT
CONTROL: BOOL;//Output parameter
END_VAR
VAR
INDEX: INT;
END_VAR
BEGIN
CONTROL:= FALSE;
FOR INDEX:= 1 TO FINALVAL DO
IQ1:= IQ1 * 2;
IF IQ1 > 10000 THEN
CONTROL:= TRUE;
END_IF;
END_FOR;
END_FUNCTION_BLOCK

In above code the step is not there so how it will know what the step is ?

FOR INDEX:= 1 TO FINALVAL DO

Re: FOR ... DO in SCL TIA Portal

Posted: Tue Jun 30, 2020 4:57 pm
by Answers to FAQs
default parameter BY is = +1