mz-automation / libiec61850

Official repository for libIEC61850, the open-source library for the IEC 61850 protocols
http://libiec61850.com/libiec61850
GNU General Public License v3.0
857 stars 459 forks source link

Is it possible to create multiple instances of the iedServer for different data models in the same application? #378

Open OzzaBuzz opened 2 years ago

OzzaBuzz commented 2 years ago

My use case is to take in multiple data models for each IED devices, and I want to handle each IED devices by spawning multiple threads of the iedServer object. Please let me know if this is possible?


#include <iostream>

#include "iec61850_server.h"
#include "hal_thread.h"
#include "iec61850_model.h"
#include "static_model.h"

using namespace std;

static IedServer iedServer = NULL, iedServer2 = NULL;
extern IedModel iedModel;

int main()
{
    bool running;
    printf("Using libIEC61850 version %s\n", LibIEC61850_getVersionString());
    iedServer = IedServer_create(&iedModel);
    int startPort = 102;
    int endPort = 105; 
    // simulating a pool of ports 
    for(int i=startPort; i<=endPort; i++)
    {
        IedServer_start(iedServer, i);
    }
    cout << &iedModel<< endl;

    if (!IedServer_isRunning(iedServer))
    {
        printf("Starting server failed (maybe need root permissions or another server is already using the port)! Exit.\n");
        IedServer_destroy(iedServer);
        exit(-1);
        running = 0;
    }
    else
    {
        running = 1;
    }
    return 0;
}
andy-w commented 1 year ago

I have a Windows application handling about 20+ IED devices. I have added multiple IP addresses to my network interface to match the IP addresses of the real IED devices. Then just create a IEDModel and IEDServer for each IED Device with its own IP address.