opcua_server是使用python写的开源OPC UA服务器软件,我们用它来部署一个OPC UA服务器。
部署环境采用Linux虚拟机,安装系统为Ubuntu20.04
克隆存储库
git clone https://github.com/latosai/ocpua_server.git
准备虚拟环境
sudo apt install python3-venv
python3 -m venv venv
source venv/bin/activate
安装依赖包
cd ocpua_server
pip install -r requirements.txt
错误解决
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
pip --default-timeout=500 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
运行服务
cd code
python3 server.py
使用UaExpert验证
UaExpert的使用方法参考我的另一篇博客:UaExpert安装使用指南
- 查看终端URL
在server.py的208左右,有如下代码
server.set_endpoint('opc.tcp://0.0.0.0:4840/freeopcua/server/')
将opc.tcp://0.0.0.0:4840/freeopcua/server/
中的0.0.0.0
换成虚拟机的IP地址。
比如我的替换后为:opc.tcp://192.168.13.62:4840/freeopcua/server/
- 使用上一步得到的连接地址,使用UaExpert打开。
看到成功连接上OPC UA服务器。
结语
以上就是OPC UA服务器的搭建,后续可以通过修改server.py代码来修改服务器的功能。