通讯网关软件019——利用CommGate X2OPCUA实现OPC UA访问Oracle服务器

本文介绍利用CommGate X2OPCUA实现OPC UA访问ORACLE数据库。CommGate X2OPCUA是宁波科安网信开发的网关软件,软件可以登录到网信智汇(http://wangxinzhihui.com)下载。

【案例】如下图所示,实现上位机通过OPC UA来获取ORACLE数据库的数据。

【解决方案】设置网关机,与ORACLE服务器采用以太网通讯,与OPC UA Client采用以太网通讯,安装CommGate X2OPCUA软件。

1. ORACLE数据表结构要求:

  • 至少要求具备ID、name、value三个字段。
  • name:标签名称,字符类型
  • value:数值,可以是字符类型或浮点类型
  • state:不是必须的,整型类型,1表示好值 0表示坏值
  • time:不是必须,可以是datetime或bigint
  • 以上字段名称如不是name、value、state、time,需要在以下配置文件进行字段名称的配置

2. ORACLE通讯调试:在网关机上运行ORACLE调试工具,与ORACLE服务器通讯调试。通讯正常后,记下通讯参数。

3. 配置X2OPCUA 出口端参数:在X2OPCUA安装目录Ini下编辑X2OPCUA.ini,修改出口端参数。

[OUT]
;输入源类型:OPCUA Server,不做修改
Type = OPCUA_SERVER
;应用名称
AppName = keanwin.Mb2OpcUaServer
;应用端口
Port = 4900
;身份验证模式(1:匿名用户  2:用户密码 3: 匿名用户 或 用户密码)
AuthMode = 1
;采用用户密码认证时,UserName不能为空
UserName =
;采用用户密码认证时,Password不能为空
Password = 
;安全策略,4个bit决定(b4 b3 b2 b1) b1: Unencrypted b2: Basic128  b3: Basic256  b4:Basic256Sha256
SecurityMode = 15
;证书文件,放在安装目录Cert子目录下
;客户提供机器名,由供应商提供该证书
CertFile = Server_Cert.der
; 私钥文件,放在安装目录Cert子目录下
;客户提供机器名,由供应商提供该证书
KeyFile = Server_Key.der
;信任客户端证书个数
Trusts = 2
;信任客户端证书
;将信任客户端证书拷贝到安装目录下Trusted子目录下
Trust1 = uaexpert.der
Trust2 = uaexpert1.der
[IN]
;输入端配置文件名,不含后缀
INI = Oracle
Type =

4. 配置X2OPCUA 入口端参数:在X2OPCUA安装目录Ini下编辑Oracle.ini,按照刚才记下的通讯参数修改入口端参数。

[IN]
;输入源类型:ORACLE,不做修改
Type = ORACLE
;Oralce Server IP
ServerIP = 127.0.0.1
; Oralce用户
UserName=sa
;用户密码
Pwd=123456
;数据库名称
DB=test
;Port 0表示采用默认端口
port = 0
;连接串,定义连接串,以连接串信息为准,以上用户密码等信息配置忽略
ConnectStr=Provider=OraOLEDB.Oracle;Persist Security Info=False;User ID=sa;Password=123456;Initial Catalog=test;Data Source=127.0.0.1
;读取数据的SQL语句,如果不设置的话,将由以下字段名自动构造
;表中至少包含name,value字段
;state字段不是必须的,没有state字段时,必须构造1个虚拟state字段,如select name, value, 1 as state from snapshot
;State值 = 1 好值  =0 坏值
ReadSQL=select name, value, state, time from snapshot
;定义Name字段名,默认为name
NameField = name
;定义Value字段名,默认为value
ValueField = value
;定义State字段名,默认为state
StateField = state
;定义Time字段名,可以不定义,默认为空,表示没有Time字段
TimeField = time

5. 标签配置:在X2OPCUA安装目录下编辑X2OPCUA.xls,配置标签。

6. 运行X2OPCUA.exe,启动网关。

7. 用OPCUA Client连接X2OPCUA,服务器和客户端双方的证书相互信任后才可以连接正常,具体参看附带的OPC UA配置手册。连接正常后确认数据是否正确。

8. 详细配置说明见《X2OPCUA V4使用手册》。

更多通信资源请登录网信智汇(http://wangxinzhihui.com)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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、付费专栏及课程。

余额充值