-
Notifications
You must be signed in to change notification settings - Fork 1
added standard examples for open62541(pp) #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
StephanKa
merged 3 commits into
Zuehlke:main
from
StephanKa:feature/add-open62541-examples
Aug 15, 2025
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ADD_EXECUTABLE(open62541_client client.cpp) | ||
| TARGET_LINK_LIBRARIES(open62541_client PRIVATE open62541::open62541) | ||
|
|
||
| ADD_EXECUTABLE(open62541_server server.cpp) | ||
| TARGET_LINK_LIBRARIES(open62541_server PRIVATE open62541::open62541) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #include <open62541/client.h> | ||
| #include <open62541/client_highlevel.h> | ||
| #include <open62541/client_config_default.h> | ||
|
|
||
| int main() | ||
| { | ||
| /* Create a client and connect */ | ||
| UA_Client *client = UA_Client_new(); | ||
| UA_ClientConfig_setDefault(UA_Client_getConfig(client)); | ||
| UA_StatusCode status = UA_Client_connect(client, "opc.tcp://localhost:4840"); | ||
| if (status != UA_STATUSCODE_GOOD) { | ||
| UA_Client_delete(client); | ||
| return status; | ||
| } | ||
|
|
||
| /* Read the value attribute of the node. UA_Client_readValueAttribute is a | ||
| * wrapper for the raw read service available as UA_Client_Service_read. */ | ||
| UA_Variant value;/* Variants can hold scalar values and arrays of any type */ | ||
| UA_Variant_init(&value); | ||
| status = UA_Client_readValueAttribute(client, UA_NODEID_STRING(1, "the.answer"), &value); | ||
| if (status == UA_STATUSCODE_GOOD && | ||
| UA_Variant_hasScalarType(&value, &UA_TYPES[UA_TYPES_INT32])) { printf("the value is: %i\n", *static_cast<UA_Int32 *>(value.data)); } | ||
|
StephanKa marked this conversation as resolved.
Outdated
|
||
|
|
||
| /* Clean up */ | ||
| UA_Variant_clear(&value); | ||
| UA_Client_delete(client);/* Disconnects the client internally */ | ||
| return status == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #include <open62541/server.h> | ||
| #include <open62541/server_config_default.h> | ||
|
|
||
| int main() | ||
| { | ||
| UA_Server *server = UA_Server_new(); | ||
| UA_Server_run_startup(server); | ||
|
|
||
| /* Should the server networklayer block (with a timeout) until a message | ||
| arrives or should it return immediately? */ | ||
| const UA_Boolean waitInternal = true; | ||
| while (true) { UA_Server_run_iterate(server, waitInternal); } | ||
|
|
||
| UA_Server_run_shutdown(server); | ||
| UA_Server_delete(server); | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| INCLUDE(FetchContent) | ||
|
|
||
| FETCHCONTENT_DECLARE( | ||
| open62541pp | ||
| GIT_REPOSITORY https://github.com/open62541pp/open62541pp.git | ||
| GIT_TAG v0.15.0 | ||
| ) | ||
| FETCHCONTENT_MAKEAVAILABLE(open62541pp) | ||
|
|
||
| INCLUDE_DIRECTORIES(${open62541pp_SOURCE_DIR}) | ||
|
StephanKa marked this conversation as resolved.
Outdated
|
||
|
|
||
| ADD_EXECUTABLE(open62541pp_client client.cpp) | ||
| TARGET_LINK_LIBRARIES(open62541pp_client PRIVATE open62541pp::open62541pp) | ||
|
|
||
| ADD_EXECUTABLE(open62541pp_server server.cpp) | ||
| TARGET_LINK_LIBRARIES(open62541pp_server PRIVATE open62541pp::open62541pp) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #include <iostream> | ||
|
|
||
| #include <open62541pp/open62541pp.h> | ||
|
|
||
| int main() { | ||
| opcua::Client client; | ||
| client.connect("opc.tcp://localhost:4840"); | ||
|
|
||
| opcua::Node node = client.getNode(opcua::VariableId::Server_ServerStatus_CurrentTime); | ||
| const auto dt = node.readValueScalar<opcua::DateTime>(); | ||
|
|
||
| std::cout << "Server date (UTC): " << dt.format("%Y-%m-%d %H:%M:%S") << "\n"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #include <open62541pp/open62541pp.h> | ||
|
|
||
| int main() { | ||
| opcua::Server server; | ||
|
|
||
| // Add a variable node to the Objects node | ||
| opcua::Node parentNode = server.getObjectsNode(); | ||
| opcua::Node myIntegerNode = parentNode.addVariable({1, 1000}, "TheAnswer"); | ||
| // Write some node attributes | ||
| myIntegerNode.writeDisplayName({"en-US", "The Answer"}) | ||
| .writeDataType(opcua::DataTypeId::Int32) | ||
| .writeValueScalar(42); | ||
|
|
||
| server.run(); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.