libIEC61850 Open source学习心得(一)——Connection handling

一、Server API

    1.IedServer IedServer_create(IedModel* iedModel)

        创建一个IedServer,iedModel是准备运行的ied模型。

    2.void IedServer_start(IedServer self, int tcpPort)

        开始监听客户端连接,iec61850的默认通信端口是102端口。

    3.void IedServer_stop(IedServer self)
        停止监听客户端连接,停止一切服务端行为。

    4.void IedServer_destroy(IedServer self)

        完全释放一个ied 

二、Client API

    1.IedConnection IedConnection_create()

        创建一个客户端连接,此时该连接还未连接到任何服务端,调用IedConnection_getState返回的状态是IED_STATE_IDLE。

    2.void IedConnection_connect(IedConnection self, IedClientError* error, char* hostname, int tcpPort)

        连接到服务端,hostname为服务端ip,tcpPort为端口,默认端口是102。

    3.void IedConnection_abort (IedConnection self, IedClientError *error)

        主动放弃一个连接,放弃掉的连接获取到的状态是IED_STATE_CLOSED

    4.void IedConnection_release (IedConnection self, IedClientError *error)

        主动释放一个连接,放弃掉的连接获取到的状态是IED_STATE_CLOSED

    5.void IedConnection_close (IedConnection self)

        主动关闭一个连接,放弃掉的连接获取到的状态是IED_STATE_CLOSED

    6.void IedConnection_destroy (IedConnection self)

        完全释放一个连接,无论放弃、释放以及关闭一个连接后,都需要调用该函数释放内存空间

    7.IedConnectionState IedConnection_getState (IedConnection self)

        获取连接状态,当调用了IedConnection_destroy后,调用该函数返回的是IED_STATE_CLOSED

    8.void IedConnection_installConnectionClosedHandler (IedConnection self, IedConnectionClosedHandler handler, void *parameter)

        注册连接关闭后的回调函数。其中:

            self是连接对象;handler是回调函数;parameter是输入回调函数的参数

            handler为(void) function(void *param,IedConnection con)类型的函数

            当服务端被关闭、链路断开等突发性连接断开事件发生时,会触立即发该回调函数

三、使用方法

    1.服务端

    iedServer ied_server = IedServer_create(&iedModel);

    IedServer_start(ied_server);

    while (running) {
        Thread_sleep(1);
    }  
 
    IedServer_stop(ied_server);
 
    IedServer_destroy(ied_server);
 
 

    2.客户端

    void IedConnectionCLosed(void *param,IedConnection con)
    {
        printf("connection is closed!\r\n");
        IedConnection_close(con);
        IedConnection_destroy(con);
    }
   

 
    IedClientError error;

    IedConnection con = IedConnection_create();

    IedConnection_connect(con, &error,”127.0.0.1“, 102);

    if (error == IED_ERROR_OK) {
      // do some work
      IedConnection_installConnectionClosedHandler(con,IedConnectionCLosed,NULL); //注册连接断开时的回调函数
      IedConnection_close(con);
    }
 
    //IedConnection_destroy(con);      //若在回调函数中没有destroy连接的话要在这里完成
    ...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值