Skip to content

Modern .NET 8 OPC DA client library with seamless local/remote server communication, Windows impersonation support, sync/async operations, real-time subscriptions, and server browsing

Notifications You must be signed in to change notification settings

MohamedGobran/SimpleOpcDAClient

Repository files navigation

SimpleOpcCom

.NET 8 OPC DA client library - Seamlessly connect to local/remote OPC servers, read real-time process data, and subscribe to data changes with simple, modern C# API


📚 Quick Navigation

For Users

For Developers

Learning OPC DA


⚡ Quick Start

Installation

# Clone the repository
git clone https://github.com/yourusername/SimpleOpcCom.git

# Build the library
cd SimpleOpcCom
dotnet build SimpleOpcCom.sln

Basic Usage

using SimpleOpcCom;

// Create client
using var client = new OpcDaClient();

// Connect to OPC server
var options = new OpcConnectionOptions("localhost", "Matrikon.OPC.Simulation.1");
client.Connect(options);

// Read data
var value = client.Read("Random.Int4");
Console.WriteLine($"Value: {value.Value}, Quality: {value.QualityString}");

// Subscribe to real-time changes
var key = client.Subscribe(
    new[] { "Random.Int4", "Random.Real8" },
    values => {
        foreach (var v in values)
            Console.WriteLine($"{v.ItemName} = {v.Value} [{v.QualityString}]");
    },
    updateRate: 1000  // Update every 1 second
);

// Disconnect (automatic with 'using')

See Quick Start Guide for detailed 5-minute tutorial.


✨ Key Features

Connection Management

  • Local and remote connections - Connect to OPC servers on any machine
  • Windows impersonation - Use different credentials for remote servers
  • Automatic DCOM configuration - Seamless remote communication
  • Connection state monitoring - Know when connected/disconnected

Data Operations

  • Synchronous reading - On-demand data retrieval with immediate results
  • Asynchronous reading - Non-blocking async/await operations
  • Batch reading - Read multiple items efficiently in one call
  • Real-time subscriptions - Get callbacks when data changes
  • Quality checking - Built-in validation of data reliability

Server Interaction

  • Server discovery - Automatically find OPC servers on network
  • Address space browsing - Navigate hierarchical tag structure
  • Item descriptions - Retrieve user-friendly tag names

Advanced Features

  • Thread-safe operations - Safe for concurrent access
  • Proper COM cleanup - No memory leaks
  • Dynamic cloaking - Advanced security for remote connections
  • Comprehensive error handling - Detailed error messages and translations

🏗️ Architecture

SimpleOpcCom is a modern, robust .NET library for communicating with OPC DA (Data Access) servers. It provides:

  • Simple API - Easy-to-use interface for OPC DA operations
  • Multi-targeting - Supports .NET 6.0, 7.0, and 8.0
  • Thread-safe - Safe for concurrent operations
  • Proper Resource Management - Automatic COM cleanup with IDisposable pattern
  • Production-Ready - Comprehensive error handling and logging support

Project Components

Core Library:

  • SimpleOpcCom/ - Main class library (.NET 6.0/7.0/8.0)
    • OpcDaClient - Main client class
    • OpcConnectionOptions - Connection configuration
    • OpcItemValue - Data model
    • OpcException - Custom exception handling

Example Applications:

  • Examples/OpcDaClient-BasicUsage/ - Console application demonstrating basic usage
  • Examples/OpcDaClient-Impersonation/ - Windows impersonation example
  • Examples/OpcDaService/ - Production-ready Windows Service

GUI Application:

  • SimpleOpcCom.WpfClient/ - Professional WPF desktop application
    • Server discovery and browsing
    • Real-time data monitoring with visual indicators
    • Profile management with save/load
    • Subscription management

📋 System Requirements

Runtime Requirements

  • Operating System: Windows 7/8/10/11, Server 2012 or later
  • .NET Runtime: .NET 6.0, 7.0, or 8.0 Runtime
  • Platform: x86 (32-bit) - Required for OPC DA COM compatibility

