client_proper.c 966 B

12345678910111213141516171819202122232425262728
  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. UA_Client_connect(client, UA_ConnectionConfig_standard, nl, "opc.tcp://localhost:16664");
  13. UA_ReadRequest read_req;
  14. UA_ReadRequest_init(&read_req);
  15. read_req.nodesToRead = UA_ReadValueId_new();
  16. read_req.nodesToReadSize = 1;
  17. read_req.nodesToRead[0].nodeId = UA_NODEID_STATIC(1, 73);
  18. read_req.nodesToRead[0].attributeId = UA_ATTRIBUTEID_VALUE;
  19. UA_ReadResponse read_resp = UA_Client_read(client, &read_req);
  20. printf("the answer is: %i\n", *(UA_Int32*)read_resp.results[0].value.dataPtr);
  21. UA_ReadRequest_deleteMembers(&read_req);
  22. UA_ReadResponse_deleteMembers(&read_resp);
  23. UA_Client_delete(client);
  24. }