libIEC61850
open source library for IEC 61850
IEC 61850 client tutorial
The IEC 61850 client API contains functions to support model discovery, reading and writing data attributes, data t handling, configuration and reception of reports, file rvices and control operations. This client API is designed to be as clo as possible to the IEC 61850 ACSI (abstract communication rvice interface) as defined in IEC 61850-7-2. But be aware that there are some points where there are some deviations from the ACSI due to practical reasons. Create a connection to a rver
Before you can connect to a rver you have to create an IedConnection object. A connection will be established with the IedConnection_connect method. The first argument is the newly created IedConnection instance. The cond argument provides a pointer to a variable where the client stack can store error informations. This is also the ca with most other client API functions (IedConnection_…) where errors can occur. The third argument is a string containing the IP address or hostname of the rver to connect. The last argument provides the TCP port of the rver. The default
TCP port of MMS is 102. So you should always lect this port.
Practical examples on how to u the IEC 61850 client API can be found in the examples folder in the libiec61850 source distributions. The examples start with “iec61850_client”.
IedClientError error;
IedConnection con = IedConnection_create();
IedConnection_connect(con, &error, "192.168.1.2", 102);
if (error == IED_ERROR_OK) {
// do some work
IedConnection_clo(con);
}
IedConnection_destroy(con);
...
The code snippet above will connect to a rver with IP address 192.168.1.2 listening on port 102 (the default MMS port). If you finished your task you have to call IedConnection_clo to properly clo the connection to the rver. After you clod the connection you should also call IedConnection_destroy to relea all resources allocated by the client stack. Control connection parameters
The IEC 61850/MMS protocol is a complex protocol consisting of a lot of OSI protocol layers. Most of them have their own parameters. Fortunately in most cas the default values of the parameters are sufficient to connect to a device. Some devices though have problems with default parameters and require a special treatment.
The IsoConnectionParameters object, that is associated with a MmsConnection can be ud to t the lower layer parameters (below the MMS layer). It can also be ud to t authentication values (e.g.
a password) if the rver requires authentication.
For more details on how to change the parameters plea have a look at the examples and the API reference documentation.
Data model discovery
IEC 61850 provides a wide range of functions to discover the data model prent at the rver. The functions are especially interesting if you want to write a generic client. If you know the data model of the device you want to communicate to you don’t need the functions.
To request the logical device list from the rver you can call the IedConnection_getLogicalDeviceList method.
LinkedList deviceList = IedConnection_getLogicalDeviceList(con, &error);
The resulting linked list contains the names of all logical devices of the rver as a list of C strings. The directory of a logical device can be retrieved by calling IedConnection_getLogicalDeviceDirectory with the name of the logical device as a parameter.
The following example iterates the list of logical devices and requests the logical node list for each logical device:
LinkedList device = LinkedList_getNext(deviceList);
while (device != NULL) {
printf("LD: %s\n", (char*) device->data);
LinkedList logicalNodes = IedConnection_getLogicalDeviceDirectory(con, &error,
(char*) device->data);
device = LinkedList_getNext(device);
}
Reading and writing data objects
You can read or write simple or complex data attributes/objects with the IedConnection_readObject and IedConnection_writeObject funtions. Before you can u the functions you have to establish a connection to a rver as explained above. The parameter lists of both functions are similar. The first argument is the connection object of an established connection. The cond argument is a pointer to an IedClientError variable. The third argument is the object reference of the data attribute/object you want to access. The fourth argument is the Functional Constraint (e.g. MX).
微软主页Note: You cannot access whole IEC 61850 data objects with the functions. For example a call to I
edConnection_readObject will result in a single MMS read command. This is restricted to functional constraint data. So in order to read all values of an IEC 61850 data object you have to u multiple readObject calls for each functional constraint the data object has elements of. This ems as a restriction at the first but turns out to be very uful. E.g. you can read all measurement or status values (functional constraints MX or ST) of an IEC 61850 data object without reading configuration values or control variables (functional constraints CF or CO).
IedClientError error;
...
/* read an analog measurement value from rver */
MmsValue* value = IedConnection_readObject(con, &error,
"simpleIOGenericIO/GGIO1.AnIn1.mag.f", MX);
if (value != NULL) {
float fval = MmsValue_toFloat(value);
唐朝的诗人
printf("read float value: %f\n", fval);
MmsValue_delete(value);
}
/* write a variable to the rver */
value = MmsValue_newVisibleString("");
IedConnection_writeObject(con, &error,
观赏螺"simpleIOGenericIO/GGIO1.NamPlt.vendor", DC, value);
if (error != IED_ERROR_OK)
printf("failed to write simpleIOGenericIO/GGIO1.NamPlt.vendor!\n");
The IedConnection_readObject and IedConnection_writeObject functions u instances of MmsValue as results or parameters. The benefit of the functions is that they are very flexible and can also be ud to access complex (structured) data. Also the type of the result has not to be know
n in advance when using the readObject function. One other conquence is that for the read function the API ur always have to free (by using MmsValue_delete) the data after processing. Also by using the writeObject functions you have to deal with MmsValue and its special tter functions. To avoid this the client API also contains some convenience functions that allow read and write with native data types as parameters. The functions are restricted to access simple (basic) data attributes. Also the type of the result has to be known in the read ca.
An example for the functions is the IedConnection_readFloatValue function:
float magF = IedConnection_readFloatValue(con, &error,
"simpleIOGenericIO/GGIO1.AnIn1.mag.f", MX);
Handling data ts
Data ts are groups of data attributes (DA) or functional constraint data objects (FCDO). They are ud to simplify access to functional related groups of variables. E.g. if you want to read the most important status values of a rver you don’t have to ask the rver for each individual variable. Instead you define a data t (or most probably u a predefined one) that contains all the required
data and request them with a single read with the data t reference as an argument. Data ts are also intended to be ud in relation with reports, GOOSE messages and logs (time ries of data).喜欢一个人的句子
So far the IEC 61850 client API supports the following data t related rvices:
•read data t values
•define a new data t
•delete an existing data t
吸的反义词
•read the directory (list of variables) of the data t
To reprent a data t client side the library us objects of type ClientDataSet. ClientDataSet can be considered as a container to store the values of a data t and consists of the functions:
void
ClientDataSet_destroy(ClientDataSet lf);
MmsValue*
ClientDataSet_getValues(ClientDataSet lf);
char*
研究生实习报告
ClientDataSet_getReference(ClientDataSet lf);
int
ClientDataSet_getDataSetSize(ClientDataSet lf);
The actual values of the data t are stored as MmsValue instance of type MMS_ARRAY. There is an array element for each member of the data t.
To access the data t related rvices the functions have to be ud:
ClientDataSet
IedConnection_readDataSetValues(IedConnection lf, IedClientError* error,
char* dataSetReference, ClientDataSet dataSet);
void
IedConnection_createDataSet(IedConnection lf, IedClientError* error,
char* dataSetReference, LinkedList /* char* */ dataSetElements); void
IedConnection_deleteDataSet(IedConnection lf, IedClientError* error,
char* dataSetReference);
LinkedList /* <char*> */
IedConnection_getDataSetDirectory(IedConnection lf, IedClientError* error,
中国梯char* dataSetReference, bool* isDeletable);
The IedConnection_readDataSetValues creates a new instance of ClientDataSet if the last parameter (dataSet) is NULL. A call to this function triggers a request to the rver. If you call the function multiple times you can provide the formerly received ClientDataSet instance as dataSet parameter. In this way you can reu the container.
This example shows how to read the values of a data t:csgo竞技模式