How to connect to Siemens S7 plc with C# and Sharp7 library

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello I'm Jenny from assassination.com and today we talk about Shelter Island that is a library to communicate with similar 70c by using C sharper so let's see how we can download the library so you can go on with automation calm this is an article how to write AC major seven basic column here you have the link to download the library I already downloaded it but I can show you so you go on shows foot then you go on chef Sevan then you go on downloads he'll find shops RM and the most recent version is d li and you just assume to download chef Sevan dot CS that is basically the sources of the library so here we downloaded the library if you need the entire package you can go on shop seven full you download it and the design load you will download a full zip package the container up share a folder with the suit that is not till a version is up if the first version so the bus here are not fixed here you have examples for windows formal controlling with any believer so in this platform does you have documentation and the user manual so this is how you have to do to download a chef Sevan library so if we take a look at the user manager server section that are interesting for example you can see the compatibility of the functions of the protocol in the page nine of the user manual well that is compatibility here you can see for example that the CPU 300 and 400 they are comfortable with all the instructions participe o 1200 and 1500 are compatible only with reading of output input Marcus and TB also CPU logo and 7200 they're comfortable again only with DB input output and marker readings so basically if you need to to read the time as counters and such PC data time and so on you cannot do that on the newest CPU so to connect to the PLC you need to specify three parameters one is the P address the second one is the back and the third one is the slot now we are going to create a projector into sharper to connect to a PLC I will use the AC team because I actually don't have a CPU but it's basically the same thing to connect to this PA system and to connect to a real PLC this is your portal with 13 Service Pack 1 so if you download the project and you you can just open the project with your portal and so you have to unzip the project and open the project ok in this process I have a bunch of the beat and program blocks a really simple project just to show some features for example I have a timer and new contacts and foil and then I have 2 DB with some variables of different types so I can show you also some conversions and ultimately from a DB one in the g3 so to connect with shop 7 we have to set the protection of the PLC on the device configuration so we double click on device configuration we go on the user manual and as you can see under protection sections you see that you have to set protection on the CPU of full access so from the wise to configuration you click on the CPU you go on the bottom you click on protection then you click on full access and here you have to click on parameter with good communication level I already did this before also to read the DB there are other instruction in the user manual so you go on Vivi's repartee you have to uncheck optimized block others so for example you go on properties under the v1 and on attribute this must be unchecked this is checked by default you have to remember for every DB to uncheck this once you uncheck this you see that about the half set of the value this is what we need to refresh the memory so let's create a c-sharp project right now so I will start with a new project and name it sharp seven jump so simple simple console application nothing too difficult just to connect and to read and write some DB before starting we have to include chef Sevan library usually I create a second project to include the library I will just right click on the solution add new project select class library and write short seven so and on sub seven I go on my download I will grab the shafts and OCS file I will put it on short seven project B the project ok then I go on my project is I don't have any more this earth we can also delete this class this is my project I will add a reference to sharp seven so I change the name of sharp seven inches for a battle if you don't have the same name for the class and the project let's go to our program let's ask individuals using shops and then we create a client oxygen middle class we have to connect to the PLC we use the medical next to teach will ask us for address flag and clock we will fight in Iraq and lot in the purpose we have to go to device configuration here we have to with properties then work on the top to general and here we find that I can't walk so slow this one that is it practice zero this number must be exact if you want to connect then we have to check for the connection result then we have to disconnect at the end let's check that these values are correct and people need the connection works perfect cutter okay now we can go on the portal and read the TV one two this TV one we covered it in in what way to recover all the values in bytes so we have to read thirty four bytes plus this value that is four bytes so we have two thirty eight bytes so we have to use a mental wreck ticket DVD if you love to the TV number 61 from Sutton from zero societies operate with age and it asks us for buffer a buffer is an array of bytes we can create curve so we can get a end of the box and the buffer itself gives us our result results so we can check the receiver put let's see if this works okay here we're reading letters are to zero so our buffer should contain the data here's the data okay this is at seven bunch of PI's we need to convert them so to convert them so we have to use the sharp seven functions okay let's see the data so we have to cube it at address zero point zero zero point one let's written one then we have to read for an integer okay again okay this number is up the offset so do it to convert this variable if I'm starting from zero I have to write true so then we have a real then we add int then we have and you know okay let's check for now these values that they are correct we don't have to check for correction in conversion with a set of nah communication so we don't have to check for the results so the first is for second is 450 that's 6.5 and want to be precise it so they seems to be collected so let's see how we can reduce the X additional values so that's okay with us anything taken a final shot we are not going to read the excavational value but they're going to read been very clear so let's just run it and this is what we obtain so let's see what we have here so the first one is 1 e 2 4 0 and it is 1 e 2 4 0 the second one is e 2 4 0 tis wrong yeah we are living the wrong address so here radio so nice this is how to rate the full DB and how to convert the values so you have to create a passel of all the bytes that you want to read and then you have to specify the position of the woods and convert so what we do now is to write some values to the DB we will start to write some values to DB 1 plus t VW to the tips the integral at offset - so to try to tell you is really similar to this value but this time instead of trading a bastard you have to write the rasa so in this case we have to create a buffer of 2 bytes because you are writing an s7 interior so there are 2 by 16 bits select create a buffer now we have to fill the buffer with the data that we want to write so we will use a set in so Kevin got a stint at and then he asked for the referral process and we can set the position to the position is 0 and we can write 15 so now we can write on the DV we have to check for the right result and again we have to check if it's provide or not so let's put a back black point here here we have a 50 on the b2 so now we are going to write 15 so right result is okay and we should see 15 and so the right is correct so we saw how to write a single value to a DB now let's write multiple values on the DB we are going to write from offset 0 to offset to end excluded so we will write all these five variables so we need 12 bytes of different types so with both boolean parallel and a double into okay let's see how we can do that this for our bones we need the set bit at this that's the first bit to true this is wrong because in its reference so we need to perfect this with Alice so let's add the second bit and we just have to change the index for the integral now we are writing from zero so we have to change the index the position and put it on to that it's the offset of integral starting from zero so we have the real and we can use set real @ 32.2 in either afloat so we have to prefix it with us the last one is deemed in and so we can use s 7.17 hat okay we can place again a break point here and check that everything works the bite is too is too little there is too little so we have to make it 1202 make it work so now that we have no Harris and arrived has happened and as you see we shot this we set this to true then 22 and 22 point you so it's really simple to write the consecutive values in a DB or just create a buffer and you just need to set the correct position and index and you are done so an interesting feature of such seven is also the possibility of reading and writing multiple variables by multiple variables I mean multiple DB in the same read so this has several benefits like a faster communication and less disappear requests being exchanged between the BCP and official program so there is multiple variables we can use the function a7 multiple basically it's like reading a single variable but you have to create multiple buffers so in the example we will read both the DB 1 and the DB 321 we are going to read the 34 bits and the DBC we are going to read the first 18 bits so s say before we are going to create two buses 141 and 142 3 so we create a buffer of 54 bytes and 18 bytes then we have to create up multi-valve variables and we have to pass the client so associating an instance of SL emotive are we have to add the two buffers to the class so we are going to use the method add and there are several overloads we have to select the wanted have five members so you can specify the area at the length to be number and so on so that we use a seventh one dot DB and here is a dot byte for water length then we specify the DB number to stop the buffer length and we give a refers to the buffer we are going to do the same for the DBC buffer just we have to specify the victory so again we are going to read our gdb invite we this time with a TD three from zero again DB three bottles of length and atv-3 bus and year it was VP one bus okay so now we can all read so we can just call a seven multiple dot feed and the shop seven library so we'll read in one coil both d1 and d3 this little sign India so again result and we have to check if it go back or not alright okay you can execute the method here we executed it so it is completed and as we see it was really contains the wrapper from BBC env1 lives on TV once again we can convert all the data I expect that they have the same value on for example we can convert for DB three just to see if click are correct so let's just change and the sing so fourth force means 15 mins 25 means one specific so again would I put all the values negative and it's 40 so like before to write multiple areas I have to create multiple buffers to set the values into the buffers and then I can write them by using a certain multiple so let's see how we can do that so let's press s I saw some values we can for example writer these minute fifty and these means 25 and we can write in DB 1 the 50 that is now it's 20 we can create a buffer because we have to write a line integral aggregate of our own of only two bytes and then we create a buffer for db3 of six bytes so we set the first buffer value with set index position zero value we can just use muse 50 and then we can use a seventh object in in DB free buffer let's put plasticity and we can set a real and it needs a float okay so same as before we create a cumulative our class multiple instance now we have to add the buffers so now we have to add the value but we cannot use the code before but we have to set a different start index design so here our sub T index because I am starting from index two here and two here so because we start now from these variables in degree one and this variable individually we have to specify the start because our buffer is only six bytes so here we have to change the index good then we can use the same code to write but in this with let's just change angles all right then we can check the result and let's see what happens in the debugger so it flows so let's go see what happened on DB one we wrote means 15 and on deviously we wrote wrong values so let's see what happens my road from their values they're going back to the let's go back to the code and let's check what fordwi1 it was collect for DB free we can see we set the buffer the first is 0 in the second is 2 so we commit an error concert in the index this is something that happens frequently so if we careful by setting the index correctly sheep both here and here now let's cry let's see if this time we would have done correctly so as you see fifty and fifty five point five five and means fifty basically this is sharp seventh in the same way they read the area the DB area I can read a lot of others area just us she liquor it counters markers input and output and timers again on the latest CPU you can just write each changes read a variety be area and input and output because the timer and the counter are implemented as DB variables is Level II as a real good documentation and all the methods that we use it in this example are explained very well in the documentation and in the examples so you can check the documentation for example for the conversions so that all the error codes there are all the methods use were used on the last part of the user manual with all the examples so if you can't go wrong with this library also Dave novella is very fast on bug fixing and also sports there is a forum you can report their diversity find ok if you want to download this example or a similar one you can again go on my website and you find the link on the github example so in the bottom of the article you find the link and you find the example to download and here you have all the code or similar codes that we used in this mo in the sample application so if you liked the video subscribe the channel there will be more on HMI and more on drivers for PC and official development and like TV devices and leave comments and everything and see you the next video
Info
Channel: Mesta Automation
Views: 48,226
Rating: undefined out of 5
Keywords: Siemens, S7, plc, driver, industrial automation, c#, hmi, scada, sharp7, snap7
Id: T4OECx2MDV0
Channel Id: undefined
Length: 24min 18sec (1458 seconds)
Published: Sun Jan 29 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.