TIA Portal: "IF" "THEN" "ELSE" "ELSIF" Statement in SCL

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello hi and welcome to today's video in which we are going to look SCL structured control lists or structured control language however you want to call it and we're going to start with a sequence of videos actually that in which we are going to create like a shelf system storage system mainly using SCL language because SCL language is a very specific language that should be used to create special functions you don't program the whole PLC program in sel you just do it for specific functions so today we are starting with the simple if statement that you basically have in every language so let's jump into it therefore I will create a new function block here this function yeah there's a function block this function block I mean does need to mean your function but could be a function as well but I am already preparing for the next video so in my case it's a function block just for today we wouldn't need a function which just just need a function but there we go so I will call it storage system and this is of course in SC L I have already prepared for my storage system some kind of storage here where I have one boolean value that tells me hey something put something into the storage boolean value takes something out of the storage then we have to select a shelf and we have here you see shelves 0 to 100 so we have in total 101 shelves maybe let's make that just 0 to 99 so we have 100 shelves in total right we have 100 shelves in total 0 to 99 and they're all empty you see false false false false holds the meaning is all empty if put in is active we are going to change the value of one of those shelves today and that shelf is the selected shelf so let's create our storage system first here I want to have this as an input those two variables there select the shelf which is an integer and put in which is a boolean value right those are just my structure elements that I want and of course also my storage my shelves and those are array of boolean because something is in there and something it's not only of course we could do anything else any data type 0 to 99 and here we go so those are my inputs to my function that I'm going to create alright so if I call my function block here my storage system I have those as inputs and I will just link them up to my to my data block that I have created in before so that's just the input declaration so to say so we have the selected shelve I have the put in command and I have my shelves which I'm going to put in here alright so this this is just data blocks I had this is just function blocks this is just the proration here so you saw everything that I did if you don't know why I did that just check out my video on function blocks yeah we just want to dive in actually here and we're using those as an input so the if statement it's actually pretty simple can i zoom in and I see I can zoom in I didn't know so the if statement is actually pretty simple right you have it here on top if you're in the stl editor you have on top a couple of commands let's just take the if statement and the if statement is pretty pretty simple if a condition is met meaning what is our condition of course the put in command I can't just take this put in now and just drag and drop it over here alright if put in is anything else then 0 so in our case if it's true then do whatever is in between here so what do we want to do of course we want to put something in the shelf right and now I realize the Shelf is actually not an input it is actually an in/out my bad here we go because we are reading values and we are also writing values of course change the story this is just yeah yeah so if put in is active then do this what do we want to do in here of course we want to put something the shelf so I go here take the shelf right just drag and drop take the shelf go there and as we are using arrays of course I would have to say which array element am I going to talk about and there I'd make those records those I don't know how they are called in English those write it in the comments all those are called the H ones the edgy the edgy braces I don't know exactly yeah and then of course I want to do that in the selected shelf you see I can just drop that here selected shelf there done my closing brackets are gone closing brackets and of course I want to say hey this is now true so that's from the last video if you saw it on the SCL series a double point and an equal sign this was an assignment in SCL and i want to put something in the shell then so let's see let's download all right let's download this whole thing and let's see if that works as intended so let's go to the main let's observe so right now my selected shelf is 0 and my puddin is also 0 so let's get to the data block that is serving as my inputs here let's say selected shelf and we can see all the shelves there false false false false false false all those so let's select a shelf maybe shelf number 5 so shelf number 5 is the one with the array element 5 right that says 5 in there and as soon as I say put in we're going to write the true in there but let's look at that in here and in here we have no I need to zoom out because that's here on the side so right now the result you see results result is basically the status in here we could also put a an equation in here with an end and an or but we're not going to do that right now we're just focusing on the statement itself so if put in is true we are going to execute that command so let's turn put and true put in is going to be true you can see that because it's off-screen here I will turn to true or to one but you see that the command now here it is true meaning all of this is being executed so we should have now in storage number five this true value pretty good so that's true we have it so if I now turn this false again what's going to happen I turn it false this is false if put in this put in is false then do this so this is not going to happen anymore so what's going to happen this is not happening but we're not automatically resetting right so it should stay the same the value should stay the same so I turn it to false you see here there's still a true in there this is not false we are just not executing this line of code so what's going to happen of course nothing all right so what's going to happen if put in no put it was false so we basically just jumping right to the end if so that's it all right that's it we're just jumping outside now we're not executing what's in here and that's the if statement very simple very easy and but of course there's more we have this put in command I of course also want to have a take out command so what do I do I put this tag out here in my list take out and so as an input to my to my block I will of course update my block here and make this an input all right so now we can also take out what does that mean when am I going to take out I could now have a second if statement so I could just copy this copy control C control V or right click copy and paste right I could take instead of this put in I can take the take out I just drag and drop wait a second and then you see the editor automatically turns this or selects the whole thing I could do this if I take out then do this alright so let's see if that works and I can already tell you yes it's going to work so let's see so shelf selected is still 5 it's true if I activate takeout it is now false because now this if statement here is active meaning this is executed there we go now we have just one just one issue we have one issue here that is if both of them are active which should of course not happen if both of them are active that is kind of stupid right now because this is coming here last so this is the stronger one right so whatever we put in the end is the stronger one of course there's always got to be a strong one but we should actually write a logic that tells us hey there's an error so not going to do that there should be an error command something if well I can't do it let's do this let's have an output that says just simple error all right it's a boolean so what can we do if what can I say if both inputs are active at the same time so put in right if put in is active oops let's make this this is easy I always do this and then it's that's way easier if put in is active and we need to have an end somehow usually in programming languages you write this stuff or this in SEL you just write an end and you see this is already keyword here we go if put in as active and take out as active right if this is active and this effective then do the statement here what do we want to do we want to know hey there's an error so what do I do error is true all right so that's a short thing so that we can catch if both are active we'll have an arrow telling us hey there's something wrong you can't take out something and put in something at the same time so let's see if I go online whoops I make changes in the call environment so I have to reopen it so if both are active at the same time that's what's going to happen now we still have both active and we still have both active both are true then we will have an error so let's see if I go online here so this is true meaning this is being executed which is still a problem this is true so this is also executed and this is true and this is true the result of both is true so we will have an error so our error is true we currently have an error what can we do to actually make this a little bit better so on top here right on top here we of course need to change some things and we would need to change some things so that it can't happen both at the same time so what could we do if put in as active and go actually put an end and can I make this sorry I oh this is not and III program in too many programming ages these days so if put in is active and take out is active I don't want this can I just no I can't do stupid program now I have to say if put in is active and take out is not active meaning is false yeah then we do this meaning only put in can is allowed to be active that's the same here and of course put in is not active right same line so this is only executed if put in if only put in this active this is only executed if only take out as active this is activated when both are active so let's see let's download and see you don't have to write an equal sign true here because it's asking for one this is automatically a one here I just want to see the result of this is going to be a 1 so if this is false all of this is going to be a 1 if this is the one it's already a 1 so let's see both are still active so you see the results of these two is false right because this is active and this is currently not false so the result here is true so it's 1 & 0 that's of course not true so if i deactivate take out for example let's see take out I modify it and I put it to a 0 right now we have an error if I put this now to a 0 the take out we do not have the error anymore we have only the put in as active so we only execute right now this so that works and that is pretty cool that is pretty cool now we have improved already a lot where in 50 minutes I just want to show you one more thing here which is the following now we can improve this because SCL is a lot about timing a lot about optimizing your code and that is not optimized here I have basically I'm basically asking for the same thing 3 times here so what I can do is I can make this this year and I can make an else statement an else statement says hey if this stuff here is 1 we're doing this if this stuff here is 0 we are doing this all right that would be the else statement but what we actually want is if this is not true then we want to do this which would be an else if and we can't write else if right else if and then we have to take all that code here which is basically a second statement elsif to all of this now do all of this and this of course can just go away directly and we only have one end if and there we go all right so if this is true we're doing this if this is false we are also asking now is this true and we're doing this so instead of always asking twice we are only asking twice if this is now wrong right if this is now wrong we're only asking twice we can take that of course a step further and we can now again go with an else--if right now we can go again with an else--if and of course now I take my error code here so now this is much optimized so instead of always asking for all three conditions we are only asking is this true if yes do this don't even look at all that if this is false don't look at this look at this if this is true do this if this is false look at this if this is the case do this all right so we are cascading our if statements a little bit so this might be a little bit complicated now that's how it is so let's see let's see with an example so right now you can always see what we are asking for and before everything was true or false here that's not how we want it we want optimized code so right now this is true this is true right this is true so we're only doing this you can see that here up top now if I make this put in also false we are not even looking at this part so I will make this now false you can see that it's off-screen now it's false so we're looking at this this is false so please look at this all right so this is also false so please look at this this is also false so please end all of this that's all we're doing it we've cascaded it so now let's only turn this one on what's going to happen we're jumping into the first step into the first statement there we got it if I turn this off again and if I turn the take on the tag out on so we are now not to do we are asking for this it's not true we're not doing this we're asking for this this is true so we are doing this now the end so this is already true so we're jumping out of it and we're not even asking for this so if I now turn both on what's going to happen we have the third case so this is false so jump over this this is false jump over this this is true do this right so we can cascade our if statements here a little bit complicated but once you get used to it's actually pretty simple so now I have nice little storage system with even an error output in case we have an error all right good that was a little bit longer than I thought a little bit more complicated just the if statement and of course there is more to it but that's the basic that's that's okay just so we have it finished here you can of course also put or statements in here all right yeah just so you know but for in our case of course we want the end statement and you can also cascade those I can put another end and I can put in or in here if you want to of course this oil is with boolean logic so you have to put braces if you want to prioritize multiply stuff like this if you are not aware of those I will make a video on digital fundamentals to this so sorry if this was a little bit too long if this is a little bit too complicated just write a comment let me know in the comments below I will continue next time with the loops I air we have two different types of loops we have a for loop and a while loop I'll continue with loops the next video so 20 minutes way too long if you have questions put them below I'll try to get to them if this is any helpful leave a like do not forget to subscribe and I wish you a nice day and I'll see you in the next episode bye bye
Info
Channel: Hegamurl
Views: 33,823
Rating: undefined out of 5
Keywords: tia, tia portal, plc, siemens, plcsim, advanced, v15, v15.1, v14, clock, controller, simatic, 1500, s7, hmi, tp700, tp900, tp, easy, learning, intro, beginner, help, training, navigation, change, quick, fast, english, german, 1200, s7-1200, s7-1500, rezept, rezepte, data, user, login, logoff, users, wincc, basic, runtime, simulation, example, screen, copy, paste, new, key, admin, trace, v16, force, test, difference, watch table, reset, protection, password, project, safety, scl, structured control list, structured control language, if, then, else, elsif
Id: kc4BmLucoXw
Channel Id: undefined
Length: 19min 25sec (1165 seconds)
Published: Thu Feb 20 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.