opc-da-client
Backend-agnostic OPC DA client library for Rust — async, trait-based, with RAII COM guard.
Features
- Async/Await API: Built for modern asynchronous Rust using
tokioandasync-trait. - Trait-Based Abstraction: The
OpcProvidertrait allows for easy mocking and backend swapping. - RAII COM Guard:
ComGuardhandles COM initialization/teardown automatically — no manualCoUninitializeneeded. - Read & Write Support: Read tag values and write typed values (
Int,Float,Bool,String) to OPC tags. - Windows COM/DCOM Support: Native OPC DA backend via
windows-rs— no external OPC crates needed. - Robust Error Handling: Leverages
anyhowfor clear error chains andfriendly_com_hint()for human-readable HRESULT explanations. - Test-Friendly: Built-in
MockOpcProvidervia thetest-supportfeature.
Installation
Add this to your Cargo.toml:
[]
= "0.1.3"
Prerequisites
- Operating System: Windows (COM/DCOM is a Windows-only technology).
- OPC DA Core Components: Ensure the OPC DA Core Components are installed and registered on your system.
- DCOM Configuration: If connecting to remote servers, appropriate DCOM permissions must be configured.
Usage Examples
Connecting & Listing Servers
Enumerate available OPC DA servers on a local or remote host.
use ;
async
Reading Tags
Connect to a specific server and read current values for a set of tags.
use ;
async
Writing a Value
Write a typed value to a single OPC tag.
use ;
async
Browsing the Address Space
Recursively discover available tags on an OPC server.
use ;
use ;
async
Architecture
The library is split into a core trait layer and concrete implementations:
OpcProvider: The primary async trait defining OPC operations (list, browse, read, write).OpcDaWrapper: The default implementation using nativewindows-rsCOM calls. Generic overServerConnectorfor testability; defaults toComConnector.ComGuard: RAII guard ensuringCoUninitializeis called exactly once per successfulCoInitializeEx.
See architecture.md for in-depth design details and spec.md for behavioral contracts.
License
This project is licensed under the MIT License.