- improved error handling in iec61850_client_example1

pull/202/head
Michael Zillgith 6 years ago
parent b6d8dfc69c
commit 3a820f3546

@ -54,8 +54,15 @@ int main(int argc, char** argv) {
MmsValue* value = IedConnection_readObject(con, &error, "simpleIOGenericIO/GGIO1.AnIn1.mag.f", IEC61850_FC_MX); MmsValue* value = IedConnection_readObject(con, &error, "simpleIOGenericIO/GGIO1.AnIn1.mag.f", IEC61850_FC_MX);
if (value != NULL) { if (value != NULL) {
float fval = MmsValue_toFloat(value);
printf("read float value: %f\n", fval); if (MmsValue_getType(value) == MMS_FLOAT) {
float fval = MmsValue_toFloat(value);
printf("read float value: %f\n", fval);
}
else if (MmsValue_getType(value) == MMS_DATA_ACCESS_ERROR) {
printf("Failed to read value (error code: %i)\n", MmsValue_getDataAccessError(value));
}
MmsValue_delete(value); MmsValue_delete(value);
} }
@ -64,62 +71,64 @@ int main(int argc, char** argv) {
IedConnection_writeObject(con, &error, "simpleIOGenericIO/GGIO1.NamPlt.vendor", IEC61850_FC_DC, value); IedConnection_writeObject(con, &error, "simpleIOGenericIO/GGIO1.NamPlt.vendor", IEC61850_FC_DC, value);
if (error != IED_ERROR_OK) if (error != IED_ERROR_OK)
printf("failed to write simpleIOGenericIO/GGIO1.NamPlt.vendor!\n"); printf("failed to write simpleIOGenericIO/GGIO1.NamPlt.vendor! (error code: %i)\n", error);
MmsValue_delete(value); MmsValue_delete(value);
/* read data set */ /* read data set */
ClientDataSet clientDataSet = IedConnection_readDataSetValues(con, &error, "simpleIOGenericIO/LLN0.Events", NULL); ClientDataSet clientDataSet = IedConnection_readDataSetValues(con, &error, "simpleIOGenericIO/LLN0.Events", NULL);
if (clientDataSet == NULL) if (clientDataSet == NULL) {
printf("failed to read dataset\n"); printf("failed to read dataset\n");
goto close_connection;
}
/* Read RCB values */ /* Read RCB values */
ClientReportControlBlock rcb = ClientReportControlBlock rcb =
IedConnection_getRCBValues(con, &error, "simpleIOGenericIO/LLN0.RP.EventsRCB01", NULL); IedConnection_getRCBValues(con, &error, "simpleIOGenericIO/LLN0.RP.EventsRCB01", NULL);
if (rcb) {
bool rptEna = ClientReportControlBlock_getRptEna(rcb);
bool rptEna = ClientReportControlBlock_getRptEna(rcb); printf("RptEna = %i\n", rptEna);
printf("RptEna = %i\n", rptEna); /* Install handler for reports */
IedConnection_installReportHandler(con, "simpleIOGenericIO/LLN0.RP.EventsRCB01",
ClientReportControlBlock_getRptId(rcb), reportCallbackFunction, NULL);
/* Install handler for reports */ /* Set trigger options and enable report */
IedConnection_installReportHandler(con, "simpleIOGenericIO/LLN0.RP.EventsRCB01", ClientReportControlBlock_setTrgOps(rcb, TRG_OPT_DATA_UPDATE | TRG_OPT_INTEGRITY | TRG_OPT_GI);
ClientReportControlBlock_getRptId(rcb), reportCallbackFunction, NULL); 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);
/* Set trigger options and enable report */ if (error != IED_ERROR_OK)
ClientReportControlBlock_setTrgOps(rcb, TRG_OPT_DATA_UPDATE | TRG_OPT_INTEGRITY | TRG_OPT_GI); printf("report activation failed (code: %i)\n", error);
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) Thread_sleep(1000);
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);
/* trigger GI report */ if (error != IED_ERROR_OK)
ClientReportControlBlock_setGI(rcb, true); printf("Error triggering a GI report (code: %i)\n", error);
IedConnection_setRCBValues(con, &error, rcb, RCB_ELEMENT_GI, true);
if (error != IED_ERROR_OK) Thread_sleep(60000);
printf("Error triggering a GI report (code: %i)\n", error);
Thread_sleep(60000);
/* disable reporting */ /* disable reporting */
ClientReportControlBlock_setRptEna(rcb, false); ClientReportControlBlock_setRptEna(rcb, false);
IedConnection_setRCBValues(con, &error, rcb, RCB_ELEMENT_RPT_ENA, true); IedConnection_setRCBValues(con, &error, rcb, RCB_ELEMENT_RPT_ENA, true);
if (error != IED_ERROR_OK) if (error != IED_ERROR_OK)
printf("disable reporting failed (code: %i)\n", error); printf("disable reporting failed (code: %i)\n", error);
ClientDataSet_destroy(clientDataSet); ClientDataSet_destroy(clientDataSet);
ClientReportControlBlock_destroy(rcb); ClientReportControlBlock_destroy(rcb);
}
close_connection: close_connection:
IedConnection_close(con); IedConnection_close(con);
} }

Loading…
Cancel
Save