index.rst 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. Introduction
  2. ============
  3. OPC Unified Architecture
  4. ------------------------
  5. `OPC UA <http://en.wikipedia.org/wiki/OPC_Unified_Architecture>`_ (short for OPC Unified Architecture) is a protocol for industrial communication and has been standardized in the IEC 62541 series. At its core, OPC UA defines a set of services to interact with a server-side object-oriented information model. Besides the service-calls initiated by the client, push-notification (discrete events and data changes with a sampling interval) can be negotiated with the server. The client/server interaction is mapped either to a binary encoding and TCP-based transmission or to SOAP-based webservices. As of late, OPC UA is marketed as the one standard for non-realtime industrial communication.
  6. The standard itself can be purchased from IEC or downloaded for free from the website of the OPC Foundation (you need to register with a valid email, though).
  7. open62541
  8. ---------
  9. open62541 (http://open62541.org) is an open source implementation of OPC UA (OPC Unified Architecture). open62541 is a C-based library (linking with C++ projects is possible) with all necessary tools to implement dedicated OPC UA clients and servers, or to integrate OPC UA-based communication into existing applications. open62541 is licensed under the LGPL with a static linking exception. So the *open62541 library can be used in projects that are not open source*. However, changes to the open62541 library itself need to published under the same license. The [plugins](plugins/), as well as the server and client [examples](examples/) are in the public domain (CC0 license). They can be reused under any license and changes do not have to be published.
  10. Motivation
  11. ^^^^^^^^^^
  12. The open62541 implementation adheres to the official specification as closely as possible. However, no warranty or service-level agreement can be provided by the open62541 community. If you intend to use OPC UA in a mission-critical product, please consider talking to a commercial vendor of OPC UA SDKs and services.
  13. Features
  14. ^^^^^^^^
  15. open62541 implements the OPC UA binary protocol stack as well as a client and server SDK. It currently supports the Micro Embedded Device Server Profile plus some additional features. The final server binaries can be well under 100kb, depending on the size of the information model.
  16. - Communication Stack
  17. - OPC UA binary protocol
  18. - Chunking (splitting of large messages)
  19. - Exchangeable network layer (plugin) for using custom networking APIs (e.g. on embedded targets)
  20. - Information model
  21. - Support for all OPC UA node types (including method nodes)
  22. - Support for adding and removing nodes and references also at runtime.
  23. - Support for inheritance and instantiation of object- and variable-types (custom constructor/destructor, instantiation of child nodes)
  24. - Subscriptions
  25. - Support for subscriptions/monitoreditems for data change notifications
  26. - Very low resource consumption for each monitored value (event-based server architecture)
  27. - Code-Generation
  28. - Support for generating data types from standard XML definitions
  29. - Support for generating server-side information models (nodesets) from standard XML definitions
  30. Features still missing in the 0.2 release are:
  31. - Encryption
  32. - Access control for individual nodes
  33. - Events (notifications emitted by objects, data change notifications are implemented)
  34. - Event-loop (background tasks) and asynchronous service requests in the client
  35. Getting Help
  36. ^^^^^^^^^^^^
  37. Releases of the library can be downloaded at https://github.com/open62541/open62541/releases. To use the latest improvements, download a nightly build of the *single-file distribution* (the entire library merged into a single source and header file) from http://open62541.org/releases. Nightly builds of MSVC binaries of the library are available [here](https://ci.appveyor.com/project/Stasik0/open62541/build/artifacts).
  38. For discussion and help, you can use
  39. - the [mailing list](https://groups.google.com/d/forum/open62541)
  40. - our [IRC channel](http://webchat.freenode.net/?channels=%23open62541)
  41. - the [bugtracker](https://github.com/open62541/open62541/issues)
  42. Contributing to open62541
  43. ^^^^^^^^^^^^^^^^^^^^^^^^^
  44. As an open source project, we invite new contributors to help improve open62541. Issue reports, bugfixes and new features are very welcome. Note that there are ways to begin contributing without deep knowledge of the OPC UA standard:
  45. - [Report bugs](https://github.com/open62541/open62541/issues)
  46. - Improve the [documentation](http://open62541.org/doc/current)
  47. - Work on issues marked as "[easy hacks](https://github.com/open62541/open62541/labels/easy%20hack)"
  48. Example Server Implementation
  49. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  50. Compile the examples with the single-file distribution `open62541.h/.c` header and source file. Using the GCC compiler, just run ``gcc -std=c99 <server.c> open62541.c -o server`` to compile.
  51. .. code-block:: c
  52. #include <signal.h>
  53. #include "open62541.h"
  54. UA_Boolean running = true;
  55. void signalHandler(int sig) {
  56. running = false;
  57. }
  58. int main(int argc, char** argv)
  59. {
  60. signal(SIGINT, signalHandler); /* catch ctrl-c */
  61. /* Create a server with one network layer listening on port 4840 */
  62. UA_ServerConfig config = UA_ServerConfig_standard;
  63. UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 4840);
  64. config.networkLayers = &nl;
  65. config.networkLayersSize = 1;
  66. UA_Server *server = UA_Server_new(config);
  67. /* Add a variable node */
  68. /* 1) Define the node attributes */
  69. UA_VariableAttributes attr;
  70. UA_VariableAttributes_init(&attr);
  71. attr.displayName = UA_LOCALIZEDTEXT("en_US", "the answer");
  72. UA_Int32 myInteger = 42;
  73. UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
  74. /* 2) Define where the node shall be added with which browsename */
  75. UA_NodeId newNodeId = UA_NODEID_STRING(1, "the.answer");
  76. UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
  77. UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
  78. UA_NodeId variableType = UA_NODEID_NULL; /* take the default variable type */
  79. UA_QualifiedName browseName = UA_QUALIFIEDNAME(1, "the answer");
  80. /* 3) Add the node */
  81. UA_Server_addVariableNode(server, newNodeId, parentNodeId, parentReferenceNodeId,
  82. browseName, variableType, attr, NULL, NULL);
  83. /* Run the server loop */
  84. UA_StatusCode status = UA_Server_run(server, &running);
  85. UA_Server_delete(server);
  86. nl.deleteMembers(&nl);
  87. return status;
  88. }
  89. Example Client Implementation
  90. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  91. .. code-block:: c
  92. #include <stdio.h>
  93. #include "open62541.h"
  94. int main(int argc, char *argv[])
  95. {
  96. /* Create a client and connect */
  97. UA_Client *client = UA_Client_new(UA_ClientConfig_standard);
  98. UA_StatusCode status = UA_Client_connect(client, "opc.tcp://localhost:4840");
  99. if(status != UA_STATUSCODE_GOOD) {
  100. UA_Client_delete(client);
  101. return status;
  102. }
  103. /* Read the value attribute of the node. UA_Client_readValueAttribute is a
  104. * wrapper for the raw read service available as UA_Client_Service_read. */
  105. UA_Variant value; /* Variants can hold scalar values and arrays of any type */
  106. UA_Variant_init(&value);
  107. status = UA_Client_readValueAttribute(client, UA_NODEID_STRING(1, "the.answer"), &value);
  108. if(status == UA_STATUSCODE_GOOD && UA_Variant_isScalar(&value) &&
  109. value.type == &UA_TYPES[UA_TYPES_INT32]) {
  110. printf("the value is: %i\n", *(UA_Int32*)value.data);
  111. }
  112. /* Clean up */
  113. UA_Variant_deleteMembers(&value);
  114. UA_Client_delete(client); /* Disconnects the client internally */
  115. return status;
  116. }
  117. .. toctree::
  118. :maxdepth: 2
  119. index
  120. building
  121. tutorials
  122. types
  123. information_modelling
  124. services
  125. server
  126. client
  127. constants
  128. internal