client.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifdef NOT_AMALGATED
  2. #include "ua_types.h"
  3. #include "ua_client.h"
  4. #else
  5. #include "open62541.h"
  6. #endif
  7. #include <stdio.h>
  8. #include "networklayer_tcp.h"
  9. int main(int argc, char *argv[]) {
  10. UA_Client *client = UA_Client_new();
  11. UA_ClientNetworkLayer nl = ClientNetworkLayerTCP_new(UA_ConnectionConfig_standard);
  12. //if(UA_Client_connect(client, UA_ConnectionConfig_standard, nl, "opc.tcp://localhost:48020") != UA_STATUSCODE_GOOD)
  13. if(UA_Client_connect(client, UA_ConnectionConfig_standard, nl, "opc.tcp://localhost:16664") != UA_STATUSCODE_GOOD)
  14. return 0;
  15. UA_NodeId node;
  16. //node.namespaceIndex = 4;
  17. //node.identifierType = UA_NODEIDTYPE_STRING;
  18. //UA_String_copycstring("Demo.Static.Scalar.Int32", &node.identifier.string);
  19. node.namespaceIndex = 1;
  20. node.identifierType = UA_NODEIDTYPE_NUMERIC;
  21. node.identifier.numeric = 442;
  22. UA_ReadRequest read_req;
  23. UA_ReadRequest_init(&read_req);
  24. read_req.nodesToRead = UA_ReadValueId_new();
  25. read_req.nodesToReadSize = 1;
  26. read_req.nodesToRead[0].nodeId = node;
  27. read_req.nodesToRead[0].attributeId = UA_ATTRIBUTEID_VALUE;
  28. UA_ReadResponse read_resp;
  29. UA_Client_read(client, &read_req, &read_resp);
  30. printf("the answer is: %i\n", *(UA_Int32*)read_resp.results[0].value.dataPtr);
  31. UA_ReadRequest_deleteMembers(&read_req);
  32. UA_ReadResponse_deleteMembers(&read_resp);
  33. UA_Client_disconnect(client);
  34. UA_Client_delete(client);
  35. }