client_types_custom.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
  3. #include <stdio.h>
  4. #include "open62541.h"
  5. #include "custom_datatype.h"
  6. int main(void) {
  7. UA_ClientConfig config = UA_ClientConfig_default;
  8. /* Make your custom datatype known to the stack */
  9. UA_DataType types[1];
  10. types[0] = PointType;
  11. config.customDataTypes = types;
  12. config.customDataTypesSize = 1;
  13. UA_Client *client = UA_Client_new(config);
  14. UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
  15. if(retval != UA_STATUSCODE_GOOD) {
  16. UA_Client_delete(client);
  17. return (int)retval;
  18. }
  19. UA_Variant value; /* Variants can hold scalar values and arrays of any type */
  20. UA_Variant_init(&value);
  21. UA_NodeId nodeId =
  22. UA_NODEID_STRING(1, "3D.Point");
  23. retval = UA_Client_readValueAttribute(client, nodeId, &value);
  24. if(retval == UA_STATUSCODE_GOOD) {
  25. Point *p = (Point *)value.data;
  26. printf("Point = %f, %f, %f \n", p->x, p->y, p->z);
  27. }
  28. /* Clean up */
  29. UA_Variant_deleteMembers(&value);
  30. UA_Client_delete(client); /* Disconnects the client internally */
  31. return UA_STATUSCODE_GOOD;
  32. }