How to change Constant with address in CASE loop TIA Portal 15.1

Sergihno

Member
Join Date
Oct 2016
Location
Ukraine
Posts
70
Hello everyone,

Who knows how to implement constants in CASE loop via address to do it flexible. I show it on screenshot. Thanks a lot.
Cv8SF8M


picture1.PNG
 
I don't think you can, the only way is to use if, else. endif statements not pretty but will work.
IF #MyTag== #CompTag THEN
.....Do something
ELSE IF #MyTag == #CompTag THEN
.....Do something
ELSE IF #MyTag == #CompTag THEN
......Do something
ELSE
........Do something
END_IF;
 
No, not with a case statement. Why don't you describe the actual processing you want to achieve - then we can suggest how to implement it.
 
Here's an example implementation that allows you to use variables to control the case statement selections. I created an array of cases each containing an array of selections. You fill in the selections you want for each case - see my example code. The selections are set to -1 for an unused selection.



Code:
FOR #i := 0 TO 15 DO
    FOR #j := 0 TO 15 DO
        "dbVariableCases".VariableCases.Cases[#i].RangeSelection[#j] := -1;
    END_FOR;
END_FOR;

//testing code
IF false THEN
    //set up case statement selections example 1
    //case Index of
    //  0,1,2: "Tag_7":= "but1_1";
    //  3,4,5: "Tag_7":= "but1_2";
    //  6:     "Tag_7":= "but1_3";
    "dbVariableCases".VariableCases.Cases[0].RangeSelection[0] := 0;
    "dbVariableCases".VariableCases.Cases[0].RangeSelection[1] := 1;
    "dbVariableCases".VariableCases.Cases[0].RangeSelection[2] := 2;
    
    "dbVariableCases".VariableCases.Cases[1].RangeSelection[0] := 3;
    "dbVariableCases".VariableCases.Cases[1].RangeSelection[1] := 4;
    "dbVariableCases".VariableCases.Cases[1].RangeSelection[2] := 5;
    
    "dbVariableCases".VariableCases.Cases[2].RangeSelection[0] := 6;
END_IF;

IF true THEN
//set up case statement selections example 2
//case Index of
//  0,1,2,3,4,5,6,7,8,9: "Tag_7":= "but1_1";
//  10,11,12:            "Tag_7":= "but1_2";
//  13,14,15:            "Tag_7":= "but1_3";
//  
"dbVariableCases".VariableCases.Cases[0].RangeSelection[0] := 0;
"dbVariableCases".VariableCases.Cases[0].RangeSelection[1] := 1;
"dbVariableCases".VariableCases.Cases[0].RangeSelection[2] := 2;
"dbVariableCases".VariableCases.Cases[0].RangeSelection[3] := 3;
"dbVariableCases".VariableCases.Cases[0].RangeSelection[4] := 4;
"dbVariableCases".VariableCases.Cases[0].RangeSelection[5] := 5;
"dbVariableCases".VariableCases.Cases[0].RangeSelection[6] := 6;
"dbVariableCases".VariableCases.Cases[0].RangeSelection[7] := 7;
"dbVariableCases".VariableCases.Cases[0].RangeSelection[8] := 8;
"dbVariableCases".VariableCases.Cases[0].RangeSelection[9] := 9;


"dbVariableCases".VariableCases.Cases[1].RangeSelection[0] := 10;
"dbVariableCases".VariableCases.Cases[1].RangeSelection[1] := 11;
"dbVariableCases".VariableCases.Cases[1].RangeSelection[2] := 12;

"dbVariableCases".VariableCases.Cases[2].RangeSelection[0] := 13;
"dbVariableCases".VariableCases.Cases[2].RangeSelection[1] := 14;
"dbVariableCases".VariableCases.Cases[2].RangeSelection[2] := 15;
END_IF;

//variable case selection
FOR #i := 0 TO 15 DO
    FOR #j := 0 TO 15 DO
        IF "dbVariableCases".VariableCases.Cases[#i].RangeSelection[#j] <> -1 THEN
            #Caseindex := #i;
            CASE #Caseindex OF
                0:
                    "Tag_7" := "but1_1";
                1:
                    "Tag_7" := "but1_2";
                2:
                    "Tag_7" := "but1_3";
                    /// etc etc    
            END_CASE;
        END_IF;
    END_FOR;
END_FOR;
 
No, not with a case statement. Why don't you describe the actual processing you want to achieve - then we can suggest how to implement it.

I have to realize controlled lets say counter. We implement in 24 hours as 1 day exchange in sec, for example 1h = 3 [sec] , or it can be X [sec]. So I implemented in touch panel each hour as bit changing button, toggle button and according to where it is on , I activate output, it should be the same output during 24 hour sequence. I will below the buttons as control for counter which activate output:

So , I want to do that time of 3 sec = 1 hour flexible and put from touch panel.

pict_seq.PNG
 
Last edited:
Can you try to rephrase, I have difficulties in understanding what is it you try to accomplish here.

Anyway, CASE is not meant to be used so that the choice would be flexible, I think "SWITCH" that is used in some other programming languages to do the same is more clear on what is it supposed to do.

Anyway. CASE has an input variable than can change the "case" to be executed, not make those cases variable.
 
My interpretation as follows:


You have 24 1 hour time slots.
You can select each slot to be active or not.

For an active slot, you can chose how long Q4.1 comes on for.
 
My interpretation as follows:


You have 24 1 hour time slots.
You can select each slot to be active or not.

For an active slot, you can chose how long Q4.1 comes on for.

Yes, I have 1 day = 24 hours, we say 1hour = 1 sec in our intervals. Intervals should be changeable. So If I want my output worked for first 3 hours I push those toggle buttons, so I have bits from them. The task is to do that time - 3 sec flexible to change, for example to change from HMI, so it should be some register to choose. With case it is impossible. I wrote the code it is now , it is with case and time of course fixed.
 
Last edited:
Can you try to rephrase, I have difficulties in understanding what is it you try to accomplish here.

Anyway, CASE is not meant to be used so that the choice would be flexible, I think "SWITCH" that is used in some other programming languages to do the same is more clear on what is it supposed to do.

Anyway. CASE has an input variable than can change the "case" to be executed, not make those cases variable.

I use SIEMENS S1500, so I have chose , STL, SCL, FBD and LAD, thats all.
 

Similar Topics

We had one go down. we have a new one. Their emergency Number don't work. The Model is TLSA046AAH-330N01-007 A catalog says we need software TET...
Replies
2
Views
136
“The HMI files we cannot open—they were saved in V13—we do not have that—I cannot restore file –please have them save in V11 and send them back to...
Replies
4
Views
135
Hi guys! I'm working in Studio 5000 and have a bunch of armorstarts there (+- 40). I need to set up parameters for each of them, mostly just same...
Replies
0
Views
75
Hello brothers We are contacting you because an error like [display change is currently controlled remotely] occurred while using the equipment we...
Replies
2
Views
173
Hi all. I'm trying to set up communication between a 1756-L72 (EN2TR) and a 1756-L82 (CPU port) using produced / consumed tags. From the L72...
Replies
13
Views
343
Back
Top Bottom