OPC UA .NET SDK示例教程:C#、VB.NET与C++ CLI项目使用指南

需积分: 50 7 下载量 6 浏览量 更新于2024-12-10 收藏 357KB ZIP 举报
资源摘要信息: "OPC UA .NET SDK示例项目库详细解析" 1. 标题解析 标题 "opcuanet-samples:C#,VB.NET和C ++ CLI的示例项目可指导开发人员使用我们的OPC UA .NET SDK" 指出了文档的主要内容和目的。该标题明确表示文档中包含了针对不同编程语言(C#,VB.NET以及C++ CLI)的示例项目,这些项目旨在辅助开发人员理解和使用OPC UA .NET SDK。OPC UA(Open Platform Communications Unified Architecture)是一种用于实现工业自动化的开放标准,它允许不同制造商的设备和系统之间进行互操作。.NET SDK则是为这些语言提供的一套软件开发工具包,用于创建能够支持OPC UA协议的应用程序。 2. 描述解析 描述部分详细说明了示例项目的具体应用,指出项目中包含了指导如何使用OPC UA .NET SDK开发OPC UA客户端和服务器应用程序的代码示例。这些示例是直接针对.NET开发者设计的,能够帮助他们更快地理解并应用OPC UA技术。描述中还特别强调了示例代码以最小的依赖项实现,并且可以在生产环境中使用,但同时提醒用户对示例代码的准确性和正确性不提供保证。 3. 标签解析 标签列出了与示例项目紧密相关的关键词,这些关键词有助于定位和理解项目内容。标签中提到了"C#"和"VB.NET",这是.NET平台下的两种主要编程语言;"dotnet"、"dotnetcore"、"dotnet-standard"指的是.NET的核心框架和标准版本;"vb-net"、"vbnet"、"c-sharp"、"csharp"是这些编程语言的常见缩写。"OPC"、"UA"、"opc-ua"是工业自动化领域的标准协议;"opcua"、"opc-ua-client"、"opcua-client"、"opc-ua-server"、"opcua-server"指出了示例项目专注于OPC UA客户端和服务器端的开发。 4. 压缩包文件名称列表解析 文件名称列表 "opcuanet-samples-master" 暗示了该资源是一个压缩包,其中包含了多个示例项目。"master"通常指的是一个代码库的主分支,表明这个资源可能是基于某个版本控制系统的主分支导出的,比如Git。这样的命名方式有助于用户识别和下载正确的资源文件。 5. 综合知识解析 OPC UA是一种跨平台、跨厂商的工业通信协议,旨在替代老化的OPC Classic,并提供了更加丰富和安全的数据交互能力。它支持从简单的传感器数据读取到复杂的系统级集成。OPC UA .NET SDK是这一通信协议在.NET平台上的实现,它使得开发者能够利用.NET框架开发出跨平台的应用程序,这些应用程序可以与其他支持OPC UA的设备和系统进行交互。 .NET开发者在创建OPC UA应用程序时,可以使用OPC UA .NET SDK提供的客户端API连接和操作服务器,也可以实现自己的OPC UA服务器供其他客户端连接和数据交换。在SDK中,开发者能找到创建连接、读写数据、管理会话以及安全通信等功能的相关类和方法。 综上所述,本资源主要面向.NET平台的开发者,特别是那些需要与工业自动化设备进行交互的开发者。它通过提供各种编程语言的示例项目,帮助开发者快速上手OPC UA技术,并将其应用到实际的开发工作中去。由于示例项目是按原样提供的,开发者在使用这些示例时需要自行验证其正确性和适用性,尤其是在生产环境中使用时要进行充分的测试和验证。
2016-10-28 上传
Overview This OPC UA reference implementation is targeting the .NET Standard Library. .Net Standard allows developing apps that run on all common platforms available today, including Linux, iOS, Android (via Xamarin) and Windows 7/8/8.1/10 (including embedded/IoT editions) without requiring platform-specific modifications. Furthermore, cloud applications and services (such as ASP.Net, DNX, Azure Websites, Azure Webjobs, Azure Nano Server and Azure Service Fabric) are also supported. Features included 1. Fully ported Core UA stack and SDK (Client, Server, Configuration & Sample assemblies) 2. Sample Servers and Clients, including all required controls, for .Net 4.6, .NetCore and UWP. 3. X.509 certificate support for client and server authentication 4. Anonymous, username, X.509 certificate (experimental) and JWT (experimental) user authentication 5. UA-TCP & HTTPS transports (client and server) 6. Folder certificate-store support 7. Sessions (including UI support in the samples) 8. Subscriptions (including UI support in the samples) Getting Started All the tools you need for .Net Standard come with the .Net Core tools. See here for what you need. How to create self signed certificates for the sample applications On Windows 1. Open a command prompt in the root folder of your repository 2. Run the script CreateAllCerts.cmd in the root folder of your repository to create the certificates for all sample applications. 3. Alternatively, you can run the script CreateCert.cmd in each sample project folder to create new self signed certificates for the application. 4. The self signed certificates are stored in OPC Foundation/CertificateStores/MachineDefault in each application project folder On Linux 1. Open a command prompt 2. Navigate to the project folder of the sample app, e.g. SampleApplications/Samples/NetCoreConsoleClient 3. Run the script ./createcert.sh to create the certificates for the sample applications. 4. The self signed certificates are stored in OPC Foundation/CertificateStores/MachineDefault in each application project folder How to build and run the samples in Visual Studio on Windows 1. Create certificates for all sample applications. 2. Open the solution UA-NetStandard.sln with VisualStudio. 3. Choose a project in the Solution Explorer and set it with a right click as Startup Project. 4. Hit F5 to build and execute the sample. How to build and run the console samples on Windows, Linux and iOS This section describes how to run the NetCoreConsoleClient, NetCoreConsolePublisher and NetCoreConsoleServer sample applications. Please follow instructions in this article to setup the dotnet command line environment for your platform. Prerequisites 1. Once the dotnet command is available, navigate to the root folder in your local copy of the repository and execute dotnet restore. This command calls into NuGet to restore the tree of dependencies. Start the server 1. Open a command prompt 2. Now navigate to the folder SampleApplications/Samples/NetCoreConsoleServer. 3. Run the script ./createcert.sh on Linux or CreateCert.cmd on Windows to create the self signed certificate for the command line application. 4. To run the server sample type dotnet run. The server is now running and waiting for connections. In this sample configuration the server always accepts new client certificates. Start the client 1. Open a command prompt 2. Now navigate to the folder SampleApplications/Samples/NetCoreConsoleClient. 3. Run the script ./createcert.sh on Linux or CreateCert.cmd on Windows to create the self signed certificate for the command line application. 4. To execute the sample type dotnet run to connect to the OPC UA console sample server running on the same host. To connect to another OPC UA server specify the server as first argument and type e.g. dotnet run opc.tcp://myserver:51210/UA/SampleServer. How to build and run the OPC UA Web Telemetry sample • Go to the Azure portal and create a new Storage account. • Open the solution OpcUaWebTelemetry.sln with VisualStudio 2015. • Open the MessageProcessing\Configuration.cs file to configure the app to use your Azure resources (Storage account and IoTHub). // {StorageAccountName} is the name of the storage account and could be found // under Settings->Access keys->Storage account name of your storage account on the Azure portal. // {AccessKey} is the access key of the storage account and could be found // under Settings->Access keys->key1 of your storage account on the Azure portal. public static string StorageConnectionString = "DefaultEndpointsProtocol=https;AccountName={StorageAccountName};AccountKey={AccessKey}"; // {ConsumerGroupName} is the name of a aonsumer group of your IoTHub. The IoTHub you use is the // one you have created for use with the OPC UA Publisher sample. // You need to create this consumer group via the messaging settings of your IoTHub in the Azure portal. // We recommend that you do not share this Consumer group with other consumers, nor that you use the $Default consumer group. public static string EventHubConsumerGroup = "{ConsumerGroupName}"; // {EventHubEndpoint} is the Event Hub compatible endpoint of your IoTHub and could be found // under Settings->Messaging->Event Hub-compatible endpoint of your IoTHub in the Azure portal. // {PrimaryKey} is the IoT Hub primary key for access with iothubowner policy and could be found // under Settings->Shared access policies->iothubowner->Primary key of your IoTHub in the Azure portal. public static string EventHubConnectionString = "Endpoint={EventHubEndpoint};SharedAccessKeyName=iothubowner;{PrimaryKey}"; // {HubName} is the Event Hub compatible name of your IoTHub and could be found // under Settings->Messaging->Event Hub-compatible name of your IoTHub in the Azure portal. public static string EventHubName = "{HubName}"; • Save the file, rebuild the solution and start it. This will start a local instance of the application. • The solution can also be deployed into a Azure App service. Please use VisualStudio 2015's Azure publishing functionality for this purpose. • Now run the OPC UA Publisher sample, connect to a OPC UA server and publish a node. • You should see the node value on the web page after a few seconds. License This repository includes the UA .NetStandard Stack, sample libraries, and sample applications. The UA .NetStandard Stack follows a dual-license: • OPC Foundation Corporate Members: RCL • Everybody else: GPL 2.0 • RCL enables OPC Foundation members to deploy their applications using the UA .NetStandard stack without being required to disclose the application code. Non-members must disclose their application code when using the UA .NetStandard Stack. • Note: Dual license applies to this repository only; GPL 2.0 applies to all derived repositories (for example 'forks'). For details check the License section below. • All samples are provided under the MIT license. Contributing We strongly encourage community participation and contribution to this project. First, please fork the repository and commit your changes there. Once happy with your changes you can generate a 'pull request'. You must agree to the contributor license agreement before we can accept your changes. The CLA and "I AGREE" button is automatically displayed when you perform the pull request. You can preview CLA here.