FOR ... DO in SCL TIA Portal

SIMATIC S7-200/300/400, Step7, PCS7, CFC, SFC, PDM, PLCSIM,
SCL, Graph, SPS-VISU S5/S7, IBHsoftec, LOGO ...
ggg315
Posts: 26
Joined: Thu May 28, 2015 6:29 am

FOR ... DO in SCL TIA Portal

Post 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;

Answers to FAQs
Faq & Info
Faq & Info
Posts: 178
Joined: Thu Oct 13, 2005 6:42 pm
Location: Frequently Asked Questions – Часто Задаваемые Вопросы

Re: FOR ... DO in SCL TIA Portal

Post 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
ggg315
Posts: 26
Joined: Thu May 28, 2015 6:29 am

Re: FOR ... DO in SCL TIA Portal

Post by ggg315 »

Thank you so much

Where Can I read in details about instructions of SCL
Update
Forum Community
Forum Community
Posts: 381
Joined: Mon Apr 12, 2010 10:59 am

Update 2 for SCL TIA Portal

Post 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;
ggg315
Posts: 26
Joined: Thu May 28, 2015 6:29 am

Re: FOR ... DO in SCL TIA Portal

Post 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
Answers to FAQs
Faq & Info
Faq & Info
Posts: 178
Joined: Thu Oct 13, 2005 6:42 pm
Location: Frequently Asked Questions – Часто Задаваемые Вопросы

Re: FOR ... DO in SCL TIA Portal

Post by Answers to FAQs »

default parameter BY is = +1