APP S7 PLC C# Siemens PLC Communication Driver

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
if you're watching this video it's because you want to learn more about how to use c sharp with siemens plc such as the s7 1500 the s7 300 the 1200 uh and plc's uh in that in that range so what i want to do here is i show an example hmi and the application that the hmi is written in will be in in visual studio and what i'm going to do is i'm going to write some bits and some other data types uh to an s7 300 and a 1500 and then i'm going to open up the the actual application in the in the plc uh true both schematic manager and tia and fully explain everything there's a number of people who tried to cover uh the you know that the driver such as a s7 edge sharp seven i you know live no dave et cetera but generally the the explanations can kind of fall short so what i want to do is clear up a lot of confusion and practically show how to actually have a visual studio application and how you can put together this free hmi uh with the with the free driver and effectively get it sending and receiving a lot of data so let's get to it so to start uh what i'm going to do is just go over the hardware and i'll give a demo first um of a kind of a working system and then i'll go over both taa and somatic manager and then i'll get right into the code in in visual studio you know where you go off and you get the library uh you know et cetera and i'll build a test project from the very start but it's just it's good to go over just an example at the beginning so what i have here is a uh is a panel which effectively hasn't gone in place it just has a number of different relays and it has a digital i o and an analog i o as well this is an s7 uh 300 uh that that you can see and i basically um it has an ethernet card as well which will highlight a little bit more in in detail so these easier cards are again they're vital for the uh for the application to work so if i just go over just as a as an example at the very beginning here's a taa project where i basically have the same hardware set up and i'm going to open up some tables and so on so i first off i'll just bring in it this is a hmi uh where i basically i'll just be able to turn on some some io i'll keep that screen open actually just so we can see i all been triggered on and off so if i just click here you'll see i all begin to go on and off i just as an example uh you know so there's bits being written there and you can see that the the plc is turning on and off and actually if i just open up the uh the cabinet so i'll just open that up there i what there's also is inside is there's actually a a digital input up here just being read from a proximity switch so i basically if i want to get say this is a pt 100 as well for an analog if i just in in the case of this example just give it a click i can see it's 21 degrees and then if i just if i just hold on to it so i'll just hold on to that now and then just we'll see that the temperature is going to gradually go up because i'm actually holding it in my in my hand so it's just going up and up and up and up just because they the the temperature again all right so then we have the the digital guy so if i just want to read them just at the moment he's true and then if you just i'm just gonna it's a digital proximity sensor so you'll see that there's a light that went down at the back it's actually not very good because my hand you'll see that this light up here goes on and off and just the way this commissioning screen is just set up it's just set for uh just it's a manual it's a it's a manual selection rather than being based on a kind of cyclical input so most people are going to want to get to this point here and we're going to want to be able to create a hmi using the library and with a with a you know a system practically in the field like that i so again just to cover it just a second time you need to have an ethernet card or you need to have a cpu that actually has an either card such as this is say for example this is a 1500 and in the fifteen hundred you're going to see that there's uh effectively two ports there so you can have two different rj45 connectors going and read directly from the the cpu if you don't have that uh then the you won't be able to um use the library um in the in the same way okay so i what i'll do now is i'll i'll i'm gonna go and i'm gonna create um the the demo project and show you exactly where to download it the scope of the demo project that i'm going to put together it's just going to be for right now anyway for the end of this video is just writing a bit and then reading a bit and um i have a a plc which was um set up using simatic manager um on a pc with xp service pack 3 and i'll just give you a quick look at that now it's basically a a fairly old system and i wanted you to show this right now just as contrast because um the next video do we'll probably use um windows 10 with uh tiaa and an s7 1500 so i just kind of want to show the flexibility i am of the of the library and basically what i'm going to do is using the library i'm going to set some of these bits here and true and false and we can take a look at a variable table and while it's uh while it's live okay so um the first thing to do is to go off and actually download the library and there'll be a link in the description below so you'll be brought to this uh this web page and if you just scroll down just at the very beginning you'll see that there's a dll there for download so just click the dll just in this case because i'm using chrome um it's basically saying look dlls or executables etc they could be dangerous to only don't know what you trust so i obviously trust this and there's you know yeah i'll just literally just click on this and then just go keep and this is effectively just going to go into the the downloads area so i'm using visual studio 2019 and i'm going to open it up and i'm going to create just a a new project just from the very beginning so i just go create new project and then it's going to be a windows forms application i'll just give it a name um i'll just call it demo one okay so this project now is is created and it's just there's the windows form so the first step for me is that i'm going to have to just reach out and put in the library that i that i just downloaded so i just right click add reference then i just browse after the area that has me dll this is where i downloaded it okay so just give it a click there just go okay so that's basically in there now so um what i'm going to bring over just as a test is just a button and this button is going to be used to actually write a bit value to the plc and then we can look at the plc live through there through the variable table okay so i'll just double click this button here and we're brought into the code okay so first things first we're going to have to put um a reference then uh to the actual the the app 7 um library so there we have it there and just so it'll all make sense as we as we put references to below okay so um in terms of i i'll explain i'll explain things as i go so first off what the way this library works is that we become a kind of a client to the to the plc and just one connection at a time so i we're we're kind of we're requesting and then the the plc gives us back information if we if we ask it okay so it's the best way to look at it so there's effectively like a kind of a client variable and which has to be um put in at the very beginning okay so the the next thing i want you to do when there's a little bit of code here if you can just copy this like for like it's exactly the right thing to do it's a method called a rise bit method and i'll explain in a little bit of detail i want to make things just as easy as possible um for someone starting off okay so i'll talk about this right bit method in a moment but just literally just put down exactly what you see here and it'll it'll it'll all make sense uh very shortly okay so um when we go to actually write or to read the first thing that we need to do is we actually need to go off and connect okay so i if you can see here we just have this client variable and then we go connect so just but don't connect to we put the ip address of the actual the plc and then this is just rack and then slot so practically all the time you're going to have a rack of 0 with an s7 300 don't even know where it's possible to be any other number and then basically you just have the slot that's where the cpu is so this will never change but then you just put in obviously the string of uh the the ip address of the of the the plc itself okay so the next thing that we're going to do is we're going to just go right bit here so um in terms of yeah what to put down we just literally just go right bit it we're making a reference to the method and all we're doing here so i actually just need to put that i put that in again so we just literally just pass a string here in this case say for example we've got db2 dot dbx the x identifying that it's a bit and then we just have its position and then the bit okay so um an example of that just to refresh anyone's memory the way the data blocks work just in this case here you just have all of these different positions here and then you have the bits inside of the the bytes effectively okay so this is say for example the second bite this is the fourth bite this is the fourth first bit in the four point it's just you have to be very very specific um in in that sense okay so then there's literally true here which is used as a bool value true or false and they're just kind of important to write down okay and essentially if i come down through here what i'm seeing is that just there is a number of um just kind of string conversions going on where we're actually just extracting out numbers that's effectively it what we what we're looking for really is we're looking at for the db number then we're looking for the position and then we're looking for the bit number and then obviously there's the boolean value so i once we go past this right this set bit function is what i need to explain a bit of detail here so what you'll see is that there's a reference to the byte then there's the position of the bit where where is it and then we actually see the value as to whether we want to be true or false and then there is a i could go into explaining this but essentially you've got this right area and parameter a function which which has all of these different parameters in it so i i will go into this in further detail but essentially what you're doing here is you're just you're taking both the position and the bit itself and your i literally you're you're writing here just one single bit only however this right area function can be used to write massive amounts of data in just in one go okay but essentially just take it that you just leave this entire function here exactly as you see you just put down the string variable of the bit that you want this could be 4.1 or any other value at all and you're after making a connection the next thing that you need to do is you just need to disconnect so you come in in and out and it's it's that simple okay so um what i'm going to do then is i'm just going to run this and hopefully we won't have any errors okay so we don't have any errors we just hit the button and that's all and i'm going to go back to the variable table and see what we have there okay so i'll just go live and i can see that everything is false okay so um what i have here then is i just have the button i'm going to give it a click and see what we get perfect it goes through so that's it's it's working fine we've got no problems at all and i'll just literally modify it back to zero and see where we can go again perfect goes back to true so this is working live now really really um you know kind of uh straightforward in the in in that respect okay so we'll just uh we'll just minimize that guy again and what we're going to do now is we're actually just going to read a bit so that's something that's um you know just as desirable as being able to write the bit to read the bit okay so um i'm just going to actually just copy something from something that i have just on another screen so it's just literally just going to be read i've got a read button and then basically you just have whether something is true or false okay so i'm going to double click this guy right here and i'm going to again so what we're going to do uh when we go to read the bit as well again we just literally we'll just we'll copy for this line from above and we've just got basically so we just do our we do an initial connection and then essentially what we need to do is we just need to um get a bite and we'll do a read okay so basically here i just say i'm after declaring a bite sorry for this uh and after declaring a bite and basically then i go off and i just do a a db read if you click on if you look at db reads you'll see that there's a db number then there's a beginning and then there's a basically a full-on size so we're going to read quite a bit into a um into a buffer here the reason why i put down a byte of four is because if you go in if you look back at the actual the db2 it had four bytes in it so effectively i just want to read the whole i want to read everything um you know back in and then i can look further from from there so as soon as i've done that then they just need to take a little bit of a closer look okay i so i what i do here is i just be very very kind of um quick on it and what i do is i declare a boolean variable and then i get i get the bit at a particular point in the buffer okay so after reading in the four bytes right and i'm going to take it in the first byte which is zero right and i'm going to take the fifth bit okay just as an example but i could take others if i wanted right so um yeah so essentially the next thing i need to do then is i'm actually just going to make an update to this to this label here right so i basically i'm just going to type that in and this is the name of the label that i've given it just said i see it's just as simple as that then i have to come in and i just have to give a a disconnect so if this is confusing anyone here it's just the fact that the name of this label um he's literally zsc one zero six seven states it's just just that is what it is i just want to check i don't have any errors in here i don't think i do so i should be i should be good to go okay so um if i go back then to my screen here what i'll see if i try to do a read is i see that it's false then if i go to modify this guy to number to true then i can see true so therefore what i've shown here is just um in a in as quick as a a a way as it possibly can i've shown how to exactly do how do you write a bit how do you read a bit and this is something that can cause a bit of confusion so i think i'll do a separate video entirely on that again but the next video is going to be with an s7 1500 and you know i'm going to be looking at tiaa live and i'm going to start looking that uh you know it gets a little bit trickier and when you try to write very large amounts of data all in one go um you know and looking at kind of like historian type of concept as well how would you kind of log stuff you know what i mean a poll and poll and poll and poll and you know continuously the plc and and and so on but hopefully that what that's done is it's shown how easy it is i'm using this library um you know in order to kind of request something and then you know i you know basically get the information back that you want
Info
Channel: Alan Phillips
Views: 674
Rating: undefined out of 5
Keywords: snap7, sharp7, c#, s7, plc, tia, s7 300, s7 1500, s7 1200, siemens
Id: STmoaSzqUY8
Channel Id: undefined
Length: 19min 7sec (1147 seconds)
Published: Sat Sep 12 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.