【OPC UA】基于OpcUaFx的OPC客户端读写KEPServerEx6服务器节点

一、OPC UA 与 UAFX

3738eeac3e0c7667c30364763aeef339.png

OPC UA and UAFX System Architecture

5cc8c6c2769d04553dcaec4b8472fa94.png通过OPC UA (a)和UAFX (b)实现水平和垂直通信的统一,以及迁移到一个连续的、收敛的网络(c),从现场到云端,反之亦然

    2021 年 12 月 8 日 – OPC基金会现场层通信(FLC)倡议成立三年之际,完成了OPC UA FX(现场交换)规范集的第二个候选版本(RC2),并开始了审核与发布程序。此外,由20家世界大型自动化供应商,利用各自的控制器和网络基础设施组件构成的供应商Demo也成功展示。此次Demo展示了在工厂和过程自动化中,自动化组件多样化用例的跨供应商互操作性。

第一个OPC UA FX多供应商演示

ecc3f4e18f8b9f2df2aeb96ccdbbbc68.png

第一个OPC UA FX多供应商演示的原理结构

2021年11月,第一个多供应商互操作性演示实现了,其中自动化和网络组件结合在一起,演示了通过OPC UA和OPC UA FX扩展的跨供应商数据交换。为此,来自不同供应商(包括世界上最大的自动化制造商)的17个控制器(包括PLC、运动和机器人控制器以及分布式控制系统)通过公共网络基础设施相互连接。

该基础设施由传统的以太网交换机、以太网TSN(时间敏感网络)交换机和毫米波频率范围的5G试验台组成。

演示器的所有控制器通过集成的OPC UA服务器提供当前状态和资产信息,通过中央仪表板进行查询和可视化。“所有控制器”视图显示多供应商演示中所有17个控制器的OPC UA连接状态,以及由每个UAFX控制器原型配置的基于pubsub的UAFX连接的状态信息。仪表板本身是交互式的,当单击17个控制器中的一个时,切换到“资产视图”,其中显示控制器建模和公开的UAFX资产信息。

为了演示UAFX扩展的可能性和优势,在演示机上模拟了一个模块化装瓶线,其中4个用于清洗、灌装、旋盖和贴标的机器单元组合成一条生产线。为了演示跨供应商互操作性,每个单元都配备了来自不同制造商的控制系统。

通信连接的配置和通过这些连接交换的过程数据来实现一个正常工作的生产线是通过一个UAFX连接管理器来实现的,如上所述。在演示中,使用了基于UA Expert的统一自动化(Unified Automation)的独立(外部)连接管理器和集成到西门子SIMATIC PLC中的连接管理器,每个都有自己的图形用户界面。连接管理器充当OPC UA客户端,并使用集成在UAFX控制器原型中的OPC UA服务器来配置各自控制器之间的UAFX连接。

然后通过这些UAFX连接使用OPC UA Pub/Sub交换相应的流程数据。控制器作为UAFX发布者和/或UAFX订阅者取决于他们在配置的生产线中的角色和位置。流程数据可以是实时数据,也可以是用于故障安全操作的安全数据。配置的生产线可以在仪表板中可视化和监视。

二、基于OPC UAFX的读写客户端

3cd24e8af1e8dbb7ddd34a5a80310c83.png读取节点客户端

8782a1179c7aaa8e51ce2bb74ae085df.png写入节点数据客户端

视频演示

读取节点客户端部分代码:

public void UpdateTags_M1(OpcClient client, ref string strM1Name, ref double dM1Position, ref int nM1Mode, ref bool bM1Status, ref double dM1Temp)
        {
            //Motor1             
            string strTagName = "ns=2;s=Devices.OPCUAReadData.Motor1.Name";
            Opc.UaFx.OpcValue opcM1Name = client.ReadNode(strTagName);
            strM1Name = (string)opcM1Name.Value;


            strTagName = "ns=2;s=Devices.OPCUAReadData.Motor1.Position";
            Opc.UaFx.OpcValue opcM1Pos = client.ReadNode(strTagName);
            dM1Position = opcM1Pos.Value==null?double.NaN:(double)opcM1Pos.Value;


            strTagName = "ns=2;s=Devices.OPCUAReadData.Motor1.Mode";
            Opc.UaFx.OpcValue opcM1Mode = client.ReadNode(strTagName);
            nM1Mode = opcM1Mode.Value==null?int.MinValue:(int)opcM1Mode.Value;


            strTagName = "ns=2;s=Devices.OPCUAReadData.Motor1.Status";
            Opc.UaFx.OpcValue opcM1Stt = client.ReadNode(strTagName);
            bM1Status = opcM1Stt.Value==null?false:(bool)opcM1Stt.Value;


            strTagName = "ns=2;s=Devices.OPCUAReadData.Motor1.Temperature";
            Opc.UaFx.OpcValue opcM1Temp = client.ReadNode(strTagName);
            dM1Temp = opcM1Temp.Value==null?double.NaN:(double)opcM1Temp.Value;            
        }

写入节点客户端部分代码:

public void WriteTags_M1(OpcClient client, ref string strM1Name, ref string strM1Position, ref string strM1Mode, ref string strM1Status, ref string strM1Temp)
        {
            //Motor1
            string strTagName = "ns=2;s=Devices.OPCUAReadData.Motor1.Name";
            string strName = strM1Name;
            client.WriteNode(strTagName, strName);


            strTagName = "ns=2;s=Devices.OPCUAReadData.Motor1.Position";
            double dPos = Convert.ToDouble(strM1Position);
            client.WriteNode(strTagName, dPos);


            strTagName = "ns=2;s=Devices.OPCUAReadData.Motor1.Status";
            bool bStt = Convert.ToBoolean(strM1Status);
            client.WriteNode(strTagName, bStt);


            strTagName = "ns=2;s=Devices.OPCUAReadData.Motor1.Mode";
            int nMode = Convert.ToInt32(strM1Mode);
            client.WriteNode(strTagName, nMode);


            strTagName = "ns=2;s=Devices.OPCUAReadData.Motor1.Temperature";
            double dTemp = Convert.ToDouble(strM1Temp);
            client.WriteNode(strTagName, dTemp);
        }

参考:

https://www.opcfoundation.cn/news/opc-foundation-china-news/47

https://www.tttech-industrial.com/resource-library/blog-posts/opc-ua-fx/

https://www.process-informatik.de/ftp/pub/handbook/en_opc-ua-framework-advanced.pdf

https://iebmedia.com/technology/edge-cloud/opc-ua-fx-for-the-field-level-and-multi-vendor-demo/

The End

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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值