Skip to content
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

添加 opcua 模块例程 #61

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/opcua/include/rmvl/opcua/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace rm
//! @addtogroup opcua
//! @{

//! @example samples/opcua/opcua_client.cpp OPC UA 客户端例程

//! OPC UA 客户端
class Client
{
Expand Down
2 changes: 2 additions & 0 deletions modules/opcua/include/rmvl/opcua/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace rm
//! @addtogroup opcua
//! @{

//! @example samples/opcua/opcua_server.cpp OPC UA 服务器例程

//! 值回调函数,Read 函数指针定义
using ValueCallBackBeforeRead = void (*)(UA_Server *, const UA_NodeId *, void *, const UA_NodeId *, void *,
const UA_NumericRange *, const UA_DataValue *);
Expand Down
15 changes: 15 additions & 0 deletions samples/opcua/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
if(NOT BUILD_rmvl_opcua)
return()
endif()

rmvl_add_exe(
rmvl_opcua_server
SOURCES opcua_server.cpp
DEPENDS opcua
)

rmvl_add_exe(
rmvl_opcua_client
SOURCES opcua_client.cpp
DEPENDS opcua
)
10 changes: 10 additions & 0 deletions samples/opcua/opcua_client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "rmvl/opcua/client.hpp"

int main()
{
rm::Client client("opc.tcp://localhost:4840");
auto var_id = rm::nodeObjectsFolder | client.find("var_demo");
auto var = client.read(var_id);
printf("\033[32mValue: %d\033[0m\n", var.cast<int>());
return 0;
}
18 changes: 18 additions & 0 deletions samples/opcua/opcua_server.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "rmvl/opcua/server.hpp"

int main()
{
rm::Server server(4840U);
rm::Variable var = 42;
var.display_name = "VarDemo";
var.browse_name = "var_demo";
server.addVariableNode(var);
server.start();

printf("\033[32mServer started for 20 seconds ...\033[0m\n");
std::this_thread::sleep_for(std::chrono::seconds(20));
printf("\033[32mServer stopped ...\033[0m\n");
server.stop();
server.join();
return 0;
}
Loading