libiec61850学习1
生活随笔
收集整理的這篇文章主要介紹了
libiec61850学习1
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
iec61850_client_example1的例子
- client_example1.c
- This example is intended to be used with server_example_basic_io or server_example_goose.
*/
在libiec61850\examples\server_example_basic_io里找到simpleIO_direct_control.cid這個文件,修改ip地址127.0.0.1。使用iedscout打開simpleIO_direct_control.cid文件,運(yùn)行仿真服務(wù)器功能。
這時可以啟動調(diào)試iec61850_client_example1程序。
int main(int argc, char** argv) {char* hostname;**int tcpPort = 102;** //服務(wù)器監(jiān)聽端口,客戶端連接服務(wù)端ip+端口if (argc > 1)hostname = argv[1];else**hostname = "localhost";**if (argc > 2)tcpPort = atoi(argv[2]);IedClientError error;//創(chuàng)建客戶端連接對象**IedConnection con = IedConnection_create();**//連接服務(wù)器**IedConnection_connect(con, &error, hostname, tcpPort);**//error 是否有錯誤if (error == IED_ERROR_OK) {/* read an analog measurement value from server */ **//根據(jù)索引讀取模擬量值simpleIOGenericIO/GGIO1.AnIn1.mag.f**MmsValue* value = IedConnection_readObject(con, &error, "simpleIOGenericIO/GGIO1.AnIn1.mag.f", IEC61850_FC_MX);if (value != NULL) {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);}/* write a variable to the server */**//寫變量simpleIOGenericIO/GGIO1.NamPlt.vendor**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! (error code: %i)\n", error);MmsValue_delete(value);/* read data set */ClientDataSet clientDataSet = IedConnection_readDataSetValues(con, &error, "simpleIOGenericIO/LLN0.Events", NULL);**//讀數(shù)據(jù)集里的數(shù)據(jù)****value = ClientDataSet_getValues(clientDataSet);****//數(shù)據(jù)集里元素個數(shù)****int size = ClientDataSet_getDataSetSize(clientDataSet);**//根據(jù)索引得到元素的值//4個元素 我添加的代碼,根據(jù)索引獲得值**int size = ClientDataSet_getDataSetSize(clientDataSet);MmsValue *tmp = MmsValue_getElement(value, 0);MmsValue* tmp1 = MmsValue_getElement(value, 1);MmsValue* tmp2 = MmsValue_getElement(value, 2);MmsValue* tmp3 = MmsValue_getElement(value, 3);//bool類型if (MmsValue_getType(tmp) == MMS_BOOLEAN){bool ret = MmsValue_getBoolean(tmp);}**if (clientDataSet == NULL) {printf("failed to read dataset\n");goto close_connection;}/* Read RCB values */ClientReportControlBlock rcb =IedConnection_getRCBValues(con, &error, "simpleIOGenericIO/LLN0.RP.EventsRCB01", NULL);if (rcb) {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);ClientReportControlBlock_destroy(rcb);}close_connection:IedConnection_close(con);}else {printf("Failed to connect to %s:%i\n", hostname, tcpPort);}IedConnection_destroy(con); }總結(jié)
以上是生活随笔為你收集整理的libiec61850学习1的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pinphp3.0后台系统权限管理的bu
- 下一篇: 《绯雨骑士团》Demo