TL62x-EVM的OpenPLC实践(一)
参照之前的博客登录TL62x-EVM的openplc runtime的网络服务器,并参照runtime的使用说明进行初步测试。
1 OpenPLC的初步测试
上传plc程序,查看是否能正常运行。
出现编译错误:
有关源码如下:
在网上找到了有关的帖子:
https://openplc.discussion.community/post/openplc-on-ubunto-20-04-10800100
原帖的帖主遇到的问题和我类似,具体如下:
帖主在Ubuntu 20.04上安装了OpenPLC_v3,在编译程序时也会遇到错误停止,输出的日志和我一样:
……
VARIABLES.csv Config0.c Config0.h Res0.c ./core/
mv: cannot stat 'Config0.c': No such file or directory
mv: cannot stat 'Config0.h': No such file or directory
mv: cannot stat 'Res0.c': No such file or directory
遇到的问题应该也和我一样:没有成功生成Config0.c、Config0.h 和 Res0.c 。
原帖中有回复认为遇到的问题是:编写的PLC 程序缺少正确格式的resource或configuration。具体来说,是因为program中需要有一个名为 Res0 的resource和一个名为 Config0 的configuration。没有它们,程序将无法运行,而OpenPLC 编辑器会自动创建这些资源。
看起来像是原来.st文件的问题,于是我将以前利用OpenPLC editor编写的程序hello.st上传编译进行尝试(具体参见这篇博客),发现可以成功编译,如下图:
注意,还需要选择有关的硬件层,如下:
选择Save changes后,即会重新编译程序,
选择Go to Dashboard,即可start PLC
出现以下错误:
OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
PSM: Starting PSM...
Traceback (most recent call last):
File "./core/psm/main.py", line 27, in <module>
import psm
File "/OpenPLC_v3/OpenPLC_v3-master/webserver/core/psm/psm.py", line 3, in <module>
from pymodbus.server.sync import ModbusTcpServer
ModuleNotFoundError: No module named 'pymodbus'
PSM: Error while starting Python interpreter
Issued start_modbus() command to start on port: 502
Server: Listening on port 502
Server: waiting for new client...
Issued start_dnp3() command to start on port: 20000
DNP3 ID manager: Starting thread (0)
DNP3 ID DNP3_Server: Listening on: 0.0.0.0:20000
Issued start_enip() command to start on port: 44818
Server: Listening on port 44818
Server: waiting for new client...
Issued stop_pstorage() command
PSM: Connection to psm failed
PSM: Error connecting to psm!
PSM: PSM is disabled
Skipping configuration of Slave Devices (mbconfig.cfg file not found)
Warning: Persistent Storage file not found
这个错误可能是由于缺少pymodbus模块导致的,本想直接安装pymodbus,但发现连pip都没有,如下:
但发现已经安装了python,如下:
所以需要安装pip以及pymodbus。但在安装pip时,输入以下命令,遇到了相应问题:
sudo apt update
sudo apt install python3-pip
所以需要首先安装依赖apt-utils,运行如下指令:
sudo apt install apt-utils
然后再安装pip:sudo apt install python3-pip,会显示安装成功。
最后安装pymodbus,如下:
在start PLC时,又出现如下问题:
OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
PSM: Starting PSM...
Traceback (most recent call last):
File "./core/psm/main.py", line 27, in <module>
import psm
File "/OpenPLC_v3/OpenPLC_v3-master/webserver/core/psm/psm.py", line 3, in <module>
from pymodbus.server.sync import ModbusTcpServer
ModuleNotFoundError: No module named 'pymodbus.server.sync'
PSM: Error while starting Python interpreter
Issued start_modbus() command to start on port: 502
Server: Listening on port 502
Server: waiting for new client...
Issued start_dnp3() command to start on port: 20000
DNP3 ID manager: Starting thread (0)
DNP3 ID DNP3_Server: Listening on: 0.0.0.0:20000
Issued start_enip() command to start on port: 44818
Server: Listening on port 44818
Server: waiting for new client...
Issued stop_pstorage() command
PSM: Connection to psm failed
PSM: Error connecting to psm!
PSM: PSM is disabled
Skipping configuration of Slave Devices (mbconfig.cfg file not found)
Warning: Persistent Storage file not found
看起来错误是,安装了pymodbus,但没有pymodbus.server.sync这个模块。参考CSDN博客,发现可能是pymodbus的版本问题,尝试改装其他版本的pymodbus,运行如下指令:
pip3 install pymodbus==2.5.3
顺利完成。
经过检查,发现已经有了ModbusTcpServer,如下:
再在OpenPLC runtime上“start PLC”,发现成功运行,结果如下:
具体Logs如下:
然后出现了新的问题,我不知道有关的硬件和接口的映射是怎样的……
2 编译脚本
实际上只需调用OpenPLC-Webserver-scripts文件夹中的compile_program.sh文件即可,下面在TL62x上进行具体尝试。
1. 将待编译的hello.st文件复制到st_files文件夹中
2. 返回目录,调用脚本,编译成功!
3 分析错误原因
1. 将待编译的generated_plc.st文件复制到st_files文件夹中,调用编译脚本
2. 分步执行编译
修改代码