Development Requirements

  • .NET SDK: .NET 8.0 SDK or later
  • IDE: Visual Studio 2022 or Visual Studio Code
  • OPC Server: Any OPC DA 2.0/3.0 compatible server for testing

Network Requirements (Remote Connections)

  • TCP port 135 (DCOM endpoint mapper)
  • TCP ports 49152-65535 (dynamic RPC ports)
  • Proper DCOM permissions configured

🚀 Example: Remote Connection with Impersonation

using SimpleOpcCom;

// Connect to remote OPC server with different credentials
var options = new OpcConnectionOptions("192.168.1.100", "Matrikon.OPC.Simulation.1")
{
    UseImpersonation = true,
    ImpersonationUsername = "opcuser",
    ImpersonationPassword = "password",
    ImpersonationDomain = "192.168.1.100"  // Server hostname for local account
};

using var client = new OpcDaClient();
client.Connect(options);

// All operations now use impersonated credentials
var values = client.Read(new[] { "Random.Int4", "Random.Real8" });
foreach (var value in values)
{
    Console.WriteLine($"{value.ItemName} = {value.Value} [{value.QualityString}]");
}

See Impersonation Guide for complete documentation.


📖 Documentation Structure

Documentation/
├── User-Guide/                        # User-facing documentation
│   ├── USER-GUIDE.md                  # Complete user guide
│   ├── QUICK-START.md                 # 5-minute tutorial
│   ├── EXAMPLES.md                    # Code examples
│   ├── WINDOWS-SERVICE-GUIDE.md       # Windows Service deployment
│   └── WPF-CLIENT-GUIDE.md            # WPF GUI application guide
│
├── Developer-Guide/                   # Developer documentation
│   ├── DEVELOPER-GUIDE.md             # Complete developer guide
│   ├── API-REFERENCE.md               # API documentation
│   └── IMPERSONATION-GUIDE.md         # Windows impersonation deep-dive
│
├── Theory-and-Concepts/               # Educational content
│   ├── OPC-DA-FUNDAMENTALS.md         # OPC DA concepts
│   ├── COM-DCOM-EXPLAINED.md          # COM/DCOM technology
│   ├── SECURITY-BEST-PRACTICES.md     # Security guidance
│   └── NETWORK-CONFIGURATION.md       # Network setup
│
└── Troubleshooting/                   # Problem-solving guides
    ├── TROUBLESHOOTING-GUIDE.md       # Complete troubleshooting
    ├── SUBSCRIPTION-TROUBLESHOOTING.md # Subscription-specific issues
    ├── CONNECTION-ISSUES.md           # Connection problems
    └── DCOM-CONFIGURATION.md          # DCOM setup guide

Browse Complete Documentation →


🔧 Common Issues

"Class not registered" error? → Ensure your application targets x86 platform (not AnyCPU or x64). Most OPC DA servers are 32-bit.

Remote connection fails? → Check DCOM permissions and firewall configuration. See DCOM Configuration Guide.

Subscriptions not receiving updates? → Ensure subscribed items have changing values (OPC DA subscriptions are change-driven). See Subscription Troubleshooting.

Complete Troubleshooting Guide →


🛠️ Tools and Resources

OPC Testing Tools

External Resources


📝 Version History

v1.0.0 (2025-11-04)

  • Initial release
  • Core OpcDaClient library with full OPC DA support
  • Windows impersonation for remote connections
  • Real-time subscription functionality
  • Example console applications
  • Production-ready Windows Service
  • Professional WPF GUI client
  • Comprehensive documentation

🤝 Contributing

We welcome contributions! Please see the Contributing Guide for details on:

  • Code standards and conventions
  • Development workflow
  • Testing requirements
  • Pull request process

📄 License

[Add license information here]


💬 Support


Built with ❤️ for industrial automation

Last Updated: 2025-11-14 | Version: 1.0.0

About

Modern .NET 8 OPC DA client library with seamless local/remote server communication, Windows impersonation support, sync/async operations, real-time subscriptions, and server browsing

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages