forked from open62541/open62541
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_method_async.c
More file actions
66 lines (57 loc) · 2.4 KB
/
client_method_async.c
File metadata and controls
66 lines (57 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
* See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
#include <open62541/client_config_default.h>
#include <open62541/client_highlevel_async.h>
#include <open62541/plugin/log_stdout.h>
#include <open62541/server_config_default.h>
static void
methodCalled(UA_Client *client, void *userdata, UA_UInt32 requestId,
UA_CallResponse *response) {
UA_StatusCode retval = response->responseHeader.serviceResult;
if(retval != UA_STATUSCODE_GOOD) {
UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_APPLICATION,
"CallRequest FAILED");
return;
}
for(size_t i = 0; i < response->resultsSize; i++) {
retval = response->results[i].statusCode;
if(retval != UA_STATUSCODE_GOOD) {
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_APPLICATION,
"CallRequest Response - %u failed",
(unsigned long)i);
continue;
}
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_APPLICATION,
"Method call was successful, returned %lu values",
(unsigned long)response->results[i].outputArgumentsSize);
}
}
int
main(int argc, char *argv[]) {
UA_Client *client = UA_Client_new();
UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
if(retval != UA_STATUSCODE_GOOD) {
UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_APPLICATION, "Not connected");
UA_Client_delete(client);
return 0;
}
/* Initiate Call 1 */
UA_Variant input;
UA_String stringValue = UA_STRING("World 1");
UA_Variant_setScalar(&input, &stringValue, &UA_TYPES[UA_TYPES_STRING]);
UA_Client_call_async(client, UA_NS0ID(OBJECTSFOLDER),
UA_NODEID_NUMERIC(1, 62541), 1, &input,
methodCalled, NULL, NULL);
/* Initiate Call 2 */
stringValue = UA_STRING("World 2");
UA_Variant_setScalar(&input, &stringValue, &UA_TYPES[UA_TYPES_STRING]);
UA_Client_call_async(client, UA_NS0ID(OBJECTSFOLDER),
UA_NODEID_NUMERIC(1, 62542), 1, &input,
methodCalled, NULL, NULL);
/* Run the client until ctrl-c */
UA_Client_runUntilInterrupt(client);
/* Clean up */
UA_Client_disconnect(client);
UA_Client_delete(client);
return 0;
}