You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old June 29th, 2020, 07:47 AM   #1
Sergihno
Member
Ukraine

Sergihno is offline
 
Join Date: Oct 2016
Location: Ukraine
Posts: 69
Book How to change Constant with address in CASE loop TIA Portal 15.1

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.
Attached Images
File Type: png picture1.PNG (29.4 KB, 120 views)
  Reply With Quote
Old June 29th, 2020, 08:01 AM   #2
parky
Member
United Kingdom

parky is online now
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 2,099
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;
  Reply With Quote
Old June 29th, 2020, 08:18 AM   #3
CommissioningMan
Member
Denmark

CommissioningMan is offline
 
Join Date: Sep 2017
Location: Denmark
Posts: 130
Something like this?:

CaseConstant.png
__________________
All things Siemens and Beckhoff. Please let it be Beckhoff.
  Reply With Quote
Old June 29th, 2020, 05:27 PM   #4
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,915
Copy your but1_x vars to an array and then your posted code reduces to one line of SCL:
Attached Images
File Type: jpg but1.jpg (13.6 KB, 114 views)
__________________
S7-300 to 1500 conversions done - email to s7conversions@hotmail.com
  Reply With Quote
Old June 30th, 2020, 01:17 PM   #5
Sergihno
Member
Ukraine

Sergihno is offline
 
Join Date: Oct 2016
Location: Ukraine
Posts: 69
Quote:
Originally Posted by CommissioningMan View Post
Something like this?:

Attachment 54883
thanks a lot.
Is it possible to rewrite those STEPs from outside, from program?
  Reply With Quote
Old June 30th, 2020, 03:17 PM   #6
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,915
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.
__________________
S7-300 to 1500 conversions done - email to s7conversions@hotmail.com
  Reply With Quote
Old June 30th, 2020, 05:02 PM   #7
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,915
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;
__________________
S7-300 to 1500 conversions done - email to s7conversions@hotmail.com
  Reply With Quote
Old June 30th, 2020, 07:15 PM   #8
Sergihno
Member
Ukraine

Sergihno is offline
 
Join Date: Oct 2016
Location: Ukraine
Posts: 69
Quote:
Originally Posted by L D[AR2,P#0.0] View Post
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.
Attached Images
File Type: png pict_seq.PNG (119.5 KB, 102 views)

Last edited by Sergihno; June 30th, 2020 at 07:17 PM.
  Reply With Quote
Old July 1st, 2020, 02:13 AM   #9
TurpoUrpo
Lifetime Supporting Member
Finland

TurpoUrpo is offline
 
Join Date: May 2008
Location: Switzerland
Posts: 1,483
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.
  Reply With Quote
Old July 1st, 2020, 03:00 AM   #10
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,915
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.
__________________
S7-300 to 1500 conversions done - email to s7conversions@hotmail.com
  Reply With Quote
Old July 1st, 2020, 02:59 PM   #11
Sergihno
Member
Ukraine

Sergihno is offline
 
Join Date: Oct 2016
Location: Ukraine
Posts: 69
Quote:
Originally Posted by L D[AR2,P#0.0] View Post
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 by Sergihno; July 1st, 2020 at 03:02 PM.
  Reply With Quote
Old July 1st, 2020, 03:00 PM   #12
Sergihno
Member
Ukraine

Sergihno is offline
 
Join Date: Oct 2016
Location: Ukraine
Posts: 69
Quote:
Originally Posted by TurpoUrpo View Post
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.
  Reply With Quote
Old July 1st, 2020, 04:27 PM   #13
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,915
Example implementation:
Attached Images
File Type: jpg hour.jpg (171.1 KB, 87 views)
__________________
S7-300 to 1500 conversions done - email to s7conversions@hotmail.com
  Reply With Quote
Old July 1st, 2020, 05:26 PM   #14
chelton
Member
Australia

chelton is offline
 
Join Date: Jan 2012
Location: melbourne
Posts: 113
I haven't worked with s7 but
Wouldn't #HourNow be "0" between midnight and 1am?
  Reply With Quote
Old July 1st, 2020, 06:00 PM   #15
L D[AR2,P#0.0]
Lifetime Supporting Member
United Kingdom

L D[AR2,P#0.0] is offline
 
Join Date: Nov 2006
Location: UK
Posts: 5,915
Yes, good spot. Redeclare the arrays to be [0..23].
__________________
S7-300 to 1500 conversions done - email to s7conversions@hotmail.com
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
TIA Portal 15.1 Issues Lary LIVE PLC Questions And Answers 37 June 11th, 2020 12:11 PM
Issue Changing IP on TP700 (WinCC / TIA Portal v14) kdcui LIVE PLC Questions And Answers 8 October 8th, 2019 02:28 PM
Simatic S7 Classic or TIA Portal Abigail LIVE PLC Questions And Answers 11 April 9th, 2017 05:13 AM
Siemens OP77B Trouble in TIA Portal Tim James LIVE PLC Questions And Answers 4 December 24th, 2012 03:27 PM
DL-06 question..... David_Emmerich LIVE PLC Questions And Answers 4 September 11th, 2007 10:29 AM


All times are GMT -4. The time now is 12:17 PM.


.