-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.c
More file actions
32 lines (28 loc) · 1.24 KB
/
Client.c
File metadata and controls
32 lines (28 loc) · 1.24 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
#include <stdio.h>
#include "open62541.h"
int main(int argc, char *argv[])
{
/* Create a client and connect */
UA_Client *client = UA_Client_new(UA_ClientConfig_default);
UA_StatusCode status = UA_Client_connect(client, "opc.tcp://localhost:4840");
if(status != UA_STATUSCODE_GOOD) {
UA_Client_delete(client);
return status;
}
/* Read the value attribute of the node. UA_Client_readValueAttribute is a
* wrapper for the raw read service available as UA_Client_Service_read. */
UA_Variant value; /* Variants can hold scalar values and arrays of any type */
UA_Variant_init(&value);
//status = UA_Client_readValueAttribute(client, UA_NODEID_STRING(1, "the.answer1"), &value);
status = UA_Client_readValueAttribute(client, UA_NODEID_NUMERIC(1,20305), &value);
printf("Status Code is received: 0x%x \r\n",status);
if(status == UA_STATUSCODE_GOOD &&
UA_Variant_hasScalarType(&value, &UA_TYPES[UA_TYPES_INT32])) {
printf(":-) The value is: %i\n\r", *(UA_Int32*)value.data);
}
else printf("The value not found :-(\r\n");
/* Clean up */
UA_Variant_deleteMembers(&value);
UA_Client_delete(client); /* Disconnects the client internally */
return status;
}