Reading from wincc with C#

3.7k views Asked by At

I need to develop an application that reads some values in a PLC through the wincc interface, I have looked around but the examples I found where all using third party software. The function I need is very basic: I just have to read once the values in the PLC without any further communication. Is there a simple way to do this?

4

There are 4 answers

0
AudioBubble On

Your question is a bit vague. The description you gave is a basic WinCC functionality. To read out a value from the PLC (called a tag) and display it in WinCC. I think that is not the question.

Do you mean to read out a tag (internel or external) from WinCC to your own application? That can be done with the ODK option in WinCC. But that is, like every development kit in Scada/DCS, not available for free.

Or you want to read out a value from the PLC that is also used in WinCC, you need a S7 connection or a open communication. S7 requires a connection resource and configuration in the PLC. Open Communication (done via TCP/IP) needs programming in the PLC.

0
dergroncki On

Here is an example by using the program identifier of WinCC:

System.Type oType = System.Type.GetTypeFromProgID("WinCC-Runtime-Project");
object wincc = System.Activator.CreateInstance(oType);

//Read the name of the runtime database (the @-Prefix identifies WinCC-System-Tags)
object catalog = oType.InvokeMember("GetValue", System.Reflection.BindingFlags.InvokeMethod, null, wincc, new object[] { "@DatasourceNameRT" });

//Read the computer name
object serverName = oType.InvokeMember("GetValue", System.Reflection.BindingFlags.InvokeMethod, null, wincc, new object[] { "@ServerName" });

//Read a WinCC-Tag with the name "MyTag"
object myTag = oType.InvokeMember("GetValue", System.Reflection.BindingFlags.InvokeMethod, null, wincc, new object[] { "MyTag" });
0
Son Nguyen On

I think the questioner hasn't written a line of code yet, neither in c# nor in Ansi-C Wincc. I am myself not from automation industrial sphere, but I understand that you can communicate with PLC directly from any modern language to suit your needs. While Wincc is aiming to rapidly develop HMI software. I currently help students to do some Python Image Processing seamless communication to PLC through Python-Snap7. The equivalent library in c# is c#-snap7 So let the Wincc to step aside.

0
MKMohanty On

Reading of PLC values through Wincc:

On first sight I will suggest read directly through PLC either using OPC, TCP telegrams or some third party library like libnodave. Its much more performant and elegant in use.

Now coming back to your question that you need wincc to supply values to your application. I will suggest following:

  1. Create a .net control or global script.
  2. Create a wcf service or database connection interface (depends on your application).
  3. Connect the tag in which plc is sending the values, in the wincc control and padd it through wcf or database interface.

I think this way is much more cleaner to take values from wincc without affecting its wincc. On the other hand you can use wincc as opc server also.