SIEMENS官方OPC UA示例源码:服务器与客户端开发

版权申诉
5星 · 超过95%的资源 34 下载量 55 浏览量 更新于2024-10-20 3 收藏 100.84MB ZIP 举报
资源摘要信息:"本资源为OPC UA官方服务器与客户端程序的源码压缩包,主要由SIEMENS公司和OPC基金组织提供。该源码具有极高的参考价值,不仅包含OPC UA Server的示例源码,也包含了OPC UA Client的示例源码。资源特别适合编程新手和已经具备一定开发经验的技术人员。 OPC统一架构(OPC Unified Architecture, OPC UA)是由OPC基金会制定的,面向服务的架构标准。它支持跨平台的数据交互和信息建模,并且提供了一种安全、可靠、可扩展的通信机制,广泛应用于工业自动化和制造业领域。 1. OPC UA基础概念 OPC UA是一种跨平台的、与厂商无关的接口标准,它为应用程序提供了丰富的信息模型。信息模型定义了应用程序的数据和行为,使得不同厂商的设备和系统能够无缝交互。OPC UA由一系列规范组成,包括地址空间模型、安全模型、会话模型等。 2. OPC UA安全机制 OPC UA的安全模型包括认证、授权、数据加密和审计功能,它为工业通讯提供了安全保障。安全机制确保了数据的完整性和保密性,防止数据在传输过程中被窃取或篡改。 3. OPC UA的通讯机制 OPC UA使用先进的网络协议栈,提供多种传输方式,如TCP/IP、HTTP等。客户端和服务器之间的通信采用会话管理机制,可以建立、激活和关闭会话。此外,OPC UA的通信模型支持发布/订阅模式,允许客户端订阅服务器上的数据变化。 4. OPC UA信息模型 OPC UA的信息模型非常灵活,可以定义任何类型的数据和设备。它包括对象模型、变量模型、方法模型等,可以清晰地表达数据的结构和类型。通过信息模型,客户端可以查询服务器上的节点信息,并对数据节点进行读写操作。 5. 开发人员如何使用源码 对于编程新手来说,通过阅读和修改这些示例源码,可以快速理解OPC UA的基本概念和编程模式。对于有一定经验的开发人员,可以深入研究源码中的高级功能实现,如安全机制和信息模型的定义,以及如何构建可扩展的OPC UA应用程序。 6. SIEMENS公司与OPC基金会的角色 SIEMENS作为工业自动化领域的知名企业,其参与编写OPC UA源码,体现了对标准的支持和行业领导地位。而OPC基金会则是一个开放的国际组织,旨在推动OPC技术的发展和应用。 7. 程序源代码的品质保证 程序老媛出品的资源,经过作者的亲测校正,保证了源码的质量。这对需要在实际项目中应用OPC UA技术的开发者来说,是一个重要的质量保证。 8. 程序源代码的适用人群 本源码适合不同层次的开发人员使用。新手可以通过学习源码来快速上手OPC UA开发,而有经验的开发者可以利用这些示例进一步开发复杂的工业通讯解决方案。 总之,OPC UA官方服务器与客户端程序的源码是学习和开发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.