channel-opc-ua

介绍

通道服务名:channel-opc-ua
工程名称:fox-edge-server-channel-opc-ua
说明:opc-ua通道服务器,作为OPC-UA的客户端,跟OPC-UA的服务端进行通信的场景。
OPC-UA是OPC基金会为脱离OPC对Windows的依赖而改进的技术,使得它能够在Linux上进行技术实现。
有些设备是基于OPC-UA实现了服务端的特性,可以使用OPC-UA进行访问。


针对这个业务场景,灵狐开发了opc-ua这种通道服务,来支持该场景。

组网

源码

源码

操作方法

该服务的操作方法,只有半双工的exchange两种模式。

1、通道配置

opc-ua通道配置,要进行证书配置,那么fox-edge和opc-ua服务器之间进行认证登录。

endpointUrl:是opc-ua服务端提供的连接串信息。

创建一个opc-ua的通道后,在通道中配置连接参数


{
     "appUri": "urn:fox-edge:UnifiedAutomation:UaExpert@fox-edge",
     "appName": "fox-edge-OpcUaClient",
     "certificate": {
          "file": "fox-edge-client.pfx",
          "path": "",
          "alias": "fox-edge-ai",
          "dnsName": "fox-edge",
          "ipAddress": "192.168.1.9",
          "stateName": "GuangDong",
          "commonName": "UaClient@fox-edge",
          "countryCode": "CN",
          "localityName": "fox-edge",
          "organization": "fox-edge",
          "keystorePassword": "123456",
          "organizationUnit": "per"
     },
     "endpointUrl": "opc.tcp://USER-20221006EY:53530/OPCUA/SimulationServer",
     "idpPassword": "",
     "idpUsername": "fox-edge"
}

注意事项:服务端提供的endpointUrl如果是包含主机名称的时候,要确保能够ping通该主机名称。 在windows环境下,操作系统是默认开启局域网ip和hostname的发现关系的,所以不需要进行相应的操作系统配置,即可通过opc-ua跟对方windows主机进行通信。 但是在linux环境下,是没有开启局域网的ip和hostname的发现的,需要手动去/etc/hosts手动添加该ip和hostname,fox-edge才能对windows服务端进行正常访问。

在Linux下编辑/etc/hosts文件,配置IP和hostname的映射关系,保存配置后,可以ping通hostname了,fox-edge在linux下,也马上就可与windows的模拟器通信了

2、启动模拟器

prosys opc ua是一个非常易用的windows下的opc-ua模拟器,可以方便进行测试。

可以看到,它提供了一个连接串,而且它的连接传是一个主机名而不是IP,它是以主机名hostname的方式进行提供服务的。

fox-edge部署在Linxu的时候,就涉及到IP-hostname之间的配置,如何配置,参考上一段说明。

3、通道操作任务

创建一个通道操作任务,进行跟opc-ua模拟器的连接测试,可以发现通信上了,并读取到了数据

4、配置范例

1、通道配置


{
     "appUri": "urn:fox-edge:UnifiedAutomation:UaExpert@fox-edge",
     "appName": "fox-edge-OpcUaClient",
     "certificate": {
          "file": "fox-edge-client.pfx",
          "path": "",
          "alias": "fox-edge-ai",
          "dnsName": "fox-edge",
          "ipAddress": "192.168.1.9",
          "stateName": "GuangDong",
          "commonName": "UaClient@fox-edge",
          "countryCode": "CN",
          "localityName": "fox-edge",
          "organization": "fox-edge",
          "keystorePassword": "123456",
          "organizationUnit": "per"
     },
     "endpointUrl": "opc.tcp://USER-20221006EY:53530/OPCUA/SimulationServer",
     "idpPassword": "",
     "idpUsername": "fox-edge"
}

2、通道操作任务配置范例

发送报文


{
     "nodeId": {
          "namespace": 3,
          "identifier": "85/0:Simulation"
     },
     "operate": "browseChildValue"
}

返回报文


