<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>润物无声 &#187; 61850</title>
	<atom:link href="http://blog.zhourunsheng.com/tag/61850/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.zhourunsheng.com</link>
	<description>天空一朵雨做的云</description>
	<lastBuildDate>Sat, 08 May 2021 05:17:21 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>libiec61850在OpenSCADA系统中的使用(二)</title>
		<link>http://blog.zhourunsheng.com/2013/08/libiec61850%e5%9c%a8openscada%e7%b3%bb%e7%bb%9f%e4%b8%ad%e7%9a%84%e4%bd%bf%e7%94%a8%e4%ba%8c/</link>
		<comments>http://blog.zhourunsheng.com/2013/08/libiec61850%e5%9c%a8openscada%e7%b3%bb%e7%bb%9f%e4%b8%ad%e7%9a%84%e4%bd%bf%e7%94%a8%e4%ba%8c/#comments</comments>
		<pubDate>Thu, 15 Aug 2013 07:36:41 +0000</pubDate>
		<dc:creator><![CDATA[润物无声]]></dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[61850]]></category>
		<category><![CDATA[OpenSCADA]]></category>

		<guid isPermaLink="false">http://blog.zhourunsheng.com/?p=1764</guid>
		<description><![CDATA[<p>上一篇文章《libiec61850在OpenSCADA系统中的使用》介绍了libiec61850和OpenSC [&#8230;]</p>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2013/08/libiec61850%e5%9c%a8openscada%e7%b3%bb%e7%bb%9f%e4%b8%ad%e7%9a%84%e4%bd%bf%e7%94%a8%e4%ba%8c/">libiec61850在OpenSCADA系统中的使用(二)</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></description>
				<content:encoded><![CDATA[<p>上一篇文章《<a href="http://blog.zhourunsheng.com/2013/08/libiec61850%E5%9C%A8openscada%E7%B3%BB%E7%BB%9F%E4%B8%AD%E7%9A%84%E4%BD%BF%E7%94%A8/" target="_blank">libiec61850在OpenSCADA系统中的使用</a>》介绍了libiec61850和OpenSCADA系统的混合编译，编译是没有问题，但是做成模块的话运行起来还是会出现问题，其中最主要的问题就是库的链接，导致运行时函数找不到，原因出在C和C++函数相互调用的关系，libiec61850是C库，OpenSCADA是C++。<span id="more-1764"></span></p>
<p>本文采用将libiec61850编译成动态库的方式供OpenSCADA系统调用，步骤如下：</p>
<h2>动态库的编译安装</h2>
<p>1. 修改libiec61850的 "lib61850\make\target_system.mk" 文件，编译选项添加fPIC</p>
<pre>CFLAGS += -g
CFLAGS += -fPIC</pre>
<p>2. 修改libiec61850 的“lib61850\Makefile”文件，添加生成动态库的参数soname</p>
<pre>$(DYN_LIB_NAME): $(LIB_OBJS)
$(CC) $(LDFLAGS) -lpthread -shared -Wl,-soname -Wl,libiec61850.so -o $(DYN_LIB_NAME) $(LIB_OBJS) $(LDLIBS)</pre>
<p>3. 编译生成动态库</p>
<pre>$ make dynlib</pre>
<p>生成 “lib61850\build\libiec61850.so”文件</p>
<p>4. 安装动态库到系统目录</p>
<pre>$ /usr/bin/install -c lib61850/build/libiec61850.so /usr/lib/i386-linux-gnu/libiec61850.so</pre>
<p>5. 修改OpenSCADA SP61850 module的 "Makefile.am" 文件，动态链接libiec61850.so</p>
<pre>#!!! The module link flags
spec_SP61850_la_LDFLAGS = -module -avoid-version -no-undefined -Llib61850/build -liec61850 $(SP61850_LDLAGS)

############ for lib61850 include header file and lib file ##################
AM_CPPFLAGS = -Ilib61850/inc -Ilib61850/src/common -Ilib61850/src/mms/iso_presentation -Ilib61850/src/mms/iso_session -Ilib61850/src/mms/iso_cotp -Ilib61850/src/mms/iso_acse -Ilib61850/src/mms/iso_mms/common -Ilib61850/src/mms/iso_mms/client -Ilib61850/src/mms/iso_mms/server -Ilib61850/src/mms/iso_client -Ilib61850/src/mms/iso_server -Ilib61850/src/mms/asn1 -Ilib61850/src/iedcommon -Ilib61850/src/iedserver/mms_mapping -Ilib61850/src/iedserver/model -Ilib61850/src/iedserver -Ilib61850/src/iedclient -Ilib61850/src/hal -Ilib61850/src/hal/thread -Ilib61850/src/hal/socket -Ilib61850/src/goose
#############################################################################</pre>
<h2>测试代码的编写</h2>
<p>1. 修改“SP61850\module.h”头文件，添加libiec6180的常用头文件</p>
<pre>/////////////////////////////////////////////////////////
extern "C"
{
#include "iec61850_server.h"
#include "iso_server.h"
#include "acse.h"
#include "thread.h"
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;

#include "static_model.h"

/* import IEC 61850 device model created from SCL-File */
extern IedModel iedModel;
}
////////////////////////////////////////////////////////

////C++类（class Lib : public TSpecial）内部添加属性
///////////////////////////////////////////////////////////

int running;
IedServer iedServer;
///////////////////////////////////////////////////////////</pre>
<p>2. 修改“SP61850\module.cpp”文件，控制服务器的启动与停止</p>
<pre>//////// 启动服务器 void Lib::modStart( )

//61850 server.
if(! running)
{
iedServer = IedServer_create(&amp;iedModel);

/* MMS server will be instructed to start listening to client connections. */
IedServer_start(iedServer, 102);

/* Instruct the server that we will be informed if a clients writes to a
* certain variables we are interested in.
*/
IedServer_observeDataAttribute(iedServer, IEDMODEL_Device1_DSCH1_NamPlt_vendor,
observerCallback);

IedServer_observeDataAttribute(iedServer, IEDMODEL_Device1_DSCH1_NamPlt_swRev,
observerCallback);

if (!IedServer_isRunning(iedServer))
{
mess_err(nodePath().c_str(),_("Start 61850 Server error."));
IedServer_destroy(iedServer);
}
else
{
running = 1;
}
}

////// 停止服务器 void Lib::modStop( )
//
if(running)
{
/* stop MMS server - close TCP server socket and all client sockets */
IedServer_stop(iedServer);

/* Cleanup - free all resources */
IedServer_destroy(iedServer);

running = 0;
}</pre>
<p>3. 注册数据监听函数</p>
<pre>extern "C"
{
void observerCallback(DataAttribute* dataAttribute)
{
if (dataAttribute == IEDMODEL_Device1_DSCH1_NamPlt_vendor)
{
printf("GGIO.NamPlt.vendor changed to %s\n",
MmsValue_toString(dataAttribute-&gt;mmsValue));
}
else if (dataAttribute == IEDMODEL_Device1_DSCH1_NamPlt_swRev)
{
printf("GGIO.NamPlt.swRef changed to %s\n",
MmsValue_toString(dataAttribute-&gt;mmsValue));
}
}
}</pre>
<p>4. 生成测试数据，修改数据节点</p>
<pre>////////////////////for test/////////////////////////////
if(running)
{
MmsValue* td = MmsValue_newIntegerFromInt32 (200);
IedServer_updateAttributeValue(iedServer, IEDMODEL_Device1_DSCH1_SchdSt_stVal, td);
MmsValue_delete(td);

td = MmsValue_newIntegerFromInt32 (202);
IedServer_updateAttributeValue(iedServer, IEDMODEL_Device1_DSCH1_Health_stVal, td);
MmsValue_delete(td);
}
////////////////////////////////////////////////</pre>
<h2>系统测试</h2>
<p>1. 编译SP61850 模块</p>
<pre>$cd openscada-0.8.0.5/src/moduls/special/SP61850

$ make clean; make

$ ~/project/openscada-0.8.0.5/src/moduls/special/SP61850$ ldd .libs/spec_SP61850.so
linux-gate.so.1 =&gt; (0x00542000)
libiec61850.so =&gt; /usr/lib/i386-linux-gnu/libiec61850.so (0x007e7000)
libstdc++.so.6 =&gt; /usr/lib/i386-linux-gnu/libstdc++.so.6 (0x00bc0000)
libm.so.6 =&gt; /lib/i386-linux-gnu/libm.so.6 (0x00e84000)
libc.so.6 =&gt; /lib/i386-linux-gnu/libc.so.6 (0x00110000)
libgcc_s.so.1 =&gt; /lib/i386-linux-gnu/libgcc_s.so.1 (0x00273000)
libpthread.so.0 =&gt; /lib/i386-linux-gnu/libpthread.so.0 (0x0028f000)
/lib/ld-linux.so.2 (0x00af2000)

$ sudo make install</pre>
<p>2. 运行测试</p>
<pre>$ sudo openscada</pre>
<p>3. 利用61850客户端软件进行连接确认，例如IEDScout，连接[192.168.1.160:102]</p>
<h2>参考资料</h2>
<p>1. <a href="http://libiec61850.com/api/">http://libiec61850.com/api/</a></p>
<p>2. <a href="http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html">http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html</a></p>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2013/08/libiec61850%e5%9c%a8openscada%e7%b3%bb%e7%bb%9f%e4%b8%ad%e7%9a%84%e4%bd%bf%e7%94%a8%e4%ba%8c/">libiec61850在OpenSCADA系统中的使用(二)</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zhourunsheng.com/2013/08/libiec61850%e5%9c%a8openscada%e7%b3%bb%e7%bb%9f%e4%b8%ad%e7%9a%84%e4%bd%bf%e7%94%a8%e4%ba%8c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>libiec61850在OpenSCADA系统中的使用</title>
		<link>http://blog.zhourunsheng.com/2013/08/libiec61850%e5%9c%a8openscada%e7%b3%bb%e7%bb%9f%e4%b8%ad%e7%9a%84%e4%bd%bf%e7%94%a8/</link>
		<comments>http://blog.zhourunsheng.com/2013/08/libiec61850%e5%9c%a8openscada%e7%b3%bb%e7%bb%9f%e4%b8%ad%e7%9a%84%e4%bd%bf%e7%94%a8/#comments</comments>
		<pubDate>Fri, 09 Aug 2013 05:01:22 +0000</pubDate>
		<dc:creator><![CDATA[润物无声]]></dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[61850]]></category>
		<category><![CDATA[OpenSCADA]]></category>

		<guid isPermaLink="false">http://blog.zhourunsheng.com/?p=1741</guid>
		<description><![CDATA[<p>libiec61850 是一套开源的C库，它实现了大多数的61850的协议转换，原理同样是基于MMS协议的映射 [&#8230;]</p>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2013/08/libiec61850%e5%9c%a8openscada%e7%b3%bb%e7%bb%9f%e4%b8%ad%e7%9a%84%e4%bd%bf%e7%94%a8/">libiec61850在OpenSCADA系统中的使用</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></description>
				<content:encoded><![CDATA[<p>libiec61850 是一套开源的C库，它实现了大多数的61850的协议转换，原理同样是基于MMS协议的映射。本文要将libiec61850用在OpenSCADA系统中，使OpenSCADA系统可以提供智能变电站61850协议的接入。</p>
<h2>简介</h2>
<p>libiec61850 is an open-source (GPLv3) implementation of an IEC 61850 client and server library. It is implemented in C to provide maximum portability. It can be used to implement IEC 61850 compliant client and server applications on embedded systems and PCs running Linux and Windows. Included is a set of simple example applications that can be used as a starting point to implement your own IEC 61850 compliant devices or to communicate with IEC 61850 devices.</p>
<p>The library implements parts of the IEC 61850 specification on top of the MMS mapping. It provides the MMS protocol stack on top of TCP/IP.<span id="more-1741"></span></p>
<h2>使用方法</h2>
<p><strong>1. 将libiec61850编译成lib的形式</strong></p>
<pre>$ cd libiec61850-0.4.1
$ make clean
$ make lib
$ ls build ### libiec61850.a</pre>
<p><strong>2. 准备编译参数</strong><br />
以examples/server_example5 为例进行说明<br />
为了与原工程项目的Makefile项目文件相分离，需要抽取出原来的编译参数。</p>
<pre>gcc -g -o server_example5 server_example5.c static_model.c -I../../inc -I../../src/common -I../../src/mms/iso_presentation -I../../src/mms/iso_session -I../../src/mms/iso_cotp -I../../src/mms/iso_acse -I../../src/mms/iso_mms/common -I../../src/mms/iso_mms/client -I../../src/mms/iso_mms/server -I../../src/mms/iso_client -I../../src/mms/iso_server -I../../src/mms/asn1 -I../../src/iedcommon -I../../src/iedserver/mms_mapping -I../../src/iedserver/model -I../../src/iedserver -I../../src/iedclient -I../../src/hal -I../../src/hal/thread -I../../src/hal/socket -I../../src/goose ../../build/libiec61850.a -lpthread</pre>
<ul>
<li>server_example5.c static_model.c 项目的源文件</li>
<li>其中-I指向头文件的目录</li>
<li>../../build/libiec61850.a指向编译出来的lib</li>
<li>-lpthread线程库的支持</li>
</ul>
<p><strong>3.准备头文件和库文件 </strong><br />
拷贝源码src目录, inc目录和build/libiec61850.a文件到指定的文件夹，然后修改编译参数-I指向的相对路径，即可实现libiec61850库的调用</p>
<p>例如，目录结构如下：</p>
<pre>lib61850/
  build
    libiec61850.a
  inc
    ...
  src
    ...</pre>
<p>Makefile.am 配置如下：</p>
<pre>############ for lib61850 include header file and lib file ##################
CFLAGS += -Ilib61850/inc -Ilib61850/src/common -Ilib61850/src/mms/iso_presentation -Ilib61850/src/mms/iso_session -Ilib61850/src/mms/iso_cotp -Ilib61850/src/mms/iso_acse -Ilib61850/src/mms/iso_mms/common -Ilib61850/src/mms/iso_mms/client -Ilib61850/src/mms/iso_mms/server -Ilib61850/src/mms/iso_client -Ilib61850/src/mms/iso_server -Ilib61850/src/mms/asn1 -Ilib61850/src/iedcommon -Ilib61850/src/iedserver/mms_mapping -Ilib61850/src/iedserver/model -Ilib61850/src/iedserver -Ilib61850/src/iedclient -Ilib61850/src/hal -Ilib61850/src/hal/thread -Ilib61850/src/hal/socket -Ilib61850/src/goose lib61850/build/libiec61850.a -lpthread
#############################################################################</pre>
<p><strong>4.实现IEC61850服务器 </strong><br />
实现自己的61850服务器，详情参照server_example5.c</p>
<h2>参考资料</h2>
<p>1. <a href="http://libiec61850.com" target="_blank">http://libiec61850.com</a></p>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2013/08/libiec61850%e5%9c%a8openscada%e7%b3%bb%e7%bb%9f%e4%b8%ad%e7%9a%84%e4%bd%bf%e7%94%a8/">libiec61850在OpenSCADA系统中的使用</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zhourunsheng.com/2013/08/libiec61850%e5%9c%a8openscada%e7%b3%bb%e7%bb%9f%e4%b8%ad%e7%9a%84%e4%bd%bf%e7%94%a8/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>OpenSCADA系统添加自定义模块</title>
		<link>http://blog.zhourunsheng.com/2013/08/openscada%e7%b3%bb%e7%bb%9f%e6%b7%bb%e5%8a%a0%e8%87%aa%e5%ae%9a%e4%b9%89%e6%a8%a1%e5%9d%97/</link>
		<comments>http://blog.zhourunsheng.com/2013/08/openscada%e7%b3%bb%e7%bb%9f%e6%b7%bb%e5%8a%a0%e8%87%aa%e5%ae%9a%e4%b9%89%e6%a8%a1%e5%9d%97/#comments</comments>
		<pubDate>Thu, 08 Aug 2013 08:56:24 +0000</pubDate>
		<dc:creator><![CDATA[润物无声]]></dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[61850]]></category>
		<category><![CDATA[OpenSCADA]]></category>

		<guid isPermaLink="false">http://blog.zhourunsheng.com/?p=1735</guid>
		<description><![CDATA[<p>前言 OpenSCADA作为一个开源的Scada系统，本文基于此系统来添加一个子模块，例子中准备添加一个支持6 [&#8230;]</p>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2013/08/openscada%e7%b3%bb%e7%bb%9f%e6%b7%bb%e5%8a%a0%e8%87%aa%e5%ae%9a%e4%b9%89%e6%a8%a1%e5%9d%97/">OpenSCADA系统添加自定义模块</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></description>
				<content:encoded><![CDATA[<h2>前言</h2>
<p>OpenSCADA作为一个开源的Scada系统，本文基于此系统来添加一个子模块，例子中准备添加一个支持61850协议的模块（名称为SP61850）。<br />
OpenScada内置支持如下的子系统</p>
<ul>
<li>"Data Bases"</li>
<li>"Communication Interfaces, Transports"</li>
<li>"Protocols of the communication interfaces"</li>
<li>"Data Sources and Data Acquisition"</li>
<li>"Archives(Histories) (of messages and values)"</li>
<li>"User Interfaces (GUI, TUI, WebGUI, speach, signal ...)"</li>
<li>"Additional modules"</li>
</ul>
<p>我们所要添加的子模块隶属于如上的"Additional modules"，即"special"子系统。<span id="more-1735"></span></p>
<h2>步骤</h2>
<p><strong>1.</strong></p>
<pre>$ cd openscada-0.8.0.5/src/moduls/special
$ cp -r =Tmpl= SP61850; cd SP61850
$ rm -f configure.in</pre>
<p><strong>2.</strong> 编辑"module.cpp"文件</p>
<p><strong>2.1</strong> module info 改为如下：</p>
<pre>//!!! Module's meta-information. Change for your module.
//*************************************************
//* Modul info! *
#define MOD_ID "SP61850"
#define MOD_NAME _("Special 61850 model")
#define MOD_TYPE SSPC_ID
#define VER_TYPE SSPC_VER
#define SUB_TYPE "LIB"
#define MOD_VER "0.0.1"
#define AUTHORS _("Carey Chow")
#define DESCRIPTION _("Special subsystem 61850 module.")
#define LICENSE "MyLicense"
//*************************************************</pre>
<p><strong>2.2</strong> 全文搜索替换 Tmpl --&gt; SP61850</p>
<p><strong>2.3 </strong>注释掉模板中无效的地方</p>
<pre>//!!! Place here your code for internal objects initialize.
//&gt; Reg functions
//reg( new MathAcos() );
//reg( new MathAsin() );</pre>
<p><strong>3. </strong>编辑"module.h"文件<br />
<strong>3.1</strong> 全文搜索替换 Tmpl --&gt; SP61850</p>
<p><strong>3.2</strong> 添加变量和函数定义</p>
<pre>//Attributes
int m_fnc;

void list( vector&lt;string&gt; &amp;ls ) { chldList(m_fnc,ls); }
AutoHD&lt;TFunction&gt; at( const string &amp;id ) { return chldAt(m_fnc,id); }</pre>
<p><strong>4.</strong> 编辑 "Makefile.am" 文件<br />
全文搜索替换 Tmpl --&gt; SP61850</p>
<p><strong>5.</strong> 编辑 openscada-0.8.0.5/configure.in 全局配置文件，添加sp61850模块的编译项<br />
在 SystemTests 模块<br />
<code>AX_MOD_EN(SystemTests,[disable build module Special.SystemTests],disable,[],<br />
[<br />
AC_MSG_RESULT(Build module: Special.SystemTests)<br />
AC_CONFIG_FILES(src/moduls/special/SystemTests/Makefile)<br />
SpecSub_mod="${SpecSub_mod}SystemTests "<br />
])</code><br />
后面添加 SP61850 模块<br />
<code>AX_MOD_EN(SP61850,[disable build module Special.SP61850],disable,[],<br />
[<br />
AC_MSG_RESULT(Build module: Special.SP61850)<br />
AC_CONFIG_FILES(src/moduls/special/SP61850/Makefile)<br />
SpecSub_mod="${SpecSub_mod}SP61850 "<br />
])</code></p>
<p><strong>6.</strong> 重新 configure，并编译我们新建立的模块</p>
<pre>$ autoreconf -if
#### 有可能需要安装 autoreconf 工具 sudo apt-get install autoconf libtool
$ ./configure --enable-SP61850
$ make
$ sudo make install</pre>
<p><strong>7.</strong> 重新启动openscada系统，在special子系统下面就会找到我们的model(SP61850)</p>
<pre>$ openscada</pre>
<h2>参考资料</h2>
<ol>
<li><a href="http://wiki.oscada.org/HomePageEn/Doc/ModuleBuild?v=pbm" target="_blank">Manual for the creation of modules for OpenSCADA</a></li>
<li><a href="http://blog.zhourunsheng.com/2013/08/openscada%E7%B3%BB%E7%BB%9F%E7%9A%84%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/" target="_blank">OpenSCADA系统的安装配置</a></li>
</ol>
<p><a rel="nofollow" href="http://blog.zhourunsheng.com/2013/08/openscada%e7%b3%bb%e7%bb%9f%e6%b7%bb%e5%8a%a0%e8%87%aa%e5%ae%9a%e4%b9%89%e6%a8%a1%e5%9d%97/">OpenSCADA系统添加自定义模块</a>，首发于<a rel="nofollow" href="http://blog.zhourunsheng.com">润物无声</a>。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.zhourunsheng.com/2013/08/openscada%e7%b3%bb%e7%bb%9f%e6%b7%bb%e5%8a%a0%e8%87%aa%e5%ae%9a%e4%b9%89%e6%a8%a1%e5%9d%97/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
