Tip:
Highlight text to annotate it
X
>>KURT: All Right, this video covers the, uh,
WAGO IO Pro programming guide for creating a function block.
and it creates a programming example of a lamp function block
[pause]
Go ahead and get started here. Click on File, New.
And we are going to be programming a 750-841.
Go to the visualizations tab and enable web visualizations in this example.
And I want my program plc prg to be a ladder.
And then I am going to add my function block.
Right click on the POU area and click 'add an object', and
its a function block, structured text.
I am going to call this Lamp underscore FB.
And this function block has an integer input, I am going to call that lamp status.
And it has an output that is a boolean, and I'm going to call that Lamp.
And a Timer On Delay which is going to be called lamp flasher.
We're going to set up our lamp flasher here.
[pause]
and if you recall, uh. you can use the input assistant for this [F2]
its a little bit more user friendly. In this example I'm going to demonstrate how quickly
you can just type things in.
um.
[pause for typing]
And
[pause for typing]
this is a case statement, depending on the value of this integer that were passing,
here, ah, we're going to execute some code.
so in the case that lamp status is a zero, we are going to set lamp to false.
if its a one,
[pause]
set lamp status to true.
and if its a two, we're going to make it flash.
And the way we are going to do this, we are going to utilize our lamp flasher, uh, elapsed
[pause]
So, when this is, lamp flasher is, ah, counting, its going to count all the way to two seconds.
at which point, if you recall, the Q wil go true, which will disable the lamp flasher.
And, at which point it will start counting again, so this is just going to keep counting
to two and then start over again.
And that that value that is actually counting is the elapsed time, um, we are going to use
in this, in this evaluation,
so, when its, half the time it will be counting it will be less than one, which would be a
true statement here,
and the other half the time it will be more than one, which will be a false statement.
So, that will basically force the lamp to blink.
And we can also have an else statement with our case. So if the lamp status is not a one
or a zero, or a two, we're going to set the lamp to false.
And we just want to end our case here.
So that's a real simple function block here.
[pause]
Go ahead and familiarize yourself with what this is doing here.
And now we want to setup some variables in our main program, so if I go to PLC PRG, and
I want to create status, and I want to define an instance of our function block.
[pause]
and I'm going to go to resources tab, and
right click on k-bus,
[click on append sub element]
we're going to pick our cards.
I've got a 402 which is a digital input, a 504 which is a digital output.
and this will vary depending on, uh, the cards you have on your particular node.
This happens to be a demonstration for the [WAGO] demo node.
and I want to assign variable names for my first two digital outputs, and I want to call
that My Lamp and My Lamp one. My Lamp 2 is actually more clear.
All right, I'm going to go back to our PLC PRG and I'm going to insert, a box with enable.
I'm going to change that to Lamp underscore FB. And you can see that it recognized that
this is a function, and the lamp status is input and the lamp boolean is our output.
Now, i'm going to define this to the Lamp one that we declared at the top here.
And our lamp status tied to that integer, and the output I'm going to tie to my lamp.
all right, so at this point, we are ready to do our visualization.
Click on the visualizations tab and make a new one, I'm going to call this plc visu.
And, all right, we're going to create an object here, click on the square,
double click on the square and I'm going to type in lamp one.
And I'm going to put that at the top. Of the box.
And I'm going to put the circle. Put a circle here.
double click on the circle, and if you go to colors,
I'll make the inside a dark green,
and the alarm color a light colored green.
then go to variables, and I can change the color based on a variable,
and you can use the input assistant here, or you can call it the name of the, uh, variable,
you can use that too.
Global variables, uh, start with a period. And if its a program, you would just type
in the program name and a period.
So, tie that to my lamp.
And then I'm going to edit, enter an input box below.
Go to the text and type in status here. And, I'm going to use the percent S, uh, identifier.
This is a, basically, the software sees this percent s and allows you to display a variable
using the text display field.
So, if I type in plc prg, which is the name of our pou, uh, its gonna, as soon as I hit
period, it'll show me which variables are available there.
I'm going to tie that to status.
And, I'm going to allow an input here. Uh, restrict the input to a zero to two which
are the values that will make the light blink.
[clears throat]
And, at this point, we should be ready to compile our program.
I'm going to click on project and build.
And you can see that we have zero errors and zero warnings, so this is good.
Click online, go to simulation mode.
And we're going to log in.
Notice, we are not running, so we need to run the processor. You can do that with an
F5 on the keyboard also.
and you can see here when the status is zero, our lamp is off
which is the expected result.
If you recall, when its a zero its false, when its a one its true, and when its a two
its gonna flash with a two second duty cycle.
I'm going to go ahead and click on the zero, and make that a one and press enter.
And you can see the light turned on.
I'm going to make that a two, and you can see we're blinking here.
So, our program is working.
And, I'm going to quickly stop the processor and log out.
I just want to show you real quickly how easy it is to leverage, uh, these function blocks.
So, we already have, uh, uh. a function block that will control a lamp.
I'm going to go ahead and create another uh, rung in our ladder diagram.
And, I'm going to declare another instance of our function block. And,
Going to insert another block with enable,
[pause]
I'm going to tie this to Lamp two, I've just defined here.
Tie that to status, and were going to use the, uh, My Lamp two, which is the second
output on our digital output card. Uh, that we declared here.
So now you can see that we've, re-used our code here and we've uh, doubled the functionality
our program.
And. Im just gonna and paste another function block here,
And, I'm gonna tie this to my lamp two, and we're going to go online with that.
and run it.
All right, now were going to download this plc and access it through a web browser.
So, I'm going to take it out of simulation mode, and I've already set up the communication
I'm just going to log in here.
and I want to make sure we run the processor.
and then I'm just going to go to a web browser, and navigate to the ip address to our plc.
Go to web visu.
And, here you can see its deployed the visualization though a standard, uh, java web browser.