{
     "type": "opc-ua",
     "uuid": "12e89eb0-eb90-4a70-a0cb-84c05b864d07",
     "name": "channel-opc-ua-2",
     "mode": "exchange",
     "send": {
          "nodeId": {
               "namespace": 3,
               "identifier": "85/0:Simulation"
          },
          "operate": "browseChildValue"
     },
     "recv": {
          "name": "",
          "nodeId": {
               "namespace": 3,
               "identifier": "85/0:Simulation"
          },
          "value": null,
          "children": [
               {
                    "name": "Counter",
                    "nodeId": {
                         "namespace": 3,
                         "identifier": "Counter"
                    },
                    "value": 30,
                    "children": []
               },
               {
                    "name": "Expression",
                    "nodeId": {
                         "namespace": 3,
                         "identifier": "Expression"
                    },
                    "value": 0.8109561618781576,
                    "children": []
               },
               {
                    "name": "Random",
                    "nodeId": {
                         "namespace": 3,
                         "identifier": "Random"
                    },
                    "value": -1.642301582707593,
                    "children": []
               },
               {
                    "name": "Sawtooth",
                    "nodeId": {
                         "namespace": 3,
                         "identifier": "Sawtooth"
                    },
                    "value": 0.7999999523162842,
                    "children": []
               },
               {
                    "name": "Sinusoid",
                    "nodeId": {
                         "namespace": 3,
                         "identifier": "Sinusoid"
                    },
                    "value": -1.9890437904381266,
                    "children": []
               },
               {
                    "name": "Square",
                    "nodeId": {
                         "namespace": 3,
                         "identifier": "Square"
                    },
                    "value": -2,
                    "children": []
               },
               {
                    "name": "Triangle",
                    "nodeId": {
                         "namespace": 3,
                         "identifier": "Triangle"
                    },
                    "value": -1.8666666648491703,
                    "children": []
               }
          ]
     },
     "timeout": 5000,
     "route": "topic_channel_respond_manager",
     "msg": "",
     "code": 200
}

发送报文


{
     "nodeId": {
          "namespace": 3,
          "identifier": "85/0:Simulation"
     },
     "operate": "browseChild"
}

返回报文


{
     "type": "opc-ua",
     "uuid": "ee22a215-616d-41b2-8c04-7dfdfc2cffe8",
     "name": "channel-opc-ua-2",
     "mode": "exchange",
     "send": {
          "nodeId": {
               "namespace": 3,
               "identifier": "85/0:Simulation"
          },
          "operate": "browseChild"
     },
     "recv": {
          "name": "",
          "nodeId": {
               "namespace": 3,
               "identifier": "85/0:Simulation"
          },
          "value": null,
          "children": [
               {
                    "name": "Counter",
                    "nodeId": {
                         "namespace": 3,
                         "identifier": "Counter"
                    },
                    "value": null,
                    "children": []
               },
               {
                    "name": "Expression",
                    "nodeId": {
                         "namespace": 3,
                         "identifier": "Expression"
                    },
                    "value": null,
                    "children": []
               },
               {
                    "name": "Random",
                    "nodeId": {
                         "namespace": 3,
                         "identifier": "Random"
                    },
                    "value": null,
                    "children": []
               },
               {
                    "name": "Sawtooth",
                    "nodeId": {
                         "namespace": 3,
                         "identifier": "Sawtooth"
                    },
                    "value": null,
                    "children": []
               },
               {
                    "name": "Sinusoid",
                    "nodeId": {
                         "namespace": 3,
                         "identifier": "Sinusoid"
                    },
                    "value": null,
                    "children": []
               },
               {
                    "name": "Square",
                    "nodeId": {
                         "namespace": 3,
                         "identifier": "Square"
                    },
                    "value": null,
                    "children": []
               },
               {
                    "name": "Triangle",
                    "nodeId": {
                         "namespace": 3,
                         "identifier": "Triangle"
                    },
                    "value": null,
                    "children": []
               }
          ]
     },
     "timeout": 5000,
     "route": "topic_channel_respond_manager",
     "msg": "",
     "code": 200
}