目录
一、libiec61850库下载编译
1.1 下载
1.2 linux编译:
1.3 win编译
二、案例编译测试
2.1 CMakeLists.txt调整(server_example_goose)
2.2 模型static_model.h/static_model.cpp生成
2.3 案例编译(server_goose)
2.4 客户端编译
2.5 运行测试
一、libiec61850库下载编译
1.1 下载
git clone https://gitee.com/openyunxingtianxia/libiec61850.git
注:官网(libIEC61850 / lib60870 | open source libraries for IEC 61850 and IEC 60870-5-101/104),最新版本是1.5.1
1.2 linux编译:
编译前准备
#!/bin/bash
#pcap库
yum install libpcap-devel
#openssl库
yum install openssl-devel
#gcc-c++
yum install gcc gcc-c++#cmake安装
mkdir cmake_new_version
cd cmake_new_version
#cmake 源码ftp网站https://cmake.org/files/ 下载需要的版本
wget https://cmake.org/files/v3.24/cmake-3.24.2.tar.gz
tar -zxvf cmake-3.24.2.tar.gz
cd cmake-3.24.2
#apt-get install libssl-dev #OPENSSL依赖 或./configure -DCMAKE_USE_OPENSSL=OFF
./configure
make -j4
#root 用户下
make install
update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force
cmake -version
libiec61850编译
#!/bin/bash
#libiec61850编译,进入目录libiec61850-master
cd libiec61850-master
mkdir build_linux
cd build_linuxcmake ..
gmake -j4
make install
#默认安装路径 头文件
#/usr/local/include/libiec61850
#默认安装路径 库文件
#/usr/local/lib
libiec61850的动态库加入环境变量:
vi /etc/profile
#在文末追加
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib64
#保存退出 :wq
#使配置生效
source /etc/profile
1.3 win编译
本文采用cmake+vs2013编译,预先安装cmake和vs2013
#进入目录libiec61850-master,例如本文路径D:\workForOrgCode\IEC61850\libiec61850-master
mkdir build_vc
cd build_vccmake .. -G "Visual Studio 12 2013"cmake --build . --config release
#或
cmake --build . --config debug
二、案例编译测试
通常,源码编译时就已经自动编译了各个案例文件,一般就在我们刚刚编译的目录下:
libiec61850-master\build_linux\examples和\libiec61850-master\build_vc2013\examples
为了理解编译好的头文件和库文件如何调用,我们尝试自行手动配置和编译一下。
server_example_goose 和 server_example_goose为例
2.1 CMakeLists.txt调整(server_example_goose)
修改CMakeLists.txt工程信息:
#进入libiec61850-master\examples\server_example_goose目录
mkdir build_linux
mkdir build_vc
#修改CMakeLists.txt文件,为了更好理解引用路径,本文给出了全路径设置include_directories(.
)set(server_example_goose_SRCSserver_example_goose.cstatic_model.c
)IF(WIN32)
set_source_files_properties(${server_example_goose_SRCS}PROPERTIES LANGUAGE CXX)include_directories("D:\\workForOrgCode\\IEC61850\\libiec61850-master\\src\\mms\\inc""D:\\workForOrgCode\\IEC61850\\libiec61850-master\\src\\common\\inc" "D:\\workForOrgCode\\IEC61850\\libiec61850-master\\src\\goose" "D:\\workForOrgCode\\IEC61850\\libiec61850-master\\src\\hal\\inc" "D:\\workForOrgCode\\IEC61850\\libiec61850-master\\third_party\\winpcap\\Include" "D:\\workForOrgCode\\IEC61850\\libiec61850-master\\src\\iec61850\\inc""D:\\workForOrgCode\\IEC61850\\libiec61850-master\\src\\logging"
)set(iec61850_LIBDIR "D:\\workForOrgCode\\IEC61850\\libiec61850-master\\build_vs2013\\src")link_directories(${iec61850_LIBDIR}"D:\\workForOrgCode\\IEC61850\\libiec61850-master\\third_party\\winpcap\\Lib"
)add_executable(server_example_goose${server_example_goose_SRCS}
)target_link_libraries(server_example_goose"D:\\workForOrgCode\\IEC61850\\libiec61850-master\\build_vc2013\\src\\Release\\iec61850.lib" wpcap
)
ELSE(WIN32)
include_directories(/usr/local/include/libiec61850
)add_executable(server_example_goose${server_example_goose_SRCS}
)target_link_libraries(server_example_gooseiec61850-lpthread
)
ENDIF(WIN32)
2.2 模型static_model.h/static_model.cpp生成
这个案例是SCL模型是通过simpleIO_direct_control_goose.icd文件生成的,用于生产的工具在“D:\workForOrgCode\IEC61850\libiec61850-master\tools\model_generator”路径下,这个生产工具需要jdk支持,最好安装1.8以上的版本
#进入该案例目录下
java -jar D:/workForOrgCode/IEC61850/libiec61850-master/tools/model_generator/genmodel.jar simpleIO_direct_control_goose.icd
2.3 案例编译(server_goose)
win编译:
cd build_vc
cmake .. -G "Visual Studio 12 2013"
cmake --build . --config debug
Linux编译:
cd build_linux
cmake ..
make -j4
2.4 客户端编译
进入\libiec61850-master\examples\iec61850_client_example2
修改CMakeLists.txt文件,大致如下
cmake_minimum_required(VERSION 2.8)project(iec61850_client2)set(iec61850_client_example2_SRCSclient_example2.c
)IF(WIN32)
set_source_files_properties(${iec61850_client_example2_SRCS}PROPERTIES LANGUAGE CXX)
ENDIF(WIN32)IF(WIN32)include_directories("D:\\workForOrgCode\\IEC61850\\libiec61850-master\\src\\mms\\inc""D:\\workForOrgCode\\IEC61850\\libiec61850-master\\src\\common\\inc" "D:\\workForOrgCode\\IEC61850\\libiec61850-master\\src\\goose" "D:\\workForOrgCode\\IEC61850\\libiec61850-master\\src\\hal\\inc" "D:\\workForOrgCode\\IEC61850\\libiec61850-master\\src\\iec61850\\inc""D:\\workForOrgCode\\IEC61850\\libiec61850-master\\src\\logging""D:\\workForOrgCode\\IEC61850\\libiec61850-master\\third_party\\winpcap\\Include"
)link_directories(# "D:\\workForOrgCode\\IEC61850\\libiec61850-master\\build_vs2013\\src""D:\\workForOrgCode\\IEC61850\\libiec61850-master\\third_party\\winpcap\\Lib"
)add_executable(iec61850_client_example2${iec61850_client_example2_SRCS}
)target_link_libraries(iec61850_client_example2"D:\\workForOrgCode\\IEC61850\\libiec61850-master\\build_vc2013\\src\\Release\\iec61850.lib"wpcap
)ELSE(WIN32)include_directories(/usr/local/include/libiec61850
)add_executable(iec61850_client_example2${iec61850_client_example2_SRCS}
)target_link_libraries(iec61850_client_example2iec61850-lpthread
)ENDIF(WIN32)
win编译:
mkdir build_vc
cd build_vc
cmake .. -G "Visual Studio 12 2013"
cmake --build . --config debug
Linux编译:
mkdir build_linux
cd build_linux
cmake ..
make -j4
2.5 运行测试
在linux启动\libiec61850-master\examples\server_example_goose服务端
cd server_example_goose/build_linux
#指定网口启动
./server_example_goose "ens33"
在win启动\libiec61850-master\examples\iec61850_client_example2客户端,该客户端读取服务端的SCL模型信息并打印输出显式
#将前面编译好的库文件iec61850.dll拷贝
#例如\libiec61850-master\build_vc2013\src\Debug目录下,拷贝到
#\libiec61850-master\examples\iec61850_client_example2\build_vc\debug目录下
#然后进入\libiec61850-master\examples\iec61850_client_example2\build_vc\debug目录,
#启动程序
iec61850_client_example2.exe 192.168.157.152 102
另外也可以采用IEDScout客户端测试工具测试,打开IEDScout工具,进入配置界面,新建一个服务链接:
可以点击advanced按钮,有更多细节参数设置
然后尽心服务搜索及链接
最终展示效果如下:
其他案例类似