forte是基于c++的第三方开源IEC 61499运行环境,默认可以不启用opcua,如果要启用opcua则需要在编译时指定opcua的参数。
1.OPCUA
1.在编译opcua时,即open62541, 需要定义 UA_ENABLE_AMALGAMATION=ON
2.cmake forte时,需要FORTE_COM_OPC_UA=ON,以及指定62541的include 和lib的位置
Linux
- Download the FORTE source from http://git.eclipse.org/c/4diac/org.eclipse.4diac.forte.git:
$ mkdir ~/4diac && cd "$_"
$ git clone -b develop https://git.eclipse.org/r/4diac/org.eclipse.4diac.forte forte
$ cd forte && mkdir build
- Download the source for open62541 from https://github.com/open62541/open62541:
- 这里用的open62541 是v1.0 , 更新一些的版本在编译Forte时会报错。如下所示:
$ cd ~/4diac
$ git clone https://github.com/open62541/open62541.git --branch=v1.0 open62541
- Build open62541. If you are running the code on production devices we suggest setting the build type to Release.
$ cd ~/4diac/open62541 && mkdir build && cd $_
$ cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Debug -DUA_ENABLE_AMALGAMATION=ON ..
$ make -j#cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DUA_ENABLE_AMALGAMATION=ON ..
- Set FORTE to include open62541. If you are running the code on production devices we suggesst setting the build type to Release.
$ cd ~/4diac/forte/build
$ cmake -DCMAKE_BUILD_TYPE=Debug \
-DFORTE_ARCHITECTURE=Posix \
-DFORTE_MODULE_CONVERT=ON \
-DFORTE_COM_ETH=ON \
-DFORTE_MODULE_IEC61131=ON \
-DFORTE_COM_OPC_UA=ON \
-DFORTE_COM_OPC_UA_INCLUDE_DIR=$HOME/4diac/open62541/build \
-DFORTE_COM_OPC_UA_LIB_DIR=$HOME/4diac/open62541/build/bin \
-DFORTE_COM_OPC_UA_LIB=libopen62541.so \
..
$ make -j
二、MQTT
Eclipse 4diac Documentationhttps://www.eclipse.org/4diac/en_help.php?helppage=html/communication/mqttPaho.html
源码用的是github上的源码:
GitHub - eclipse/paho.mqtt.c: An Eclipse Paho C client library for MQTT for Windows, Linux and MacOS. API documentation: https://eclipse.github.io/paho.mqtt.c/An Eclipse Paho C client library for MQTT for Windows, Linux and MacOS. API documentation: https://eclipse.github.io/paho.mqtt.c/ - GitHub - eclipse/paho.mqtt.c: An Eclipse Paho C client library for MQTT for Windows, Linux and MacOS. API documentation: https://eclipse.github.io/paho.mqtt.c/https://github.com/eclipse/paho.mqtt.c
ince you need MQTT Paho, you need to install the libraries in your computer. Therefore you need to download the code and compile it. You will need the same tools needed for FORTE (git, cmake, compilers). The process is based on the normal compilation of FORTE, but the MQTT feature is enabled. Here's a quick link to FORTE's compilation. For the installation please follow the next steps:
- Checkout and build MQTT Paho (if you are using Windows, some commands might change):
$ git clone https://github.com/eclipse/paho.mqtt.c.git $ cd paho.mqtt.c
-
Use CMake to generate the files to compile in a similar way you would use for compiling FORTE. The options in CMake for Paho are less and easy to understand. You will export the files to [binPaho]. Then do
$ cd [binPaho] $ make
- Configure FORTE compilation files by starting CMake as you usually and follow the next steps:
- Check FORTE_COM_PAHOMQTT in CMake
- Set FORTE_COM_PAHOMQTT_INCLUDE_DIR in CMake to the folder where the header files of Paho are.
- Verify that the library specified in FORTE_COM_PAHOMQTT_LIB has the same name as the one you compiled. If not, change it.
- Set FORTE_COM_PAHOMQTT_LIB_DIR to the folder where FORTE_COM_PAHOMQTT_LIB is located.
- Configure CMake until nothing is marked red afterwards generate with CMake.
- Build forte
mkdir build && cd build
cmake -DPAHO_BUILD_STATIC ..
make -j
make install
mqtt就安装到 /usr/local/lib目录下了
三、MODBUS
modbus用的是 https://libmodbus.org/ 官方的源码
具体方法参考:
Eclipse 4diac Documentationhttps://www.eclipse.org/4diac/en_help.php?helppage=html/communication/modbus.html
The Modbus com interface need the libmodbus library to work. Follow the steps below to set up your environment before compiling FORTE.
- libmodbus files should be placed in the following folder structure:
- [ibmodbushome]/include/modbus: include files
- [libmodbushome]/lib: libmodbus.lib (windows) or libmodbus.so (posix)
- When configuring FORTE project with CMake choose [ibmodbushome] as FORTE_COM_MODBUS_LIB_DIR
- forte.exe must be able to find the dynamic libmodbus library after build. Therefore copy libmodbus.dll/so to folder with forte.exe or add libmodbus.dll/so to library include path.
./configure
make -j
make install
modbus就安装到 /usr/local/lib目录下了
编译forte时定义 FORTE_COM_MODBUS_LIB_DIR 为 /usr/local即可。
四、opcua modbus mqtt 都加上
cd forte
mkdir build && cd build
用以下命令运行cmake命令。注意modbus的与一般的默认目录有所区别
cmake -DCMAKE_BUILD_TYPE=Debug \
-DFORTE_ARCHITECTURE=Posix \
-DFORTE_MODULE_CONVERT=ON \
-DFORTE_COM_ETH=ON \
-DFORTE_MODULE_IEC61131=ON \
-DFORTE_COM_OPC_UA=ON \
-DFORTE_COM_OPC_UA_INCLUDE_DIR=$HOME/work/61499/open62541/build \
-DFORTE_COM_OPC_UA_LIB_DIR=$HOME/work/61499/open62541/build/bin \
-DFORTE_COM_OPC_UA_LIB=libopen62541.so \
-DFORTE_COM_MODBUS=ON \
-DFORTE_COM_MODBUS_INCLUDE_DIR=/usr/local/include \
-DFORTE_COM_MODBUS_LIB_DIR=/usr/local \
-DFORTE_COM_PAHOMQTT=ON \
-DFORTE_COM_PAHOMQTT_LIB_DIR=/usr/local/lib \
-DFORTE_COM_PAHOMQTT_INCLUDE_DIR=/usr/local/include \
..
modbus的目录非常特别是因为forte这CMake脚本写的有点。。。
root@ubuntu-star5:~/work/61499/forte_2.0.1/build# grep -nr MODBUS_ ../src
../src/com/modbus/readme.txt:7:2. When configuring forte project with CMake choose <libmodbushome> as FORTE_COM_MODBUS_LIB_DIR
../src/com/modbus/CMakeLists.txt:16:SET(FORTE_COM_MODBUS_LIB_DIR "" CACHE PATH "Path to Modbus library directory (leave empty for installed source code)")
../src/com/modbus/CMakeLists.txt:27: forte_add_include_directories( ${FORTE_COM_MODBUS_LIB_DIR}/include )
../src/com/modbus/CMakeLists.txt:29: if(EXISTS ${FORTE_COM_MODBUS_LIB_DIR})
../src/com/modbus/CMakeLists.txt:30: forte_add_include_directories( ${FORTE_COM_MODBUS_LIB_DIR}/include/modbus )
../src/com/modbus/CMakeLists.txt:31: forte_add_link_directories( ${FORTE_COM_MODBUS_LIB_DIR}/lib )
../src/com/modbus/CMakeLists.txt:32: else(EXISTS ${FORTE_COM_MODBUS_LIB_DIR})
../src/com/modbus/CMakeLists.txt:34: endif(EXISTS ${FORTE_COM_MODBUS_LIB_DIR})
../src/com/modbus/CMakeLists.txt:37: forte_add_include_directories( ${FORTE_COM_MODBUS_LIB_DIR}/include )
../src/com/modbus/CMakeLists.txt:38: forte_add_link_directories( ${FORTE_COM_MODBUS_LIB_DIR}/lib )
参考:
OPC UA with IEC 61499 Tutorial (from v 1.11.0)