Connecting to WinCC OPC DA and OPC UA Servers from VB.NET

David Krause9 min read
OPC / OPC UASiemensTechnical Reference
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Overview

Siemens WinCC (both the legacy WinCC V7.x and the current TIA Portal WinCC RT Professional runtime) exposes process tag values through an embedded OPC server. Two generations of this interface are in active use:

  • OPC DA (Data Access) 2.0/3.0 — COM/DCOM based, the original channel used in WinCC V6, V7, and older WinCC RT Professional projects. The classic ProgID is OPCServer.WinCC.1.
  • OPC UA (Unified Architecture) — TCP based, introduced in WinCC V7.2 and is the recommended channel in TIA Portal WinCC RT Professional V17 onward.

Both channels let a VisualBasic 2008 / VB.NET data-collection application read and write WinCC internal tags, archive tags, and alarm variables. This reference covers the ProgID, DCOM, sample code, and the migration path to OPC UA documented in TIA Portal V20.

WinCC OPC Architecture

WinCC Runtime acts as an OPC DA Server and (since V7.2) an OPC UA Server. External applications act as OPC Clients. The same instance can be a server to a SCADA tag on the engineering station and a client to a lower-level PLC OPC channel.

PLC / S7-1500 Tag DB / I/O S7Comm / PROFINET WinCC Runtime Tag Manager OPC DA + OPC UA VB.NET Client DAAutomation 2.0 OPCServer.WinCC.1 Channel selection in TIA Portal V20 OPC DA Channel legacy V7 clients OPC UA Channel V20 default Named Connections S7 channel only

OPC DA ProgID Reference

Every COM/OPC DA server registers a programmatic identifier (ProgID) under HKEY_CLASSES_ROOT. The WinCC runtime registers the following ProgIDs after a complete install:

Server ProgID Description
WinCC OPC DA Server OPCServer.WinCC.1 Default in-process access to internal WinCC tags
WinCC OPC DA Server (V7.x legacy) OPCDAServer.WinCC.1 Variant exposed by some older WinCC V6/V7 builds
WinCC OPC HDA Server OPCHDAServer.WinCC.1 Historical Data Access (archive values)
WinCC OPC AE Server OPCAlarmEvent.WinCC.1 Alarms & Events subscription

If the ProgID is not visible in the registry, the WinCC OPC channel was not installed. Reinstall WinCC with the "OPC" option ticked, or run RegAsm /codebase against the server DLL located in %ProgramFiles%\Siemens\Automation\WinCC\bin\.

Prerequisites

  1. WinCC Runtime (V7.x or TIA Portal V20 RT Professional) installed and licensed on the server PC.
  2. The WinCC project activated so the "WinCC Runtime" service is running — the OPC server only starts with the runtime.
  3. SIMATIC NET installed if you plan to use the S7 OPC channel examples shipped under C:\Program Files\Siemens\SIMATIC_NET\Samples\OPC\.
  4. On the client PC: the "OPC Core Components 2.00 Redistributable" (x86 for VB6/VB2008, x64 for newer .NET) and the OPCDAAuto.dll (Siemens OPC DAAutomation 2.0 wrapper).
  5. Administrator rights on both machines to edit DCOM, Windows Firewall, and COM security.
Critical: WinCC Runtime must be running before any client attempts Connect(). The server reports E_NOINTERFACE / 0x80004002 if the service is stopped.

VB.NET Sample Using OPC DAAutomation 2.0

The interface contract implemented by OPCDAAuto.dll is documented in the OPC Data Access Automation 2.0 Specification. The wrapper exposes four coclasses:

Coclass Interface Role
OPCServer IOPCServer Create group, enumerate children, get status
OPCGroups IOPCGroups Container of groups on this connection
OPCGroup IOPCGroup Add items, set active state, data callback
OPCItem IOPCItem Read/Write a single tag

Add a COM reference in Visual Studio: Project → Add Reference → COM → "Siemens OPC DAAutomation 2.0". The reference embeds the RCW OPCDAAuto.dll from the WinCC bin folder.

' VB.NET 2008/2010+ — WinCC OPC DA read example
Imports OPCDAAuto

