SysGetVariableString函数

发布于:2025-08-16 ⋅ 阅读:(16) ⋅ 点赞:(0)

博主最近写canoe上位机,用到SysGetVariableString函数,如是仔细研究了一下这个函数,在Vector工具链(里如CANoe/vTESTStudio),用于读取字符串类型系统变量的核心函数,用于获取操作系统或应用程序中存储的字符串类型变量值。该函数通常用于读取环境变量、配置文件设置或系统注册表中的字符串值。
当然在特定平台下,原生API也不一样: Windows: GetEnvironmentVariable Linux: getenv,C标准库: getenv
本博主是在用canoe开发工具链,故此只做在Vector工具链的介绍:

在capl里可以搜到函数如下图:
在这里插入图片描述

‌一、函数原型与参数
在这里插入图片描述

二、参数说明
namespace Name of the name space.

variable Name of the variable.

buffer Buffer that takes the value of the variable.

bufferSize Size of the buffer.

SysVarName Name of the fully qualified name of the system variable, including all name spaces, separated by “::”. The name must be preceded by “sysVar::”.

三使用如下

1,获取文件路径
char filePath[100];
sysGetVariableString(sysvar::TestData::_pathName, filePath, elcount(filePath));
配合Panel控件实现登录功能

‌2,网络参数配置
char ipAddr[16];
dword ipNum;
sysGetVariableString(sysvar::DUT::dut_address, ipAddr, elcount(ipAddr));
ipNum = IPGetAddressAsNumber(ipAddr); // 转换为数值类型
适用于TCP/IP连接初始化

3,用户交互数据传递
char username[10];
sysGetVariableString(sysvar::Login::userName, username, elcount(username));
配合Panel控件实现登录功能;

以上是对这个函数的详细介绍,如有不清楚可以联系本博主。
以下是环境变量的关联:

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述在这里插入图片描述
在这里插入图片描述

这个函数联合使用。编译一下无报错。