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