Module WinCCClient
  Private WithEvents opcGrp As OPCGroup
  Dim WithEvents srv As OPCServer
  Dim grps As OPCGroups

  Sub Main()
    srv = New OPCServer()
    ' Connect to local WinCC
    srv.Connect("OPCServer.WinCC.1", "127.0.0.1")
    Console.WriteLine("ServerState: " & srv.ServerState.ToString())
    ' Expected: OPC_STATUS_RUNNING = 1

    grps = srv.OPCGroups
    opcGrp = grps.Add("VBGroup")
    opcGrp.UpdateRate = 250           ' ms
    opcGrp.IsActive = True
    opcGrp.IsSubscribed = True        ' enable DataChange callback

    ' WinCC internal tag syntax <prefix>:<name>
    Dim itm As OPCItem
    itm = opcGrp.OPCItems.AddItem("Process.Pressure", 1)
    Console.WriteLine("Initial value: " & itm.Value)

    Console.ReadLine()
    srv.Disconnect()
  End Sub

  Private Sub opcGrp_DataChange(ByVal TransactionID As Integer, _
                                ByVal NumItems As Integer, _
                                ByRef ClientHandles As Array, _
                                ByRef ItemValues As Array, _
                                ByRef Qualities As Array, _
                                ByRef TimeStamps As Array) _
                                Handles opcGrp.DataChange
    For i As Integer = 0 To NumItems - 1
      Console.WriteLine(Now.ToString("HH:mm:ss.fff") & _
        " Handle=" & ClientHandles(i) & _
        " V=" & ItemValues(i) & _
        " Q=" & Qualities(i))
    Next
  End Sub
End Module
Tag prefix in WinCC: use Process. for internal tags, the configured "Connection" name (for example CNC_1.) for S7 tags, Archive. for archive tags. WinCC tags are case-sensitive on the server side.

DCOM Configuration (Remote Client → Remote Server)

When the VB application and the WinCC OPC DA server are on different machines, DCOM must be configured on both ends. Default Windows security blocks anonymous access since Windows XP SP2.

  1. Run dcomcnfg as administrator.
  2. Component Services → Computers → My Computer → DCOM Config. Locate "OPCServer.WinCC". If absent, register it with regsvr32 OPCDAServer.dll from the WinCC bin folder.
  3. Right-click → Properties:
    • General → Authentication Level: Connect (or None for lab test only).
    • Location: tick "Run application on the following computer" and enter the WinCC server hostname.
    • Security: add the client user account to Launch & Activation and Access permissions, allowing Local + Remote.
    • Identity: use "This user" and supply a domain service account that exists on both PCs.
  4. On the WinCC server, open Windows Firewall with Advanced Security and allow OPCEnum (TCP 135) plus the dynamic DCOM range 49152–65535 (or a fixed range set via HKLM\Software\Microsoft\Rpc\Internet keys Ports, PortsInternetAvailable, UseInternetPorts).
  5. On the client, allow outbound 135 and the same dynamic range.
  6. Reboot both machines. Validate with the OPCEnum browser: \<server>\OPCEnum should list OPCServer.WinCC.1.
Production deployments: never use Authentication Level = None. Use a domain service account and certificate-based OPC UA instead — see the next section.

Migrating to OPC UA on TIA Portal V20

TIA Portal V20 documentation Using OPC in WinCC (RT Professional) states that the WinCC runtime ships with an OPC channel that can act as a client to DA or UA servers and exposes itself as an OPC UA server. The default server endpoint in V20 is:

opc.tcp://<wincc-pc>:4840
Security policies: None, Basic128Rsa15, Basic256, Basic256Sha256
Application URI: urn:<hostname>:WinCC-OPC-UA-Server

Activating the WinCC OPC UA Server in TIA Portal V20

  1. In the TIA Portal project tree, right-click the HMI device → Properties → OPC UA Server.
  2. Tick "Activate OPC UA Server".
  3. Set the port (default 4840) and select the security policy and message mode. For a quick lab test, None + Sign is sufficient; production should use Basic256Sha256 + SignAndEncrypt.
  4. Under Security → User authentication, add a user account or use certificate-based trust.
  5. Compile and download to the RT Professional target.
  6. Activate the project. The UA server endpoint becomes reachable as soon as Runtime starts.

This procedure matches Siemens KB article "Configure WinCC OPC UA Server — Communication" (ID 109755215).

VB.NET OPC UA Client (Modern Replacement)

After migration, the OPC DAAutomation wrapper is no longer needed. Use the open-source OPCFoundation.NetStandard.Opc.Ua.Client NuGet package. The replacement pattern is structurally identical to the DA sample above.

// .NET 6+ console client — WinCC OPC UA
using Opc.Ua;
using Opc.Ua.Client;

var cfg = new ApplicationConfiguration() {
  ApplicationName = "VBtoUA",
  SecurityConfiguration = new SecurityConfiguration {
    ApplicationCertificate = new CertificateIdentifier(),
    TrustedPeerCertificates = new CertificateTrustList()
  },
  TransportQuotas = new TransportQuotas() { OperationTimeout = 15000 }
};
await cfg.Validate(Opc.Ua.ApplicationType.Client);
var app = new ApplicationInstance(cfg);
await app.CheckApplicationInstanceCertificate(false, 0);

var endpoint = CoreClientUtils.SelectEndpoint(
  "opc.tcp://<wincc-pc>:4840", useSecurity: false);
var session = await Session.Create(cfg, endpoint, false,
  "VBtoUA", 60000, null, null);

var node = new NodeId("Process.Pressure", 2);   // ns=2 = WinCC default
var val = await session.ReadValueAsync(node);
Console.WriteLine($"Pressure = {val.Value} @ {val.ServerTimestamp}");

