libiec61850学习1

iec61850_client_example1的例子

  1. client_example1.c的文件最上边注释,/*
  • client_example1.c
  • This example is intended to be used with server_example_basic_io or server_example_goose.
    */
    在libiec61850\examples\server_example_basic_io里找到simpleIO_direct_control.cid这个文件,修改ip地址127.0.0.1。使用iedscout打开simpleIO_direct_control.cid文件,运行仿真服务器功能。

这时可以启动调试iec61850_client_example1程序。

int main(int argc, char** argv) {

    char* hostname;
    **int tcpPort = 102;**       //服务器监听端口,客户端连接服务端ip+端口

    if (argc > 1)
        hostname = argv[1];
    else
        **hostname = "localhost";**

    if (argc > 2)
        tcpPort = atoi(argv[2]);

    IedClientError error;

	//创建客户端连接对象
    **IedConnection con = IedConnection_create();**

	//连接服务器
    **IedConnection_connect(con, &error, hostname, tcpPort);**
	
	//error 是否有错误
    if (error == IED_ERROR_OK) {

        /* read an analog measurement value from server */     
        **//根据索引读取模拟量值simpleIOGenericIO/GGIO1.AnIn1.mag.f**
        MmsValue* value = IedConnection_readObject(con, &error, "simpleIOGenericIO/GGIO1.AnIn1.mag.f", IEC61850_FC_MX);

        if (value != NULL) {

            if (MmsValue_getType(value) == MMS_FLOAT) {
                float fval = MmsValue_toFloat(value);
                printf("read float value: %f\n", fval);
            }
            else if (MmsValue_getType(value) == MMS_DATA_ACCESS_ERROR) {
                printf("Failed to read value (error code: %i)\n", MmsValue_getDataAccessError(value));
            }

            MmsValue_delete(value);
        }

        /* write a variable to the server */
        **//写变量simpleIOGenericIO/GGIO1.NamPlt.vendor**
        value = MmsValue_newVisibleString("libiec61850.com");
        IedConnection_writeObject(con, &error, "simpleIOGenericIO/GGIO1.NamPlt.vendor", IEC61850_FC_DC, value);

        if (error != IED_ERROR_OK)
            printf("failed to write simpleIOGenericIO/GGIO1.NamPlt.vendor! (error code: %i)\n", error);

        MmsValue_delete(value);

        /* read data set */
        ClientDataSet clientDataSet = IedConnection_readDataSetValues(con, &error, "simpleIOGenericIO/LLN0.Events", NULL);
        **//读数据集里的数据**
        **value = ClientDataSet_getValues(clientDataSet);**
        **//数据集里元素个数**
         **int size = ClientDataSet_getDataSetSize(clientDataSet);**
		//根据索引得到元素的值
        //4个元素 我添加的代码,根据索引获得值
        **int size = ClientDataSet_getDataSetSize(clientDataSet);
        MmsValue *tmp =  MmsValue_getElement(value, 0);
        MmsValue* tmp1 = MmsValue_getElement(value, 1);
        MmsValue* tmp2 = MmsValue_getElement(value, 2);
        MmsValue* tmp3 = MmsValue_getElement(value, 3);
        
        //bool类型
        if (MmsValue_getType(tmp) == MMS_BOOLEAN)
        {
            bool ret =  MmsValue_getBoolean(tmp);
            
        }**

        if (clientDataSet == NULL) {
            printf("failed to read dataset\n");
            goto close_connection;
        }

        /* Read RCB values */
        ClientReportControlBlock rcb =
                IedConnection_getRCBValues(con, &error, "simpleIOGenericIO/LLN0.RP.EventsRCB01", NULL);

        if (rcb) {
            bool rptEna = ClientReportControlBlock_getRptEna(rcb);

            printf("RptEna = %i\n", rptEna);

            /* Install handler for reports */
            IedConnection_installReportHandler(con, "simpleIOGenericIO/LLN0.RP.EventsRCB01",
                    ClientReportControlBlock_getRptId(rcb), reportCallbackFunction, NULL);

            /* Set trigger options and enable report */
            ClientReportControlBlock_setTrgOps(rcb, TRG_OPT_DATA_UPDATE | TRG_OPT_INTEGRITY | TRG_OPT_GI);
            ClientReportControlBlock_setRptEna(rcb, true);
            ClientReportControlBlock_setIntgPd(rcb, 5000);
            IedConnection_setRCBValues(con, &error, rcb, RCB_ELEMENT_RPT_ENA | RCB_ELEMENT_TRG_OPS | RCB_ELEMENT_INTG_PD, true);

            if (error != IED_ERROR_OK)
                printf("report activation failed (code: %i)\n", error);

            Thread_sleep(1000);

            /* trigger GI report */
            ClientReportControlBlock_setGI(rcb, true);
            IedConnection_setRCBValues(con, &error, rcb, RCB_ELEMENT_GI, true);

            if (error != IED_ERROR_OK)
                printf("Error triggering a GI report (code: %i)\n", error);

            Thread_sleep(60000);

            /* disable reporting */
            ClientReportControlBlock_setRptEna(rcb, false);
            IedConnection_setRCBValues(con, &error, rcb, RCB_ELEMENT_RPT_ENA, true);

            if (error != IED_ERROR_OK)
                printf("disable reporting failed (code: %i)\n", error);

            ClientDataSet_destroy(clientDataSet);

            ClientReportControlBlock_destroy(rcb);
        }

close_connection:

        IedConnection_close(con);
    }
    else {
        printf("Failed to connect to %s:%i\n", hostname, tcpPort);
    }

    IedConnection_destroy(con);
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

金士顿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值