client_proper.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. struct UA_Client {
  10. UA_ClientNetworkLayer networkLayer;
  11. UA_String endpointUrl;
  12. UA_Connection connection;
  13. UA_UInt32 sequenceNumber;
  14. UA_UInt32 requestId;
  15. /* Secure Channel */
  16. UA_ChannelSecurityToken securityToken;
  17. UA_ByteString clientNonce;
  18. UA_ByteString serverNonce;
  19. /* UA_SequenceHeader sequenceHdr; */
  20. /* UA_NodeId authenticationToken; */
  21. /* Session */
  22. UA_NodeId sessionId;
  23. UA_NodeId authenticationToken;
  24. };
  25. int main(int argc, char *argv[]) {
  26. UA_Client *client = UA_Client_new();
  27. UA_ClientNetworkLayer nl = ClientNetworkLayerTCP_new(UA_ConnectionConfig_standard);
  28. UA_Client_connect(client, UA_ConnectionConfig_standard, nl, "opc.tcp://localhost:48020");
  29. UA_NodeId node;
  30. node.namespaceIndex = 4;
  31. node.identifierType = UA_NODEIDTYPE_STRING;
  32. UA_String_copycstring("Demo.Static.Scalar.Int32", &node.identifier.string);
  33. UA_ReadRequest read_req;
  34. UA_ReadRequest_init(&read_req);
  35. read_req.nodesToRead = UA_ReadValueId_new();
  36. read_req.nodesToReadSize = 1;
  37. read_req.nodesToRead[0].nodeId = node;
  38. read_req.nodesToRead[0].attributeId = UA_ATTRIBUTEID_VALUE;
  39. UA_ReadResponse read_resp = UA_Client_read(client, &read_req);
  40. printf("the answer is: %i\n", *(UA_Int32*)read_resp.results[0].value.dataPtr);
  41. UA_ReadRequest_deleteMembers(&read_req);
  42. UA_ReadResponse_deleteMembers(&read_resp);
  43. UA_Client_delete(client);
  44. }