Skip to content

Commit

Permalink
🔧 更新 OPC UA 字符串字面量到 Variable 转换构造函数的写法
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoxi-scut committed Feb 16, 2025
1 parent 961e08c commit 38bb940
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions modules/opcua/include/rmvl/opcua/variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class RMVL_EXPORTS_W Variable final
* @param[in] str 字符串
*/
template <std::size_t N>
Variable(const char (&str)[N]) : Variable(std::string(str, N)) {}
Variable(const char (&str)[N]) : Variable(std::string(str)) {}

/**
* @brief 列表构造
Expand Down Expand Up @@ -367,8 +367,8 @@ struct RMVL_EXPORTS_W_AG DataSourceVariable
RMVL_W_RW std::string display_name{};
//! 变量的描述
RMVL_W_RW std::string description{};
//! 访问性
RMVL_W_RW uint8_t access_level{};
//! 访问性,默认为只读
RMVL_W_RW uint8_t access_level{1U};

/**
* @brief 数据源 Read 回调函数
Expand Down
10 changes: 6 additions & 4 deletions modules/opcua/test/test_opcua_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,13 @@ TEST(OPC_UA_ClientTest, event_monitor)
srv.addEventTypeNode(etype);
rm::Client cli("opc.tcp://127.0.0.1:5010");

std::string source_name;
std::string source_name{};
std::string messgae{};
int aaa{};
cli.monitor({"SourceName", "aaa"}, [&](rm::ClientView, const rm::Variables &fields) {
source_name = fields[0].cast<std::string>();
aaa = fields[1];
cli.monitor({"Message", "SourceName", "aaa"}, [&](rm::ClientView, const rm::Variables &fields) {
messgae = fields[0].cast<std::string>();
source_name = fields[1].cast<std::string>();
aaa = fields[2];
});
// 触发事件
auto event = rm::Event::makeFrom(etype);
Expand Down

0 comments on commit 38bb940

Please sign in to comment.