当前位置:网站首页>Several silly built-in functions about relative path / absolute path operation in CAPL script
Several silly built-in functions about relative path / absolute path operation in CAPL script
2022-07-21 08:24:00 【Ant soldier】
Related articles
Preface
- CAPL About relative paths in scripts , Several silly built-in functions of absolute path operation
- Demonstrate hardware and software environment Win10 x64 ; CANoe 11 SP2 x64
Catalog
getAbsFilePath
- .
long getAbsFilePath(char relPath[], char absPath[], long absPathLen)
- According to the following
help
Explanation of the document , According to the relative path of input , Output absolute path . - So here comes the question , The absolute path of the output , What is the root directory ?
- If the dead end path of the output , This path does not exist on the hard disk , Will you make a mistake ?
- 1️⃣ Note the following file
userFilesTest.txt
Path to file :D:\CANoe-Demo\TestModule\FilePathFunc
- 2️⃣ Let's execute the following script , Note that the script file name is :
filePathFuncTest.can
anduserFilesTest.txt
At the same directory
on key 'e'
{
char absPath[256];
long retVal;
retVal = getAbsFilePath("userFilesTest.txt", absPath, 256);
write ("absPath: %s ", absPath);
write ("retVal: %d ", retVal);
}
- 3️⃣ The output result shows that the return value of the function is
31
, This indicates the return valueThe string length of the absolute path
; In addition, the range value isD:\CANoe-Demo\userFilesTest.txt
, Not expectedD:\CANoe-Demo\TestModule\FilePathFunc\userFilesTest.txt
- The key is coming. :
1: The path of the return value does not exist on this machine , No mistake. ;
2: The composition of the absolute root directory is not based on this script as a reference root directory , But with thiscfg
The folder where the file is located is the root directory
- 4️⃣ So we want to get the exact absolute pathname , It's going to take cfg The file is in the root directory , Then write the relative path , As shown in the following figure :
on key 'f'
{
char absPath[256];
long retVal;
retVal = getAbsFilePath("TestModule\\FilePathFunc\\userFilesTest.txt", absPath, 256);
write ("absPath: %s ", absPath);
write ("retVal: %d ", retVal);
}
setFilePath
- .
void setFilePath (char Path[],dword mode);
- According to the following
help
Explanation of the document , That is, when there is an operation on a file, you should first set the file path to be operated - So here comes the question , When I read and write files , Is this function necessary ? What happens if you don't write ?
- 1️⃣ Look at the path and location of the following file
- 2️⃣ We won't add
setFilePath
function , Directly operate thistest.ini
What about the file ?
on key 'g'
{
long retVal;
// write in INI file function
retVal = writeProfileInt ("setting", "parameter_1", 8, "test.ini");
write ("retVal: %d ", retVal);
}
- 3️⃣ The output result shows that the return value of the function is
1
, This indicates that the function was executed successfully , howevertest.ini
There is no information in the file - The key is coming. :
1: The path of the return value does not exist on this machine , No mistake. ;
2: The root directory that makes up the absolute path does not take this script as the reference root directory , But with thiscfg
The folder where the file is located is the root directory
- 4️⃣ stay The open cfg Found test.ini file , And write the value , This means that , If you enter the file name directly , If cfg There is no such file under the file , Then write will be created directly .
- 5️⃣ OK, Write the file name directly , No path found , Then I can fill in the absolute path
on key 'h'
{
long retVal;
// write in INI file function
// Write the absolute path directly ?
retVal = writeProfileInt ("setting", "parameter_1", 8, "D:\\CANoe-Demo\\TestModule\\FilePathFunc\\test.ini");
write ("retVal: %d ", retVal);
}
- 6️⃣ what ? The return value is 0, It's not going to work ; It turns out that if the path of the file to be operated is not set in advance , It has to be a relative path , Absolutely no way .
- 7️⃣ This time we set the relative path
on key 'j'
{
long retVal;
// write in INI file function
// If the file operation path is not set in advance , Relative paths must be used
retVal = writeProfileInt ("setting", "parameter_1", 8, "TestModule/FilePathFunc/test.ini");
write ("retVal: %d ", retVal);
}
- 8️⃣ It did , But if the file I want to operate is not there D disc , And also cfg There is no relative relationship between files , How to do that ?, It seems that it must be used
setFilePath
perhapssetWritePath
. Talent
- 9️⃣ I'm not convinced , Is there really no way to get it ? Must compromise first set
setFilePath
? Look at the picture below , There's another way ,
Configuration|Options|Extensions|User Files Add the files to be operated ,
Note here , You cannot add a quotation with the same file name , Even if the path is different
- Then directly operate on the file name
on key 'l'
{
long retVal;
retVal = writeProfileInt ("setting", "parameter_1", 8, "test.ini");
write ("retVal: %d ", retVal);
}
- The test results are as follows , It can be successful ;
- 1️⃣1️⃣ After the trial and error of the previous steps , For the applicability of the code , Let's not struggle , It's better to add
setFilePath
function
on key 'k'
{
long retVal;
setFilePath("E:\\FilePathFunc", 1);
retVal = writeProfileInt ("setting", "parameter_1", 8, "test.ini");
write ("retVal: %d ", retVal);
}
- 1️⃣2️⃣ The test results are as follows ;
setWritePath
setWritePath
yes setFilePath
A subset of functions
getUserFilePath
- . Look at the picture below help file
1️⃣ The sum of this function
getAbsFilePath
The function is very similar to , But it's different , For example, the following codegetUserFilePath
First, in the user files Inside ( In the screenshot above , Added ) seek , eureka , Just return the absolute path of this file
Open it if you can't find it cfg Go to the price folder directory where the document is locatedgetAbsFilePath
Open it directly cfg Go to the price folder directory where the document is located , If you can't find it, you will report an error .
on key 'z'
{
char absPath[256];
long retVal;
retVal = getUserFilePath("test.ini", absPath, 256);
write ("getUserFilePath absPath: %s ", absPath);
write ("getUserFilePath retVal: %d ", retVal);
retVal = getAbsFilePath("test.ini", absPath, 256);
write ("getAbsFilePath absPath: %s ", absPath);
write ("getAbsFilePath retVal: %d ", retVal);
}
- 2️⃣ Look at the output , If you are free, you can user file stay option Take it out and try again to see what the result is
RegisterUserFile
- . Look at the picture below help file , Is in the form of code CANoe During operation, it can also be in user Files Add files to
- 1️⃣ Look directly at the code , Execute and see the results
on key 'x'
{
char absPath[256];
long retVal;
retVal = RegisterUserFile("E:\\FilePathFunc\\test2.ini",0);
write ("getUserFilePath retVal: %d ", retVal);
retVal = getUserFilePath("test2.ini", absPath, 256);
write ("getUserFilePath absPath: %s ", absPath);
write ("getUserFilePath retVal: %d ", retVal);
}
- 2️⃣ stop it
CANoe
Operation of , Look at the output andUser Files
The configuration has automatically settest2.ini
File added
summary
- Have the most simple life , The furthest dream , Even if it's freezing tomorrow , Lu Yao's horse died !
- Wechat partners can pay attention Langge on-board diagnosis , A small circle in the industry , In the group
SkyDrive data
,Source code
,There are all kinds of gods
Free time communication technology , Talk about job opportunities .- If this blog is helpful to you , please “ give the thumbs-up ” “ Comment on ”“ Collection ” One key, three links Oh ! It's not easy to code words , Everyone's support is my driving force to stick to it .
边栏推荐
- 鴻蒙3.0發布,多屏融合穩步推進,穀歌卻再受重挫
- 鸿蒙3.0发布,多屏融合稳步推进,谷歌却再受重挫
- The committee member information page of the registration conclusion at the roadshow
- 商品砍价功能实现
- Web漏洞安全-失效访问权限控制
- Selenium Grid 安装
- Three dimensional data (channel in the second dimension) - four-dimensional data (channel in the first dimension before input to the pooling layer) - three-dimensional data (channel in the second dime
- 【29. DFS深度优先】
- ES6模块化
- Laravel 实现数据库和迁移文件的双向同步
猜你喜欢
Cause and effect of memory alignment
【c ++ primer 笔记】第6章 函数
Laravel 实现数据库和迁移文件的双向同步
Overview | comprehensive comparative research on image denoising
水调歌头·明月几时有
CANoe仿真功能之自动化序列(Automation Sequences )
【27. 表达式求值(中缀表达式)】
【Power Shell】Invoke-Expression ,Invoke-Expression -Command $activateCommand;错误或power shell激活虚拟环境报错失败
Wireless communication technology commonly used in the Internet of things
物联网常用的无线通信技术
随机推荐
UML sequence diagram / sequence diagram / sequence diagram
【29. DFS深度优先】
ThinkPHP implements mongodb curd
传感器的特性及性能参数
【25. 哈希表】
解决函数名冲突问题(dlopen,dlsym,dlclose)
Worthington细胞色素 C 消化研究丨羧肽酶 B方案
Redis ranking
sql 盲注
Redis realizes the ranking of surrounding scenic spots from near to far
内核结构与设计
V853 development board hardware data - risc-v core e907 user manual
Codevs - 2750 is concerned about the southern disaster area
Grafana visual configuration chart time series
Examples illustrate the division basis of code segment (.Text), data segment (.Data), BSS segment, read-only data segment (.Rodata) and stack
从0到1 拿下C语言—程序结构及使用示例
【Appium】Failed to create session. An unknown server-side error occurred while processing the command
限制input框中的输入类型及长度
Laravel 实现数据库和迁移文件的双向同步
内存对齐的前因后果