Introduction
OPC UA (Open Platform Communications Unified Architecture) is the modern standard for industrial communication. It enables secure, platform-independent data exchange between machines, PLCs, SCADA systems, and enterprise applications.
If you’re building industrial software in .NET, OPC UA is often the backbone of your integration layer.
This tutorial walks through:
- How OPC UA works
- Real architecture in production systems
- Step-by-step .NET implementation
- Best practices for industrial environments
What is OPC UA?
OPC UA is a machine-to-machine communication protocol designed for industrial automation.
It replaces older OPC standards by adding:
- Platform independence
- Built-in security (encryption, certificates)
- Structured data models
- Scalability (from PLC to cloud)
OPC UA Architecture
7
Key Components
- OPC UA Server
- Exposes data (PLC, SCADA, sensors)
- OPC UA Client
- Reads/writes data (.NET app, MES, ERP)
- Address Space
- Structured data model (nodes, variables)
- Transport Layer
- TCP / HTTPS
Real Production Flow
In a real factory setup:
- PLC collects machine data
- OPC UA Server exposes variables
- .NET application reads data
- Data is processed and stored
- MES/ERP consumes results
Example Data Flow
6
Step 1: Install OPC UA in .NET
Run:
dotnet add package OPCFoundation.NetStandard.Opc.UaStep 2: Basic OPC UA Client in C#
Below is a minimal working example.
using Opc.Ua;
using Opc.Ua.Client;
using Opc.Ua.Configuration;public class OpcUaClient
{
public async Task ReadValue()
{
var config = new ApplicationConfiguration
{
ApplicationName = "OpcUaClient",
ApplicationType = ApplicationType.Client,
SecurityConfiguration = new SecurityConfiguration
{
AutoAcceptUntrustedCertificates = true
},
TransportConfigurations = new TransportConfigurationCollection(),
TransportQuotas = new TransportQuotas { OperationTimeout = 15000 },
ClientConfiguration = new ClientConfiguration()
}; await config.Validate(ApplicationType.Client); var endpoint = CoreClientUtils.SelectEndpoint("opc.tcp://localhost:4840", false);
var endpointConfig = EndpointConfiguration.Create(config);
var configuredEndpoint = new ConfiguredEndpoint(null, endpoint, endpointConfig); using var session = await Session.Create(
config,
configuredEndpoint,
false,
"OPC UA Session",
60000,
null,
null); var nodeId = new NodeId("ns=2;s=Machine/Temperature"); var value = session.ReadValue(nodeId); Console.WriteLine($"Temperature: {value.Value}");
}
}Step 3: Connecting to PLC (Siemens Example)
8
Steps:
- Enable OPC UA Server in PLC (e.g. Siemens S7-1500)
- Configure endpoint (e.g.
opc.tcp://192.168.0.10:4840) - Define exposed variables
- Import certificate in client
Step 4: Subscriptions (Real-Time Data)
Polling is inefficient. OPC UA supports subscriptions.
var subscription = new Subscription(session.DefaultSubscription)
{
PublishingInterval = 1000
};var monitoredItem = new MonitoredItem(subscription.DefaultItem)
{
StartNodeId = new NodeId("ns=2;s=Machine/Speed"),
AttributeId = Attributes.Value,
SamplingInterval = 1000
};monitoredItem.Notification += (monitoredItem, e) =>
{
foreach (var value in monitoredItem.DequeueValues())
{
Console.WriteLine($"Speed: {value.Value}");
}
};subscription.AddItem(monitoredItem);
session.AddSubscription(subscription);
subscription.Create();OPC UA vs SCADA vs Direct PLC Access
| Approach | Pros | Cons |
|---|---|---|
| Direct PLC | Fast | Vendor lock |
| SCADA | Visualization | Limited integration |
| OPC UA | Standardized, secure | Slight overhead |
Security in OPC UA
OPC UA includes:
- Encryption (TLS)
- Certificates
- Authentication
- User roles
Important in production:
- Never use
AutoAcceptUntrustedCertificates = true - Use signed certificates
- Restrict endpoints
Best Practices
1. Use Subscriptions, not Polling
Better performance and scalability.
2. Separate Integration Layer
Create dedicated service:
OpcUaServiceDataProcessorEventPublisher
3. Use Message Broker
Combine OPC UA with:
- RabbitMQ
- Kafka
Flow:
PLC → OPC UA → .NET → Queue → Microservices
Advanced Architecture (Enterprise)
6
Common Problems
Connection issues
- Firewall blocks port 4840
- Certificate mismatch
Performance
- Too many nodes subscribed
- High sampling rate
Debugging
- Use OPC UA client tools:
- UA Expert
When to Use OPC UA
Use OPC UA when:
- You integrate multiple PLC vendors
- You need secure communication
- You build scalable industrial systems
Avoid when:
- Simple single-device communication
- Ultra-low latency (<1ms required)
Conclusion
OPC UA is the industry standard for modern industrial communication.
For .NET developers, it provides:
- Clean integration layer
- Scalability
- Security
- Vendor independence
If you’re building industrial or manufacturing systems, OPC UA is not optional — it’s foundational.
References
https://www.unified-automation.com/products/development-tools/uaexpert.html
More Info
We implement this in real production systems.
If you need help → contact us