await session.CloseAsync();
Namespace index: on a default WinCC V20 install, internal tags live in namespace index 2. Check with UaExpert or the HMS Networks "Communicating to a Siemens WinCC SCADA via OPC UA" reference if tags are not found.

Parameter & Error-Code Reference

Symptom Hex code WinCC / DCOM cause Fix
Server not registered 0x80040154 OPC DAAutomation wrapper not on client Install "OPC Core Components" or run regsvr32 OPCDAAuto.dll
Cannot connect to remote server 0x800706BA DCOM RPC port 135 blocked, or service account missing Open firewall, set DCOM identity to a domain user present on both PCs
Access denied 0x80070005 COM launch/access ACLs Edit Component Services → OPCServer.WinCC → Security tab
Quality BAD / BadCommunicationError 0x80050000 range WinCC RT not running or PLC connection lost Confirm "WinCC Runtime" service is "Started"
Group Add returns InvalidHandle 0x80010107 Stale COM apartment after exception Use MTA thread for the OPC loop; never STA with a pumping form

Troubleshooting Matrix

Layer Diagnostic tool Pass criterion
TCP / DNS Test-NetConnection <server> -Port 135 (DA) or Test-NetConnection <server> -Port 4840 (UA) TcpTestSucceeded = True
DCOM enumeration (DA) OPCEnum browser or OpcEnum.exe from Matrikon Server list contains OPCServer.WinCC.1
Security policy (UA) UaExpert → Add Server → Discover Endpoint returns UserTokenPolicy list
Authentication (UA) UaExpert → Settings → Manage Certificates Client cert is in the server's "Trusted" store at %ProgramData%\Siemens\Automation\WinCC\opc\pki\trusted\
Tag existence WinCC Tag Management → right-click tag → Properties Tag name matches prefix:name syntax used in client

Verification Checklist

  • WinCC Runtime "Started", project "Active" in WinCC Explorer or TIA Portal "Online → Start Runtime".
  • Client successfully calls Connect() without throwing — check ServerState == 1 (OPC_STATUS_RUNNING).
  • A read on a known tag returns a numeric value, not a Quality = 0 (BAD) variant.
  • DataChange callback fires at the requested UpdateRate ±20 %.
  • After Disconnect(), Task Manager → Details on the server shows no orphaned CCExplorer.exe instances.

Field-Proven Caveats

  • VB6 / VB2008 must run as a 32-bit process when using the classic OPCDAAuto.dll; loading the 64-bit variant raises 0x80040154 on a 64-bit client. Build the VB project with "Platform Target = x86".
  • Tag browse via IOPCBrowseServerAddressSpace is throttled by WinCC — never call Browse() inside the DataChange loop; cache the handle list once.
  • Archive tag reads on the HDA server require the WinCC archive segment to be open; a closed segment returns OPC_E_INVALIDHANDLE.
  • On multi-user WinCC systems, the OPC server runs only on the server project; on client projects (WinCC Client), the OPC channel must be enabled in "Server Modules" and the client PC must trust the OPCEnum service account.
  • For new deployments, prefer OPC UA on TIA Portal V20 — DCOM hardening in Windows 11 24H2 has tightened default ACLs and breaks many legacy DA configurations.

FAQ

What is the ProgID of the WinCC OPC DA server?

The default ProgID is OPCServer.WinCC.1. WinCC V7 also registers OPCHDAServer.WinCC.1 for historical data and OPCAlarmEvent.WinCC.1 for alarms and events.

Why does Connect() fail with 0x800706BA on a remote PC?

This is the classic DCOM RPC error. Either TCP port 135 is blocked by the firewall, the WinCC OPC server is not registered on the server, or the DCOM identity account does not exist on the client. Open port 135, confirm dcomcnfg can see OPCServer.WinCC, and set Identity to a domain user present on both PCs.

Do I need WinCC Runtime running before opening an OPC connection?

Yes. The OPC server is hosted by the WinCC Runtime process and only starts when the project is activated. If RT is stopped, the client receives 0x80004002 (E_NOINTERFACE) or the server enumerates an empty list.

How do I expose WinCC tags over OPC UA on TIA Portal V20?

Open the HMI device → Properties → OPC UA Server, tick "Activate OPC UA Server", set port 4840, choose a security policy, then compile, download, and activate the project. The endpoint opc.tcp://<pc>:4840 becomes available immediately, as documented in Siemens KB 109755215.

Can I use the same VB.NET code for DA and UA?

No. OPC DA uses the COM OPCDAAuto.dll wrapper (ProgID OPCServer.WinCC.1), while OPC UA uses the WCF/TCP stack and the OPC Foundation .NET Standard client library. After migrating to TIA Portal V20, replace the COM reference with the OPCFoundation.NetStandard.Opc.Ua.Client NuGet package and connect to opc.tcp://<pc>:4840 instead.

Back to blog