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

        /* read an analog measurement value from server */
        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 server */
        value = MmsValue_newVisibleString("libiec61850.com");
        IedConnection_writeObject(con, &error, "simpleIOGenericIO/GGIO1.NamPlt.vendor", DC, value);

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

        MmsValue_delete(value);

        /* read data set */
        ClientDataSet clientDataSet;

        clientDataSet = IedConnection_getDataSet(con, &error, "simpleIOGenericIO/LLN0.Events", NULL);

        if (clientDataSet == NULL)
            printf("failed to read dataset\n");

        printDataSetValues(ClientDataSet_getDataSetValues(clientDataSet));

        IedConnection_enableReporting(con, &error, "simpleIOGenericIO/LLN0.RP.EventsRCB", clientDataSet,
                TRG_OPT_DATA_UPDATE | TRG_OPT_INTEGRITY, reportCallbackFunction, ClientDataSet_getDataSetValues(
                        clientDataSet));

        Thread_sleep(5000);

        IedConnection_disableReporting(con, &error, "simpleIOGenericIO/LLN0.RP.EventsRCB");

        IedConnection_close(con);
    }

    IedConnection_destroy(con);

	printf("I've done all work. Press anykey...");
	getche();
}
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);

    	LinkedList device = LinkedList_getNext(deviceList);

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

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

    		LinkedList logicalNode = LinkedList_getNext(logicalNodes);

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

    			char* lnRef = (char*) alloca(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) {
    			    char* dataObjectName = (char*) dataObject->data;

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

    			    dataObject = LinkedList_getNext(dataObject);

    			    char* doRef = (char*) alloca(129);

    			    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;

    				printf("    DS: %s\n", dataSetName);

    				dataSet = LinkedList_getNext(dataSet);
    			}

    			LinkedList_destroy(dataSets);

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

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

    IedConnection_destroy(con);
}
Example #3
0
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) {

        /* read an analog measurement value from server */
        MmsValue* value = IedConnection_readObject(con, &error, "simpleIOGenericIO/GGIO1.AnIn1.mag.f", IEC61850_FC_MX);

        if (value != NULL) {
            float fval = MmsValue_toFloat(value);
            printf("read float value: %f\n", fval);
            MmsValue_delete(value);
        }

        /* write a variable to the server */
        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!\n");
        else
            MmsValue_delete(value);


        /* read data set */
        ClientDataSet clientDataSet = IedConnection_readDataSetValues(con, &error, "simpleIOGenericIO/LLN0.Events", NULL);

        if (clientDataSet == NULL)
            printf("failed to read dataset\n");

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


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

        close_connection:

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

    IedConnection_destroy(con);
}