libiec61850学习2(动态获取模型)

libiec61850\examples\server_example_basic_io\simpleIO_direct_control.cid文件,ip设置127.0.0.1

iedsout打开这个文件
有的朋友对模型不了解,我上传了修改ip的cid文件,下载地址:
https://download.csdn.net/download/wojiuguowei/12921163
/*

  • client_example2.c
  • This example shows how to browse the data model of an unknown device.
    */

#include “iec61850_client.h”

#include <stdlib.h>
#include <stdio.h>

void
printSpaces(int spaces)
{
int i;

for (i = 0; i < spaces; i++)
    printf(" ");

}

void
printDataDirectory(char* doRef, IedConnection con, int spaces)
{
IedClientError error;

LinkedList dataAttributes = IedConnection_getDataDirectory(con, &error, doRef);

//LinkedList dataAttributes = IedConnection_getDataDirectoryByFC(con, &error, doRef, MX);

if (dataAttributes != NULL) {
    LinkedList dataAttribute = LinkedList_getNext(dataAttributes);

    while (dataAttribute != NULL) {
        char* daName = (char*) dataAttribute->data;

        printSpaces(spaces);
        printf("DA: %s\n", (char*) dataAttribute->data);

        dataAttribute = LinkedList_getNext(dataAttribute);

        char daRef[130];
        sprintf(daRef, "%s.%s", doRef, daName);
        printDataDirectory(daRef, con, spaces + 2);
    }
}

LinkedList_destroy(dataAttributes);

}

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

char* hostname;
int tcpPort = 102;

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);

if (error == IED_ERROR_OK) {

    printf("Get logical device list...\n");
  


    LinkedList deviceList = IedConnection_getLogicalDeviceList(con, &error);

    if (error != IED_ERROR_OK) {
        printf("Failed to read device list (error code: %i)\n", error);
        goto cleanup_and_exit;
    }

    LinkedList device = LinkedList_getNext(deviceList);

    while (device != NULL) {
        printf("LD: %s\n", (char*) device->data);

//获得逻辑设备simpleIOGenericIO

        LinkedList logicalNodes = IedConnection_getLogicalDeviceDirectory(con, &error,
                (char*) device->data);

        LinkedList logicalNode = LinkedList_getNext(logicalNodes);

        while (logicalNode != NULL) {

//获得逻辑节点GGIO1

根据lntype GGIO1,在里LNodeType找到DO,然后再在一次遍历根据DO,再根据type查找DA
在这里插入图片描述

         printf("  LN: %s\n", (char*) logicalNode->data);

            char lnRef[129];

            sprintf(lnRef, "%s/%s", (char*) device->data, (char*) logicalNode->data);

            LinkedList dataObjects = IedConnection_getLogicalNodeDirectory(con, &error,
                    lnRef, ACSI_CLASS_DATA_OBJECT);

            LinkedList dataObject = LinkedList_getNext(dataObjects);

            while (dataObject != NULL) {

            //数据对象DO
            

                char* dataObjectName = (char*) dataObject->data;

                printf("    DO: %s\n", dataObjectName);

                dataObject = LinkedList_getNext(dataObject);

                char doRef[129];

数据对象引用simpleIOGenericIO/GGIO1.Mod

                sprintf(doRef, "%s/%s.%s", (char*) device->data, (char*) logicalNode->data, dataObjectName);

                printDataDirectory(doRef, con, 6);                }

            LinkedList_destroy(dataObjects);

//遍历数据集

            LinkedList dataSets = IedConnection_getLogicalNodeDirectory(con, &error, lnRef,
                    ACSI_CLASS_DATA_SET);

            LinkedList dataSet = LinkedList_getNext(dataSets);

            while (dataSet != NULL) {
                char* dataSetName = (char*) dataSet->data;
                bool isDeletable;
                char dataSetRef[130];
                sprintf(dataSetRef, "%s.%s", lnRef, dataSetName);

                LinkedList dataSetMembers = IedConnection_getDataSetDirectory(con, &error, dataSetRef,
                        &isDeletable);

                if (isDeletable)
                    printf("    Data set: %s (deletable)\n", dataSetName);
                else
                    printf("    Data set: %s (not deletable)\n", dataSetName);

                LinkedList dataSetMemberRef = LinkedList_getNext(dataSetMembers);

                while (dataSetMemberRef != NULL) {

                    char* memberRef = (char*) dataSetMemberRef->data;

                    printf("      %s\n", memberRef);

                    dataSetMemberRef = LinkedList_getNext(dataSetMemberRef);
                }

                LinkedList_destroy(dataSetMembers);

                dataSet = LinkedList_getNext(dataSet);
            }

            LinkedList_destroy(dataSets);

            LinkedList reports = IedConnection_getLogicalNodeDirectory(con, &error, lnRef,
                    ACSI_CLASS_URCB);

报告控制

在这里插入图片描述

读 LD 列表采用 GetNameList 服务,客户端发起读 VMD,服务器端以 LD 列表响应,如下图示:
请求 vmd
在这里插入图片描述

响应
在这里插入图片描述

在这里插入图片描述

读 LD 中有名列表页采用 GetNameList 服务,客户端发起读哪个 LD,服务器端响应,如下图示:

读请求

在这里插入图片描述

响应
在这里插入图片描述

读数据集采用 GetNamedVariableListAttributrs 服务,客户端发起读哪个 LD 的哪个数据集,
服务器端以 FCDA 响应,如下图示:
读 响应

在这里插入图片描述

服务器端以值响应,如下图示:
在这里插入图片描述

            LinkedList report = LinkedList_getNext(reports);

            while (report != NULL) {
                char* reportName = (char*) report->data;

                printf("    RP: %s\n", reportName);

                report = LinkedList_getNext(report);
            }

            LinkedList_destroy(reports);

            reports = IedConnection_getLogicalNodeDirectory(con, &error, lnRef,
                    ACSI_CLASS_BRCB);

            report = LinkedList_getNext(reports);

            while (report != NULL) {
                char* reportName = (char*) report->data;

                printf("    BR: %s\n", reportName);

                report = LinkedList_getNext(report);
            }

            LinkedList_destroy(reports);

            logicalNode = LinkedList_getNext(logicalNode);
        }

        LinkedList_destroy(logicalNodes);

        device = LinkedList_getNext(device);
    }

    LinkedList_destroy(deviceList);

    IedConnection_close(con);
}
else {
    printf("Connection failed!\n");
}

cleanup_and_exit:
IedConnection_destroy(con);
}

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

金士顿

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

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

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

打赏作者

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

抵扣说明:

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

余额充值