diff --git a/APP_Framework/Applications/control_app/opcua_demo/opcua_demo.c b/APP_Framework/Applications/control_app/opcua_demo/opcua_demo.c index 20a01ef5b..342375357 100755 --- a/APP_Framework/Applications/control_app/opcua_demo/opcua_demo.c +++ b/APP_Framework/Applications/control_app/opcua_demo/opcua_demo.c @@ -102,7 +102,7 @@ void *test_ua_get_server_info(void *param) { UA_Client *client = UA_Client_new(); - ua_print("ua: [%s] start ...\n", __func__); + ua_pr_info("ua: [%s] start ...\n", __func__); if (client == NULL) { @@ -121,12 +121,15 @@ void *test_ua_get_server_info(void *param) } ua_print("ua: [%s] connect ok!\n", __func__); - ua_print("--- start read time ---\n", __func__); + ua_pr_info("--- start read time ---\n", __func__); ua_read_time(client); - ua_print("--- get server info ---\n", __func__); - ua_get_server_info(client); + ua_pr_info("--- get server info ---\n", __func__); + ua_browser_objects(client); + + /* Same thing, this time using the node iterator... */ + ua_browser_nodes(client); /* Clean up */ UA_Client_disconnect(client); diff --git a/APP_Framework/Framework/control/plc/interoperability/opcua/ua_api.h b/APP_Framework/Framework/control/plc/interoperability/opcua/ua_api.h index c7b485ae8..30345d4c5 100755 --- a/APP_Framework/Framework/control/plc/interoperability/opcua/ua_api.h +++ b/APP_Framework/Framework/control/plc/interoperability/opcua/ua_api.h @@ -17,11 +17,14 @@ #define OPC_SERVER "opc.tcp://192.168.250.5:4840" #define ua_print //printf -#define ua_trace() //KPrintf("ua: [%s] line %d checked!\n", __func__, __LINE__) +#define ua_trace() //printf("ua: [%s] line %d checked!\n", __func__, __LINE__) +#define ua_pr_info KPrintf #define ua_debug int ua_server_connect(void); int ua_get_server_info(UA_Client *client); +void ua_browser_objects(UA_Client *client); +void ua_browser_nodes(UA_Client *client); void ua_read_time(UA_Client *client); int16 ua_test(void); diff --git a/APP_Framework/Framework/control/plc/interoperability/opcua/ua_client.c b/APP_Framework/Framework/control/plc/interoperability/opcua/ua_client.c index 8c587168e..a4083ea8e 100755 --- a/APP_Framework/Framework/control/plc/interoperability/opcua/ua_client.c +++ b/APP_Framework/Framework/control/plc/interoperability/opcua/ua_client.c @@ -30,7 +30,7 @@ static UA_StatusCode nodeIter(UA_NodeId childId, UA_Boolean isInverse, UA_NodeId } UA_NodeId *parent = (UA_NodeId *)handle; - ua_print("%d, %d --- %d ---> NodeId %d, %d\n", + ua_pr_info("%d, %d --- %d ---> NodeId %d, %d\n", parent->namespaceIndex, parent->identifier.numeric, referenceTypeId.identifier.numeric, childId.namespaceIndex, childId.identifier.numeric); @@ -59,13 +59,13 @@ int ua_get_points(UA_Client *client) endpointArray[i].endpointUrl.data); } UA_Array_delete(endpointArray,endpointArraySize, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]); - return EXIT_SUCCESS; + return EXIT_SUCCESS; } void ua_browser_objects(UA_Client *client) { /* Browse some objects */ - ua_print("Browsing nodes in objects folder:\n"); + ua_pr_info("Browsing nodes in objects folder:\n"); UA_BrowseRequest bReq; UA_BrowseRequest_init(&bReq); bReq.requestedMaxReferencesPerNode = 0; @@ -74,17 +74,17 @@ void ua_browser_objects(UA_Client *client) bReq.nodesToBrowse[0].nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER); /* browse objects folder */ bReq.nodesToBrowse[0].resultMask = UA_BROWSERESULTMASK_ALL; /* return everything */ UA_BrowseResponse bResp = UA_Client_Service_browse(client, bReq); - ua_print("%-9s %-16s %-16s %-16s\n", "NAMESPACE", "NODEID", "BROWSE NAME", "DISPLAY NAME"); + ua_pr_info("%-9s %-16s %-16s %-16s\n", "NAMESPACE", "NODEID", "BROWSE NAME", "DISPLAY NAME"); for(size_t i = 0; i < bResp.resultsSize; ++i) { for(size_t j = 0; j < bResp.results[i].referencesSize; ++j) { UA_ReferenceDescription *ref = &(bResp.results[i].references[j]); if(ref->nodeId.nodeId.identifierType == UA_NODEIDTYPE_NUMERIC) { - ua_print("%-9d %-16d %-16.*s %-16.*s\n", ref->nodeId.nodeId.namespaceIndex, + ua_pr_info("%-9d %-16d %-16.*s %-16.*s\n", ref->nodeId.nodeId.namespaceIndex, ref->nodeId.nodeId.identifier.numeric, (int)ref->browseName.name.length, ref->browseName.name.data, (int)ref->displayName.text.length, ref->displayName.text.data); } else if(ref->nodeId.nodeId.identifierType == UA_NODEIDTYPE_STRING) { - ua_print("%-9d %-16.*s %-16.*s %-16.*s\n", ref->nodeId.nodeId.namespaceIndex, + ua_pr_info("%-9d %-16.*s %-16.*s %-16.*s\n", ref->nodeId.nodeId.namespaceIndex, (int)ref->nodeId.nodeId.identifier.string.length, ref->nodeId.nodeId.identifier.string.data, (int)ref->browseName.name.length, ref->browseName.name.data, @@ -93,6 +93,7 @@ void ua_browser_objects(UA_Client *client) /* TODO: distinguish further types */ } } + ua_pr_info("\n"); UA_BrowseRequest_clear(&bReq); UA_BrowseResponse_clear(&bResp); } @@ -131,7 +132,7 @@ UA_UInt32 ua_start_sub(UA_Client *client) /* The first publish request should return the initial value of the variable */ UA_Client_run_iterate(client, 1000); - return subId; + return subId; } void ua_read_attr(UA_Client *client) @@ -269,33 +270,33 @@ void ua_add_nodes(UA_Client *client) int ua_get_server_info(UA_Client *client) { - UA_StatusCode retval; + UA_StatusCode retval; - /* Listing endpoints */ - retval = ua_get_points(client); - if(retval != UA_STATUSCODE_GOOD) { - UA_Client_delete(client); - return EXIT_FAILURE; - } + /* Listing endpoints */ +// retval = ua_get_points(client); +// if(retval != UA_STATUSCODE_GOOD) { +// UA_Client_delete(client); +// return EXIT_FAILURE; +// } +// +// /* Connect to a server */ +// /* anonymous connect would be: retval = UA_Client_connect(client, "opc.tcp://localhost:4840"); */ +// retval = UA_Client_connect(client, OPC_SERVER); +// if(retval != UA_STATUSCODE_GOOD) { +// UA_Client_delete(client); +// return EXIT_FAILURE; +// } - /* Connect to a server */ - /* anonymous connect would be: retval = UA_Client_connect(client, "opc.tcp://localhost:4840"); */ - retval = UA_Client_connect(client, OPC_SERVER); - if(retval != UA_STATUSCODE_GOOD) { - UA_Client_delete(client); - return EXIT_FAILURE; - } - - ua_browser_objects(client); + ua_browser_objects(client); /* Same thing, this time using the node iterator... */ - ua_browser_nodes(client); + ua_browser_nodes(client); #ifdef UA_ENABLE_SUBSCRIPTIONS - UA_Int32 subId = ua_start_sub(client); + UA_Int32 subId = ua_start_sub(client); #endif - ua_read_attr(client); + ua_read_attr(client); #ifdef UA_ENABLE_SUBSCRIPTIONS /* Take another look at the.answer */ @@ -306,11 +307,11 @@ int ua_get_server_info(UA_Client *client) #endif #ifdef UA_ENABLE_METHODCALLS - ua_call_remote(client); + ua_call_remote(client); #endif #ifdef UA_ENABLE_NODEMANAGEMENT - ua_add_nodes(client); + ua_add_nodes(client); #endif return EXIT_SUCCESS;