简体   繁体   中英

Reading from wincc with C#

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?

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.

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.

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" });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM