I think the simulator of TIA Portal works. Or eventually just mock the driver altogheter. There is an example on "HMI with WPF part 3" where I use a DummyPlcService.
Hello Mesta Thanks for your video.Can you please tell me that how I can connect to "S7 200 smart" plc? Will it require tsap and what is the configuration for PLC?
hi there, this is a very useful video for me. Currently I am doing TIA Openness, do you have any idea on it? The concept is still the same using Visual Studio and TIA Openness. I really hope i can contact you
Hello Thao, Do you remember what was your firmware? I can easily connect to my plc, but i can't read anything :( while i desactivitez optimized block, and all protections. Thank you
Hey man, do you know any possibility for a PLC like S7-1200 to work as a TCP socket listener so any random IPs from the same subnet could connect at it ? (I am not thinking to MODBUS, just TCP only) - thanks!
thank for the video, it is helpful. I have a question, is there any way we can access the DBs dynamically from the PLC? like lets say we want to find out how many DBs are there in a PLC?
Hey Buddy! can you help me? I'm trying to write and get the value to this address DB14.STRING6.20 and I can't do it. Is giving me the error WrongVariableFormat or something like that. Do you know KEPServer tool ? I can access, write and read to this address without problems. Do you know how I can make it ? Sometimes, the factory line production is giving me the batch number or another important stuff and this is important for me. Thanks!
Ciao Michele, Can you pls tell me if the Dll packed on Nugets is the full Dll with no dependencies to other libraries? I am trying to build this in unity Game Engine and I want to be sure it havent more dependencies than his own Dll. I dont want to go Web Server way , its not professional.
Hi, there is a possibility that after some time without closing the connection with the plc the read class read some strange value? Like 2.xxxE-38 instead of 170666 for a double variable. if i have a service, it's better to keep connection always open or close it and reopen after some times? Thanks.
It shouldn't happen. Do you check LastErrorCode and/or LastErrorString after every read, before using the values? Usually with TCP sockets it's normal to keep the socket open and check from time to time if the connection is still alive. You probably need to investigate more, if this happens only with the double or also if other values are corrupted. Also try to replace ReadClass with a ReadBytes and assign the values manually, to check if it is an issue of the ReadClass method.
Ok, thanks. Sorry but i have some other question. If i want to use ReadClass, i have to use the same name for the variable inside the PLC and inside the class? if i have to read a block of byte representing a string how can i do that? i try declaring an array of bytes but it doesn't work... Thank you very much!
Strings are not supported in ReadClass at the moment, but you can download the sources and contribute to the project. Regarding the names, it's not needed that the names in the class are the same as the names of the DB. The order and variable type in C# must be the same of the DB.
You can use them togheter. The easiest and safest way is to write the "Value" property of the HMI controls from the code. You can also implement the interface ICommComponent, that permits to assign a Tag to a control and the control gets the value by polling the plc. Personally I would go with the first approach.
Hi, I have downloaded the TIA Portal Step 7 Professional version V13 from Siemens offical website. During installation it is giving errror that file "SIMATIC_STEP_7_Professional_V13.001 is not found" even the file is existing in the same dierectory where it is looking for it. Please recommend me some solution for it.
I recently wrote an article on another C# driver that should be compatible with Logo: www.mesta-automation.com/how-to-write-a-siemens-s7-plc-driver-with-c-and-sharp7/ You can check that out.
Hello Mestz Automation, The procedure that you did for the S7-1200 is the same for a Logo ? I am installing the package S7.Net will try it and will give you a feed back Thanks
I got 3 errors that I cant build Visual: CS0815 Cannot assign void to an implicitly-typed variable (LINE 17) CS1061 'Plc' does not contain a definition for 'LastErrorCode' and no extension method 'LastErrorCode' accepting a first argument of type 'Plc' could be found (LINE 20) CS1061 'Plc' does not contain a definition for 'LastErrorString' and no extension method 'LastErrorString' accepting a first argument of type 'Plc' could be found (LINE 20) Can you help ?
HI am the same you too . if you have the anwer .please let me know. thanks. and when you connect if you not clear it yet , you can communication with me my email: hoangtung2205@gmail.com
Do you want to connect your PLC using C#? Use Sharp7 library. Do not use S7.Net. www.mesta-automation.com/how-to-write-a-siemens-s7-plc-driver-with-c-and-sharp7/
I tried this code on visual studio 2017 But I keep getting "System.InvalidCastException" on a row that reads variable from plc. When I open example project it doesn't throw same exception. What could be a problem? I did get and install the .dll from nuget.
I'd like to add that command like IsConnected() seems to work just fine there's some kind of problem I don't understand yet with commands that read variables.
You can only use S7.net and Sharp 7 in C#7 or higher, I have been working around with unity for weeks by now to just notice you simply cant, till unity dont support C# 7. I hope it goes to everyone whom is trying the same. Its simply pointless, tuplas are not supported in unity C# right now and both libraries use it. I just feel I wasted my time :( Gonna turn to try to sniffer the web server from Unity and see how it goes. Give visibility to that, will safe ppl time.
I find ReadClass(); very unstable. Its necessary to keep class properties in order but making any action with class can affect it. According to MSDN " GetProperties(); method does not return fields in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which fields are returned, because that order varies. I consider creating an array with names and addressed of variables from plc and looping through to make many single Read();
I agree that ReadClass it's not the best implementation possible. The point of ReadClass is just to match the same exact structure of a DB in a class, so it can be filled with the data from the plc with a single instruction. Of course if you change the order of variables, in the program or in the plc, it will break. It is more fragile than indexing and convert manually all the data, but it saves you a lot of code.
try checking your PG/PC interface, windows "control panel" - switch to small icon, and then "set pg/pc interface" (or similar), the s7 online has to be connected to the PLCsim, for running af simulated PLC, or the network card a real PLC is connected to, if you have one a real one
Già da tempo programmo in plc e hmi siemens ma a dire il vero sono molto attratto da queste interfacce! Ora la domanda è usando visual studio come interfaccia posso andare a modificare le Db del plc? Mi consiglieresti più vstudio o visual basic da imparare? Grazie
Puoi leggere o scrivere sulle DB, non puoi aggiungere/rimuovere variabili, perche' ci sarebbe da compilare e trasferire il software sul plc. Visual Basic e' dal 2008 che non e' piu' mantenuto da Microsoft. La scelta sta su C# e VB.Net, entrambi in Visual Studio. Tutto lo sviluppo e le novita' di Microsoft sono in C#. VB.Net e' mantenuto solo per motivi storici e per la user-base, comunque molto ridotta, e ha valore 0 sul mercato. Il 99% dei nuovi software in .Net usano C#, come tutte le librerie open source.
the only command working on this package is : isconnected, isavailable, open() ..... the others no !!!! not usefull really, try to work with a real PLC !!
Already solved this...if it will help somebody string Koda = S7.Net.Types.String.FromByteArray(db4Bytes.Skip(6).Take(40).ToArray()); Koda = Koda.Replace("\0", string.Empty); //remove blank positions from stirng
Hi, Thanks for the useful video, what software would you recommend to simulate the PLC device if we have no PLC to connect to?
I think the simulator of TIA Portal works. Or eventually just mock the driver altogheter. There is an example on "HMI with WPF part 3" where I use a DummyPlcService.
Hello Mesta Thanks for your video.Can you please tell me that how I can connect to "S7 200 smart" plc? Will it require tsap and what is the configuration for PLC?
Can s7 be used in real time production environment with Siemens controllers?
hi there, this is a very useful video for me. Currently I am doing TIA Openness, do you have any idea on it? The concept is still the same using Visual Studio and TIA Openness. I really hope i can contact you
Thank you very much for the video.
Is it possible to place NetTOPLCSIM inside the C # library?
Thank you for watching the example
I'm testing it now
When using S7.Net, we ask if there is a license
Should I buy and use it?
But must to pay for this library ?
Hello Thao,
Do you remember what was your firmware?
I can easily connect to my plc, but i can't read anything :( while i desactivitez optimized block, and all protections.
Thank you
Hey man, do you know any possibility for a PLC like S7-1200 to work as a TCP socket listener so any random IPs from the same subnet could connect at it ? (I am not thinking to MODBUS, just TCP only) - thanks!
Hello ,
Can you guild me to what i should do to read data continuously from PLC ?
Thanks for this tutorial, but when it comes to LReal and LInt how do you convert them to get the right value in c#?
How do I assign the offset ?, e.g. 0.0, 0.1 that you have shown.
It shows that I can't modify that value
I am using tia 16
thank for the video, it is helpful. I have a question, is there any way we can access the DBs dynamically from the PLC?
like lets say we want to find out how many DBs are there in a PLC?
No, it doesn't support browsing the DB.
Thank you for the tutorial. My question is can we read the values without using datablocks in TIA portal? thank you
Hello, did u find an answer?
Thank you
Hey Buddy! can you help me? I'm trying to write and get the value to this address DB14.STRING6.20 and I can't do it. Is giving me the error WrongVariableFormat or something like that.
Do you know KEPServer tool ? I can access, write and read to this address without problems. Do you know how I can make it ?
Sometimes, the factory line production is giving me the batch number or another important stuff and this is important for me.
Thanks!
Exactly what I've been looking for last few weeks! Thank you!
Very interesting video, hi, I'm using this library, unfortunately I haven't found a way to use the events on datachange, can you help me? thank you
Ciao Michele, Can you pls tell me if the Dll packed on Nugets is the full Dll with no dependencies to other libraries? I am trying to build this in unity Game Engine and I want to be sure it havent more dependencies than his own Dll. I dont want to go Web Server way , its not professional.
What is the difference between S7.net Library & Snap7 library ? Thank you in advance
Hi, how can i connect a live chart, showing the present value?
Hello i need the port can help me ?
Ciao, funziona anche con s7 300 usato col vecchio simatic manager?
Is it compatible with different PLC, (B&R, Mitsubishi)?
hi, can I syncr time of plc with c# ?
Can you help me? urgent please.
Hi, there is a possibility that after some time without closing the connection with the plc the read class read some strange value? Like 2.xxxE-38 instead of 170666 for a double variable. if i have a service, it's better to keep connection always open or close it and reopen after some times? Thanks.
It shouldn't happen. Do you check LastErrorCode and/or LastErrorString after every read, before using the values? Usually with TCP sockets it's normal to keep the socket open and check from time to time if the connection is still alive.
You probably need to investigate more, if this happens only with the double or also if other values are corrupted. Also try to replace ReadClass with a ReadBytes and assign the values manually, to check if it is an issue of the ReadClass method.
It's possible conexion in C++?
hello, Thanks For a great tuturial, Can you confirm if this library will work for PCS7 system (Siemens s7 4105h plcs)
Thanks.
Can you provide same for Profibus driver? I want to communicate VB.net application with S7-300 with Profibus driver. Please help.
Hello, if i want to use the method ReadClass with a dataBlock bigger than 200 Bytes, how can i do it? I must create 2 different classes?
Thanks!
+Mattia Pavoni it should work also for more than 200 bytes. The comment is outdated.
Ok, thanks. Sorry but i have some other question. If i want to use ReadClass, i have to use the same name for the variable inside the PLC and inside the class? if i have to read a block of byte representing a string how can i do that? i try declaring an array of bytes but it doesn't work...
Thank you very much!
Strings are not supported in ReadClass at the moment, but you can download the sources and contribute to the project.
Regarding the names, it's not needed that the names in the class are the same as the names of the DB. The order and variable type in C# must be the same of the DB.
WHICH VERSION TIA PORTAL DO YOU USE IN THIS VIDEO???
I USE TIA PORTAL V13 STEP 7 PROFESSIONAL BUT CAN NOT OPEN YOUR FILE
Tia V13 SP1. Unzip in a folder then on Tia portal: Project -> Open
Can you tell me why you only use DBXX addresses instead of usong the native addresses of the PLC, such as %Q, %I, %QW, %IW? Thanks!
I always mapped I/O to DB.
Hello! Nice work!
Is possible to use that code with advanced HMI controls?
Thx!
You can use them togheter.
The easiest and safest way is to write the "Value" property of the HMI controls from the code.
You can also implement the interface ICommComponent, that permits to assign a Tag to a control and the control gets the value by polling the plc.
Personally I would go with the first approach.
+Mesta Automation Could you provide an exemple? That would help me a lot!
Thanks again!
I'll see if I can do that this weekend.
Hi,
I have downloaded the TIA Portal Step 7 Professional version V13 from Siemens offical website. During installation it is giving errror that file "SIMATIC_STEP_7_Professional_V13.001 is not found" even the file is existing in the same dierectory where it is looking for it. Please recommend me some solution for it.
I still have to convert the project...
Thanks you so much! This tutorial is so useful!
Helo..how you convert byte (inside is data in hex) to decimal?
Thank a lot !! But in v 0.4.0 has no error processing(var result = plc.Open();), plc. Open return void and has no lasterrorcode .....
Thanks for this video. Function Read / Write Class is working perfectly on newest version TIA15. Regards
thanks a lot . thank you for posting project.
The best tutorial. thanks
Very nice video, thanks for sharing.
Is it easy to create an HMI on C# with Siemens Logo ?
I recently wrote an article on another C# driver that should be compatible with Logo: www.mesta-automation.com/how-to-write-a-siemens-s7-plc-driver-with-c-and-sharp7/
You can check that out.
Hello Mestz Automation, The procedure that you did for the S7-1200 is the same for a Logo ?
I am installing the package S7.Net will try it and will give you a feed back
Thanks
The only issue will be with write and read variables because DBs does not exists in logo you have only Input,Outputs, M and NetworkVariable !!!
I don't know much about logo plc. You can download the sources from Github and make it work anyway.
Can you tell me when i use DBW, DBX, and DBD please ? Thank you so much
DBX is a bool, DBW a word and DBD a double word
I can't read A SINGLE VARIABLE bool type of both DBx... and Qx.y. please help me...thanks so much
I got 3 errors that I cant build Visual:
CS0815 Cannot assign void to an implicitly-typed variable (LINE 17)
CS1061 'Plc' does not contain a definition for 'LastErrorCode' and no extension method 'LastErrorCode' accepting a first argument of type 'Plc' could be found (LINE 20)
CS1061 'Plc' does not contain a definition for 'LastErrorString' and no extension method 'LastErrorString' accepting a first argument of type 'Plc' could be found (LINE 20)
Can you help ?
thank you very much for this awesome tutorial.
Brilliant video! Thank you for posting it!!
Hi, I'm not using PLCSIM. How can I read the DBs by using this program if PLC is connected directly?
HI am the same you too .
if you have the anwer .please let me know. thanks.
and when you connect if you not clear it yet , you can communication with me
my email: hoangtung2205@gmail.com
Hi, I got the solution but I have not tried it yet. We should use Sharp7 library instead of S7.Net.
Keshav Kumar
hi I am not understand yet .about yours talking .
I have real pleasure S7-1200 .type 1212c .V3
now I want make 1 project to practice.
but I have no idea .
Do you want to connect your PLC using C#?
Use Sharp7 library. Do not use S7.Net.
www.mesta-automation.com/how-to-write-a-siemens-s7-plc-driver-with-c-and-sharp7/
I tried this code on visual studio 2017 But I keep getting "System.InvalidCastException" on a row that reads variable from plc. When I open example project it doesn't throw same exception. What could be a problem? I did get and install the .dll from nuget.
I'd like to add that command like IsConnected() seems to work just fine there's some kind of problem I don't understand yet with commands that read variables.
Hello
I can not read the M1000.0 bit marker.
MD1004 read well
System.InvalidCastException: "The specified cast is invalid."
Thank you
I got an error :
System.InvalidCastException: 'Specified cast is not valid.'
Can you help me to fix it.
Thank you.!
hi, I cant read and write strings, can you show please.
it's appearing error: "Couldn't establish the connection to 127.0.0.1.
Message: WrongNumberReceivedBytes"
What is wrong?
this library has an error in the file PLCAddress.cs Row 164. you need to fix VarType.Byte to VarType.Bit
Great work
You can only use S7.net and Sharp 7 in C#7 or higher, I have been working around with unity for weeks by now to just notice you simply cant, till unity dont support C# 7. I hope it goes to everyone whom is trying the same. Its simply pointless, tuplas are not supported in unity C# right now and both libraries use it. I just feel I wasted my time :( Gonna turn to try to sniffer the web server from Unity and see how it goes. Give visibility to that, will safe ppl time.
in reality. We have to update data every mms, how can I do that?
Interesting video.
can we use it withe S7-200 ??
+fares salah no but there is another tutorial in this channel that uses Sharp7, which will work with S7 200
can you give the link of video ? and thanks
I find ReadClass(); very unstable. Its necessary to keep class properties in order but making any action with class can affect it. According to MSDN " GetProperties(); method does not return fields in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which fields are returned, because that order varies.
I consider creating an array with names and addressed of variables from plc and looping through to make many single Read();
I found a better solution. You can create two the same classes. Use ReadClass(); only with one of them and process only the copy.
I agree that ReadClass it's not the best implementation possible.
The point of ReadClass is just to match the same exact structure of a DB in a class, so it can be filled with the data from the plc with a single instruction.
Of course if you change the order of variables, in the program or in the plc, it will break. It is more fragile than indexing and convert manually all the data, but it saves you a lot of code.
why readbytes function use 38 bytes?? i'm sorry not understand clearly
I can't connect to PLCSIM.Could you tell me why,please!!
try checking your PG/PC interface, windows "control panel" - switch to small icon, and then "set pg/pc interface" (or similar), the s7 online has to be connected to the PLCsim, for running af simulated PLC, or the network card a real PLC is connected to, if you have one a real one
Danke für die Infos :D
ciao michele sei italiano? avrei diverse domande da farti?
Ciao, si sono italiano.
Già da tempo programmo in plc e hmi siemens ma a dire il vero sono molto attratto da queste interfacce! Ora la domanda è usando visual studio come interfaccia posso andare a modificare le Db del plc? Mi consiglieresti più vstudio o visual basic da imparare? Grazie
Puoi leggere o scrivere sulle DB, non puoi aggiungere/rimuovere variabili, perche' ci sarebbe da compilare e trasferire il software sul plc.
Visual Basic e' dal 2008 che non e' piu' mantenuto da Microsoft.
La scelta sta su C# e VB.Net, entrambi in Visual Studio. Tutto lo sviluppo e le novita' di Microsoft sono in C#.
VB.Net e' mantenuto solo per motivi storici e per la user-base, comunque molto ridotta, e ha valore 0 sul mercato. Il 99% dei nuovi software in .Net usano C#, come tutte le librerie open source.
Best vid ever
I can't connect to my real PLC (1212c dc/dc/dc), can someone help me? please
i can't fine S7.net.dll
can u send visual studio C # software link free ware and key? ur video is very helpfull me
Visual Studio 2017 Community is free. Search it on google.
Very very well
thank a lot
the only command working on this package is : isconnected, isavailable, open() ..... the others no !!!!
not usefull really, try to work with a real PLC !!
please send your email
Can I use S7.Net with STEP 7? I have a s7400.
Also..how to pass the string? does the program know that first byte is total lengh and second the actual lenght?
Already solved this...if it will help somebody
string Koda = S7.Net.Types.String.FromByteArray(db4Bytes.Skip(6).Take(40).ToArray());
Koda = Koda.Replace("\0", string.Empty); //remove blank positions from stirng
@@matejhlaca1152 hi matej, can you explain for details ? FromByteArray with its contructors ?
@@matejhlaca1152 thanks, I've just solved it.