【CSEN024】python-opcua client usage

@JIANG Kang

python-opcua client usage

python-opcua is an open source pure python library for OPC UA communication. It implements client/server communication method of OPC UA standard and include many features of the standards(security, address space, information model, DA, HA, A&E, invoking method, etc.). Its official webpage url is https://github.com/FreeOpcUa/python-opcua. As of this writing this library is deprecated.

In this article we will illustrate how to read/write data and invoke method from Elite CS series robot through OPC UA communication by using the client library.

Preparation

Connect PC to robot controller at port 'FB1'.

Robot side:

1.       Make sure system version is 2.30 or above.

2.       Install OPC UA plugin.

3.       Start OPC UA service.

PC side:

1.       Make sure openssl library version is 1.1.1g or above

2.       Install python-opcua library. Please refer to its webpage for installation steps.https://github.com/FreeOpcUa/python-opcua#installation

Configure and run program

1.       Download the attached python client program. 📎client-minimal.py

2.       Open a terminal and issue the following commands to generate X509 certificate and private key

elite@ubuntu:~$ openssl req -x509 -newkey rsa:2048 -keyout my_private_key.pem -out my_cert.pem -days 355 -nodes -addext "subjectAltName = URI:urn:open62541.server.application"
elite@ubuntu:~$ openssl x509 -outform der -in my_cert.pem -out my_cert.der

3.       Open the program file and modify variable settings to match the real configuration.

ip = "192.168.1.10"        # ip address of robot controller FB1 port
port = "4840"         # port for OPC UA service. No need to change
app_uri = "urn:open62541.server.application" # application uri for OPC UA server. No need to change
security_policy = "Basic256Sha256"    # security policy. No need to change
security_mode = "SignAndEncrypt"    # security mode. No need to change
cert = "my_cert.pem"       # change it to the certificate generated in previous step
p_key = "my_private_key.pem"     # change it to the private key generated in previous step
user = "elite"         # user name for authentication. No need to change
password = "elibot"        # password for authentication. No need to change

4.       Save program and execute it in terminal.

elite@ubuntu:~$ python3 client-minimal.py

Program runs and prints the result. 

Comments of the program.

·       To retrieve node by id, node's id can be found in the [Attributes] panel of 'UA Expert'.

is_power_on = client.get_node("ns=1;i=54319")

·       To trace node in the address space tree, provide the path from root node all the way to leaf node.

myvar = root.get_child(["0:Objects", "1:EliteROBOTS","6:Controller","6:ControllerOperatingInfo","6:Status","6:RobotMode"])

Each node's name can be referenced in the [Attributes] panel in 'UA Expert'.

·       The complete library API can be referenced here:https://python-opcua.readthedocs.io/en/latest/#

Known Issue

The Python client program may not be able to connect to Elite robot successfully.

If this problem occurs to you, please download the modified program file 📎client.pyand overwrite the one in your own python opc-ua library(better backup the old program first). In case of python bundled pip, it should be in the location: ~/.local/lib/python3.x/site-packages/opcua/client

The cause seems to be that server endpoint returned a different security policy value 'Aes128_Sha256_RsaOaep' instead of the specified one 'Basic256_Sha256'. Need further study by developing team.

点击显示全文
赞同0
发表评论
分享

手机扫码分享
0
387
收藏
举报
收起
登录
  • 密码登录
  • 验证码登录
还没有账号,立即注册
还没有账号,立即注册
注册
已有账号,立即登录
选择发帖板块
上传文件
举报
请选择举报理由
举报
举报说明