client_types_custom.c 1.2 KB

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