How to Interface External .NET C# Applications with PCS 7 and WinCC Using OpenPCS 7, ODK, and Connectivity Pack

How to Interface External .NET C# Applications with PCS 7 and WinCC Using OpenPCS 7, ODK, and Connectivity Pack

To connect custom C# .NET applications to PCS 7, developers should not attempt to link raw, internal WinCC DLLs, which are undocumented unmanaged C libraries subject to breaking changes. Instead, use Siemens-supported interfaces: OpenPCS 7 provides industry-standard OPC UA and OPC DA interfaces accessible via the standard OPC Foundation .NET SDK; WinCC/ODK (Open Development Kit) provides official, supported C/C++ APIs that can be wrapped using P/Invoke; and the WinCC Connectivity Pack offers standard OLE-DB providers for querying historical alarms and tag archives directly using ADO.NET.

Table of Contents

Risks of Linking Internal WinCC DLLs Directly in .NET

Developers seeking to integrate external manufacturing execution systems (MES), analytics platforms, or proprietary C# tools with SIMATIC PCS 7 often inspect the WinCC installation directory (C:\Program Files (x86)\Siemens\WinCC\bin) and attempt to reference internal DLLs such as CCAxDataStore.dll, dmclient.dll, or pdsv_com.dll.

Attempting to link internal WinCC DLLs directly presents severe technical risks:
1. Unmanaged C Interfaces Without Type Libraries: Internal WinCC libraries are compiled unmanaged C/C++ binaries without .NET metadata or COM interop type libraries. Calling them requires manual P/Invoke declarations with strict C memory alignment that is prone to access violations and memory leaks.
2. Lack of Compatibility Guarantees: Internal DLL functions and export signatures change between PCS 7 versions, Service Packs, and Update rollups without notice. A C# application compiled against PCS 7 V8.0 internal DLLs will crash when deployed on PCS 7 V8.2 or V9.0.
3. Threading and Security Deadlocks: WinCC internal data managers (dmclient) rely on strict single-threaded apartment (STA) models and local DCOM contexts. Calling these APIs from multi-threaded .NET garbage-collected runtimes causes deadlocks, crashes the WinCC graphics runtime (pdlrt.exe), or corrupts the runtime database.
4. Licensing Non-Compliance: Accessing WinCC data without the appropriate interface license violates software licensing terms. Siemens provides dedicated, licensed integration products designed specifically for external access.

Supported Integration Options: OpenPCS 7, ODK, and Connectivity Pack

Siemens provides three officially supported, fully documented pathways for third-party software integration:

  1. OpenPCS 7:
    * OpenPCS 7 acts as an enterprise integration server that consolidates data across multiple OS server pairs.
    * It exposes data via standard industrial protocols: OPC UA (Unified Architecture), OPC DA 2.05a / 3.0 (Data Access), OPC HDA (Historical Data Access), and OPC A&E (Alarms & Events).
    * C# applications can communicate using standard, open-source libraries such as the official OPC Foundation .NET Standard SDK.
  2. WinCC / PCS 7 Open Development Kit (WinCC/ODK):
    * The official option package for developers requiring low-level C-API access to WinCC configuration and runtime data.
    * Provides comprehensive headers (dmclient.h, mcpasup.h), import libraries, sample code, and documentation for tag access, user administration, and alarm logging.
    * Can be wrapped in C# using C++/CLI or P/Invoke wrappers.
  3. WinCC Connectivity Pack:
    * Provides the WinCCOLEDBProvider.1 OLE-DB driver.
    * Enables external applications to query historical process value archives (Tag Logging) and alarm message archives (Alarm Logging) using standard SQL queries and ADO.NET in C#.

Connecting C# Applications via OpenPCS 7 OPC UA / DA

The recommended modern approach for custom C# .NET development is implementing an OPC UA Client connected to the OpenPCS 7 OPC UA Server.

Key architectural steps:
* Install OpenPCS 7 Station: The OpenPCS 7 software runs either on a dedicated PC station or hosted directly on an OS Server / Single Station.
* Configure Security: Open the SIMATIC OpenPCS 7 Configuration tool and set up security certificates (Sign & Encrypt or Sign, Basic256Sha256).
* Reference OPC Foundation SDK in C#: In your Visual Studio project, add the NuGet package OPCFoundation.NetStandard.Opc.Ua.
* Sample C# Connection Code:

using Opc.Ua;
using Opc.Ua.Client;
using System;
using System.Threading.Tasks;

public class Pcs7OpcClient
{
    private Session session;

    public async Task ConnectAsync(string serverUrl)
    {
        var config = new ApplicationConfiguration()
        {
            ApplicationName = "CustomPCS7Client",
            ApplicationType = ApplicationType.Client,
            SecurityConfiguration = new SecurityConfiguration
            {
                ApplicationCertificate = new CertificateIdentifier { StoreType = "Directory", StorePath = "Certificates" },
                AutoAcceptUntrustedCertificates = true
            },
            TransportConfigurations = new TransportConfigurationCollection(),
            TransportQuotas = new TransportQuotas { OperationTimeout = 15000 },
            ClientConfiguration = new ClientConfiguration { DefaultSessionTimeout = 60000 }
        };
        await config.Validate(ApplicationType.Client);

        var endpoint = CoreClientUtils.SelectEndpoint(serverUrl, false);
        var endpointConfig = EndpointConfiguration.Create(config);
        var configuredEndpoint = new ConfiguredEndpoint(null, endpoint, endpointConfig);

        session = await Session.Create(config, configuredEndpoint, false, "PCS7_Session", 60000, null, null);
        Console.WriteLine("Connected to OpenPCS 7 OPC UA Server successfully.");
    }
}

This allows reading live tags, monitoring subscriptions, and invoking methods across the plant bus and terminal bus securely.

Querying Process Archives Using WinCC OLE-DB in C

When historical trends or alarm reports are needed in C#, use the WinCC Connectivity Pack OLE-DB provider rather than proprietary DLLs:

using System;
using System.Data;
using System.Data.OleDb;

public class WinCcArchiveReader
{
    private string connectionString = "Provider=WinCCOLEDBProvider.1;" +
                                     "Catalog=CC_OS_16_10_19_00_00_00_R;" +
                                     "Data Source=OS_SERVER01\\WINCC";

    public void ReadTagArchive(string tagName, DateTime startTime, DateTime endTime)
    {
        // Query format for WinCC OLE-DB archive values
        string query = $"TAG:R,'{tagName}','{startTime:yyyy-MM-dd HH:mm:ss}','{endTime:yyyy-MM-dd HH:mm:ss}'";

        using (OleDbConnection conn = new OleDbConnection(connectionString))
        {
            conn.Open();
            using (OleDbCommand cmd = new OleDbCommand(query, conn))
            using (OleDbDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    DateTime timestamp = reader.GetDateTime(1);
                    double value = reader.GetDouble(2);
                    long quality = reader.GetInt64(3);
                    Console.WriteLine($"{timestamp}: {value} (Quality: {quality})");
                }
            }
        }
    }
}

This interface is fully supported by Siemens, runs in standard 64-bit .NET environments, and does not interfere with the active WinCC runtime process.

Comparison of PCS 7 External Interface Options

The table below compares the supported mechanisms for external application connectivity to SIMATIC PCS 7.

Interface OptionProtocol / TechnologyTarget DataSupported LanguagesLicensing RequirementOpenPCS 7OPC UA, OPC DA, OPC HDA, OPC A&EReal-time tags, Alarms, Historical archivesC#, VB.NET, Python, C++, JavaOpenPCS 7 Server LicenseWinCC / PCS 7 ODKC-Application Programming Interface (C-API)Configuration, Tag Management, User AdminC, C++, C#/CLI WrapperWinCC/ODK Engineering LicenseWinCC Connectivity PackOLE-DB Provider (WinCCOLEDBProvider.1)Historical Tag Logging and Alarm LoggingC#, VB.NET, SQL Reporting ServicesConnectivity Pack License per ServerInternal WinCC DLLsUnmanaged, undocumented proprietary binariesInternal memory structuresNot supportedUnsupported / Prohibited

Verification

To verify external C# integration with PCS 7:
1. If using OpenPCS 7, use a standard third-party test client (such as UAExpert or OPC Quick Client) to connect to opc.tcp://<OpenPCS7_Host>:4841 and verify tag browsing and subscription updates.
2. Run your custom C# application and connect to the OpenPCS 7 endpoint. Confirm that variable values match those displayed in WinCC Graphics Designer.
3. Check the Windows Event Viewer on the OpenPCS 7 server under Applications and Services Logs to ensure no security rejection or certificate validation errors are logged.
4. If using Connectivity Pack, verify that SQL queries execute without COM exceptions and correctly retrieve historical records matching the WinCC Online Trend Control.

Limitations and Operational Precautions

  • Never install third-party developer software (Visual Studio, debugging tools, compiler runtimes) on an active production OS Server; develop externally and connect across the terminal bus.
  • Always validate final license quantities and MLFBs (such as OpenPCS 7 or Connectivity Pack options) against the applicable Siemens catalog and authorized distributor quotation before deploying production interfaces.
  • High-frequency polling over OPC DA or OPC UA can overload the OS Server CPU; use change-based subscriptions (minimum update rate 500 ms) instead of cyclic read polling loops.
  • DCOM-based interfaces (OPC DA 2.05a) require specific Windows DCOM hardening configurations (Microsoft KB5004442); prefer OPC UA to avoid DCOM authentication barriers.

Engineer FAQ

Can I use standard OPC DA in C# without installing OpenPCS 7?

WinCC OS Single Stations and Servers include a local OPC DA 2.05a server. However, connecting remotely over the network without OpenPCS 7 requires configuring complex DCOM permissions on both machines and consumes client connection handles. OpenPCS 7 provides a centralized, multi-server data gateway that isolates production servers from external network traffic.

Why does my C# application crash when calling WinCC ODK C-functions?

WinCC ODK functions use unmanaged 32-bit __stdcall calling conventions and specific memory allocation rules. If your C# project is compiled as Any CPU or 64-bit (x64), calling into 32-bit WinCC DLLs causes a BadImageFormatException or memory access violation. You must target x86 and correctly marshal pointers and structs.

What is the difference between OpenPCS 7 and the WinCC Connectivity Pack?

OpenPCS 7 is primarily designed for real-time data access (OPC DA/UA) and standardized OPC-based historical access (HDA/A&E). The WinCC Connectivity Pack provides direct relational OLE-DB database access to compressed Tag Logging and Alarm Logging archives using SQL syntax.

Technical References

Related Articles

Related Tags

  • OpenPCS 7
  • WinCC ODK
  • OPC UA
  • C# Development
  • Connectivity Pack
6 respuestas